-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
60 lines (52 loc) · 1.4 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React from 'react';
import Animated, {
useCode,
startClock,
divide,
set,
interpolate,
Extrapolate,
} from 'react-native-reanimated';
import { useValue, useClock, useDiff, useConst } from 'react-native-redash';
import Card, { cards } from '../../components/Card';
import { Container, AnimatedCardView } from './styles';
const SkewScroll: React.FC = () => {
const cardsArray = [...cards, ...cards, ...cards, ...cards];
const clock = useClock();
const y = useValue(0);
const velocity = useValue(0);
const onScroll = useConst(() =>
Animated.event([
{
nativeEvent: {
contentOffset: { y },
},
},
]),
);
const dy = useDiff(y); // calcs the diff between frames
const dt = useDiff(clock);
useCode(() => [startClock(clock), set(velocity, divide(dy, dt))], []);
const skewY = interpolate(velocity, {
inputRange: [-8, 0, 8],
outputRange: [-Math.PI / 9, 0, Math.PI / 9],
extrapolate: Extrapolate.CLAMP,
});
return (
<Container
as={Animated.ScrollView}
scrollEventThrottle={1}
onScroll={onScroll}
showsVerticalScrollIndicator={false}>
{cardsArray.map((card, i) => (
<AnimatedCardView
as={Animated.View}
style={{ transform: [{ skewY }] }}
key={i}>
<Card card={card} />
</AnimatedCardView>
))}
</Container>
);
};
export default SkewScroll;