This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
102 lines (92 loc) · 2.72 KB
/
index.ios.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
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
import React, {
AppRegistry,
Component,
Dimensions,
ScrollView,
StyleSheet,
Text,
View
} from 'react-native';
import PageControlIOS from 'react-native-pagecontrol';
class PageControlIOSExample extends Component {
constructor(props) {
super(props);
this.state = {
currentPage: 0,
width: Dimensions.get('window').width
};
this._onPageControlValueChange = this._onPageControlValueChange.bind(this);
this._onScroll = this._onScroll.bind(this);
}
render() {
return (
<View style={styles.container}>
<View style={styles.pageControlContainer}>
<PageControlIOS
currentPage={this.state.currentPage}
numberOfPages={4}
onValueChange={this._onPageControlValueChange}
pageIndicatorTintColor="grey"
currentPageIndicatorTintColor="rgb(200,200,0)"
/>
</View>
<View style={styles.scrollerContainer}>
<ScrollView
ref="ScrollView"
horizontal={true}
onScroll={this._onScroll}
pagingEnabled={true}
scrollEventThrottle={16}>
<View style={[styles.scrollPage, {width: this.state.width, backgroundColor: '#F00'}]}>
<Text>Page 1</Text>
</View>
<View style={[styles.scrollPage, {width: this.state.width, backgroundColor: '#0F0'}]}>
<Text>Page 2</Text>
</View>
<View style={[styles.scrollPage, {width: this.state.width, backgroundColor: '#00F'}]}>
<Text style={{color: '#FFF'}}>Page 3</Text>
</View>
<View style={[styles.scrollPage, {width: this.state.width, backgroundColor: '#FF0'}]}>
<Text>Page 4</Text>
</View>
</ScrollView>
</View>
</View>
);
}
_onPageControlValueChange(currentPage) {
this.refs.ScrollView.scrollResponderScrollTo({x: this.state.width * currentPage, y: 0, animated: true});
}
_onScroll({nativeEvent}) {
let currentPage = Math.round(nativeEvent.contentOffset.x / nativeEvent.layoutMeasurement.width);
if (this.state.currentPage !== currentPage) {
this.setState({currentPage});
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#F5FCFF',
paddingTop: 50
},
pageControlContainer: {
alignItems: 'center'
},
scrollerContainer: {
flex: 1
},
scrollPage: {
alignItems: 'center',
justifyContent: 'center',
flex: 1,
height: 50
}
});
AppRegistry.registerComponent('PageControlIOSExample', () => PageControlIOSExample);