-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFlatListExample.js
65 lines (55 loc) · 1.76 KB
/
FlatListExample.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from 'react';
import {
View,
SafeAreaView,
FlatList,
Dimensions
} from 'react-native';
import {
PageControlAji,
PageControlAleppo,
PageControlJaloro,
PageControlPoblano
} from 'react-native-chi-page-control';
const width = Dimensions.get('window').width;
const DATA = ["red", "blue", "green", "yellow"];
class FlatListExample extends React.Component{
state = {
progress: 0
};
constructor(props) {
super(props);
this.onScroll = this.onScroll.bind(this)
};
render() {
return (
<>
<SafeAreaView>
<FlatList
style={{marginBottom: 20}}
data={DATA}
horizontal
pagingEnabled
renderItem={this.renderItem}
onScroll={this.onScroll}
keyExtractor={item => item}
/>
<View style={{alignItems: 'center'}}>
<PageControlAji progress={this.state.progress} numberOfPages={DATA.length} style={{marginBottom: 10}} />
<PageControlAleppo progress={this.state.progress} numberOfPages={DATA.length} style={{marginBottom: 10}}/>
<PageControlJaloro progress={this.state.progress} numberOfPages={DATA.length} style={{marginBottom: 10}}/>
<PageControlPoblano progress={this.state.progress} numberOfPages={DATA.length} style={{marginBottom: 10}}/>
</View>
</SafeAreaView>
</>
)
};
renderItem({item}) {
return <View style={{height: 100, width: width, backgroundColor: item, borderColor: 'black', borderWidth: 2}} />
};
onScroll(e) {
// Get progress by dividing current FlatList X offset with full FlatList width
this.setState({ progress: e.nativeEvent.contentOffset.x / ((DATA.length - 1) * width) })
};
};
export default FlatListExample;