-
Notifications
You must be signed in to change notification settings - Fork 36
/
App.tsx
183 lines (177 loc) · 4.84 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import React from 'react';
import {
StyleSheet,
View,
Text,
Animated,
FlatList,
useWindowDimensions,
} from 'react-native';
import {
ScalingDot,
SlidingBorder,
ExpandingDot,
SlidingDot,
} from 'react-native-animated-pagination-dots';
interface ItemProps {
key: string;
title: string;
description: string;
}
const INTRO_DATA = [
{
key: '1',
title: 'App showcase ✨',
description:
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
},
{
key: '2',
title: 'Introduction screen 🎉',
description:
"Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. ",
},
{
key: '3',
title: 'And can be anything 🎈',
description:
'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. ',
},
{
key: '4',
title: 'And can be anything 🎈',
description:
'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. ',
},
{
key: '5',
title: 'And can be anything 🎈',
description:
'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. ',
},
{
key: '6',
title: 'And can be anything 🎈',
description:
'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. ',
},
];
const App = () => {
const {width} = useWindowDimensions();
const scrollX = React.useRef(new Animated.Value(0)).current;
const renderItem = React.useCallback(
({item}: {item: ItemProps}) => {
return (
<View style={[styles.itemContainer, {width: width - 80}]}>
<Text>{item.title}</Text>
<Animated.Text>{item.description}</Animated.Text>
</View>
);
},
[width],
);
const keyExtractor = React.useCallback((item: ItemProps) => item.key, []);
return (
<View style={[styles.container]}>
<FlatList
data={INTRO_DATA}
keyExtractor={keyExtractor}
showsHorizontalScrollIndicator={false}
onScroll={Animated.event(
[{nativeEvent: {contentOffset: {x: scrollX}}}],
{
useNativeDriver: false,
},
)}
style={styles.flatList}
pagingEnabled
horizontal
decelerationRate={'normal'}
scrollEventThrottle={16}
renderItem={renderItem}
/>
<View style={styles.text}>
<View style={styles.dotContainer}>
<Text>Expanding Dot</Text>
<ExpandingDot
data={INTRO_DATA}
expandingDotWidth={30}
scrollX={scrollX}
inActiveDotColor={'#347af0'}
activeDotColor={'#347af0'}
inActiveDotOpacity={0.5}
dotStyle={styles.dotStyles}
containerStyle={styles.constainerStyles}
/>
</View>
<View style={styles.dotContainer}>
<Text>Scaling Dot</Text>
<ScalingDot
data={INTRO_DATA}
scrollX={scrollX}
containerStyle={styles.constainerStyles}
inActiveDotColor={'#347af0'}
activeDotColor={'#347af0'}
/>
</View>
<View style={styles.dotContainer}>
<Text>Sliding Border</Text>
<SlidingBorder
containerStyle={styles.constainerStyles}
data={INTRO_DATA}
scrollX={scrollX}
dotSize={24}
borderPadding={-5}
/>
{/*<Pagination data={INTRO_DATA} scrollX={scrollX} />*/}
</View>
<View style={styles.dotContainer}>
<Text>Sliding Dot</Text>
<SlidingDot
marginHorizontal={3}
containerStyle={styles.constainerStyles}
data={INTRO_DATA}
scrollX={scrollX}
dotSize={12}
/>
</View>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#e7e7e7',
},
text: {
flex: 1,
justifyContent: 'space-evenly',
},
flatList: {
flex: 1,
},
dotContainer: {
justifyContent: 'center',
alignSelf: 'center',
},
dotStyles: {
width: 10,
height: 10,
borderRadius: 5,
marginHorizontal: 3,
},
constainerStyles: {
top: 30,
},
itemContainer: {
backgroundColor: '#fff',
justifyContent: 'center',
alignItems: 'center',
padding: 40,
marginTop: 40,
marginHorizontal: 40,
borderRadius: 20,
},
});
export default App;