-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleScreen.js
87 lines (75 loc) · 1.99 KB
/
SimpleScreen.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
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
Dimensions,
Image,
TouchableHighlight,
} = React;
var ViewPager = require('react-native-viewpager');
//var ViewPager = require('./ViewPager');
var deviceWidth = Dimensions.get('window').width;
var IMGS = [
'https://images.unsplash.com/photo-1441742917377-57f78ee0e582?h=1024',
'https://images.unsplash.com/photo-1441716844725-09cedc13a4e7?h=1024',
'https://images.unsplash.com/photo-1441448770220-76743f9e6af6?h=1024',
'https://images.unsplash.com/photo-1441260038675-7329ab4cc264?h=1024',
'https://images.unsplash.com/photo-1441126270775-739547c8680c?h=1024',
'https://images.unsplash.com/photo-1440964829947-ca3277bd37f8?h=1024',
'https://images.unsplash.com/photo-1440847899694-90043f91c7f9?h=1024'
];
var count = 0;
var SimpleScreen = React.createClass({
getInitialState: function() {
var dataSource = new ViewPager.DataSource({
pageHasChanged: (p1, p2) => p1 !== p2,
});
return {
dataSource: dataSource.cloneWithPages(IMGS),
page: 0
};
},
render: function() {
return (
<View style={styles.container}>
<ViewPager
ref={(viewpager) => {this.viewpager = viewpager}}
style={this.props.style}
dataSource={this.state.dataSource}
renderPage={this._renderPage}
isLoop={false}
autoPlay={false}/>
<TouchableHighlight style={styles.button} onPress={() => {
this.viewpager.goToPage(count + 1);
count = count + 1;
}}>
<Text>Click</Text>
</TouchableHighlight>
</View>
);
},
_renderPage: function(
data: Object,
pageID: number | string,) {
return (
<Image
source={{uri: data}}
style={styles.page} />
);
},
});
var styles = StyleSheet.create({
container: {
flex: 1,
},
page: {
width: deviceWidth,
},
button: {
padding: 10,
},
});
module.exports = SimpleScreen;