-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterpolateScrollView.js
50 lines (46 loc) · 1.12 KB
/
InterpolateScrollView.js
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
import { StatusBar } from "expo-status-bar";
import { useEffect } from "react";
import { StyleSheet, Text, View } from "react-native";
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
withSpring,
withRepeat,
useAnimatedGestureHandler,
useAnimatedScrollHandler,
} from "react-native-reanimated";
import { Page } from "./components/Page";
const WORDS = ["What's", "up", "mobile", "devs?"];
export default function App() {
const translateX = useSharedValue(0);
const scrollHandler = useAnimatedScrollHandler((event) => {
translateX.value = event.contentOffset.x;
});
return (
<Animated.ScrollView
onScroll={scrollHandler}
scrollEventThrottle={16}
style={styles.container}
horizontal
pagingEnabled
>
{WORDS.map((title, index) => {
return (
<Page
key={index.toString()}
title={title}
index={index}
translateX={translateX}
/>
);
})}
</Animated.ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
},
});