/
App.tsx
113 lines (97 loc) · 2.29 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
import { range } from "lodash";
import React, { useState } from "react";
import { SafeAreaView, StyleSheet, View, Text, StatusBar } from "react-native";
import { Carousel } from "@fnando/react-native-carousel";
const Indicators = ({
count,
selectedIndex,
}: {
count: number;
selectedIndex: number;
}) => {
const children = range(count).map((index: number) => {
const selected = index === selectedIndex;
return (
<View
key={index}
style={{
...styles.indicator,
backgroundColor: selected ? "#000" : "#ffffff80",
}}>
<Text
style={{
...styles.indicatorText,
color: selected ? "#fff" : "#00000090",
}}>
{index + 1}
</Text>
</View>
);
});
return (
<SafeAreaView style={styles.indicatorsSafeArea}>
<View style={styles.indicators}>{children}</View>
</SafeAreaView>
);
};
const App = () => {
const [currentPage, setCurrentPage] = useState(0);
const handlePageChange = ({
currentPage: newCurrentPage,
}: {
currentPage: number;
}) => {
setCurrentPage(newCurrentPage);
};
return (
<View style={styles.container}>
<Carousel showsIndicator={false} onPageChange={handlePageChange}>
<View style={{ ...styles.page, backgroundColor: "orange" }}>
<Text>Page 1</Text>
</View>
<View style={{ ...styles.page, backgroundColor: "gray" }}>
<Text>Page 2</Text>
</View>
<View style={{ ...styles.page, backgroundColor: "#4a90e2" }}>
<Text>Page 3</Text>
</View>
</Carousel>
<Indicators count={3} selectedIndex={currentPage} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
page: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
indicatorsSafeArea: {
position: "absolute",
bottom: 0,
left: 0,
right: 0,
},
indicators: {
flex: 1,
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
},
indicator: {
width: 20,
height: 20,
alignItems: "center",
justifyContent: "center",
marginHorizontal: 5,
borderRadius: 10,
},
indicatorText: {
fontFamily: "System",
fontWeight: "700",
},
});
export default App;