-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
121 lines (110 loc) · 2.87 KB
/
App.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
StyleSheet,
View,
Dimensions,
TouchableOpacity,
FlatList,
ViewToken,
FlatListComponent,
} from "react-native";
import Animated, {
useAnimatedScrollHandler,
useSharedValue,
useAnimatedRef,
} from "react-native-reanimated";
import { Feather } from "@expo/vector-icons";
import { CircleView } from "./src/components/CircleView";
import { Dots } from "./src/components/Dots";
const data = ["This", "Is", "My", "Onboarding", "Jaia.Dev 🤌🏼"];
const { width, height } = Dimensions.get("screen");
export default function App() {
const scrollX = useSharedValue(0);
const flatListRef = useAnimatedRef<FlatList>();
const flatListIndex = useSharedValue(0);
const handleOnScroll = useAnimatedScrollHandler({
onScroll: (event) => {
scrollX.value = event.contentOffset.x;
},
});
const onViewableItemsChanged = ({
viewableItems,
}: {
viewableItems: ViewToken[];
}) => {
if (viewableItems[0].index !== null) {
flatListIndex.value = viewableItems[0].index;
}
};
const handleScrollToNext = () => {
const ITEMS_SIZE = data.length - 1;
if (flatListIndex.value < ITEMS_SIZE)
flatListRef.current.scrollToIndex({
index: flatListIndex.value + 1,
});
};
const renderItem = ({ item, index }) => {
return <CircleView item={item} index={index} scrollX={scrollX} />;
};
return (
<View style={styles.container}>
<Animated.FlatList
horizontal
ref={flatListRef}
onViewableItemsChanged={onViewableItemsChanged}
data={data}
renderItem={renderItem}
onScroll={handleOnScroll}
scrollEventThrottle={16}
showsHorizontalScrollIndicator={false}
contentContainerStyle={{
alignItems: "center",
justifyContent: "center",
}}
pagingEnabled
/>
<View
style={{
position: "absolute",
width,
justifyContent: "center",
alignItems: "center",
bottom: height * 0.1,
gap: 40,
}}
>
<View
style={{
justifyContent: "center",
alignItems: "center",
flexDirection: "row",
gap: 12,
}}
>
{data.map((_, index) => {
return <Dots index={index} scrollX={scrollX} key={index} />;
})}
</View>
<TouchableOpacity
style={{
width: 60,
height: 60,
backgroundColor: "#FFFFFF",
justifyContent: "center",
alignItems: "center",
padding: 16,
borderRadius: 30,
}}
onPress={handleScrollToNext}
>
<Feather name="arrow-right" size={24} />
</TouchableOpacity>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#65bfff",
},
});