-
Notifications
You must be signed in to change notification settings - Fork 107
/
CarouselPager.android.js
44 lines (39 loc) · 1.13 KB
/
CarouselPager.android.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
var React = require('react');
var createReactClass = require('create-react-class');
var {
View
} = require('react-native');
import ViewPager from "@react-native-community/viewpager";
var CarouselPager = createReactClass({
scrollToPage(page, animated) {
if (typeof animated === 'undefined') {
animated = true;
}
if (animated) {
this.refs.viewPager.setPage(page);
} else {
this.refs.viewPager.setPageWithoutAnimation(page);
}
this._onPageSelected(page);
},
_onPageSelected(page) {
this.props.onEnd(page);
},
render() {
return <ViewPager
ref="viewPager"
style={{flex: 1}}
contentContainerStyle={this.props.contentContainerStyle}
automaticallyAdjustContentInsets={false}
horizontal={true}
showsHorizontalScrollIndicator={false}
bounces={false}
onPageScroll={this.props.onBegin}
onPageSelected={(e) => this._onPageSelected(e.nativeEvent.position)}
scrollsToTop={false}
>
{this.props.children.map((c, idx) => <View key={idx} style={{flex: 1}}>{c}</View>)}
</ViewPager>;
},
});
module.exports = CarouselPager;