forked from nick/react-native-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarouselPager.js
37 lines (32 loc) · 964 Bytes
/
CarouselPager.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
var React = require('react');
var {
ScrollView,
} = require('react-native');
var CarouselPager = React.createClass({
scrollToPage(page, animated) {
if (typeof animated === 'undefined') {
animated = true;
}
this.refs.scrollView.scrollTo({x: page * this.props.width, y: 0, animated: animated});
},
_onMomentumScrollEnd(e) {
var activePage = e.nativeEvent.contentOffset.x / this.props.width;
this.props.onEnd(activePage);
},
render() {
return <ScrollView ref="scrollView"
contentContainerStyle={this.props.contentContainerStyle}
automaticallyAdjustContentInsets={false}
horizontal={true}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
bounces={false}
onScrollBeginDrag={this.props.onBegin}
onMomentumScrollEnd={this._onMomentumScrollEnd}
scrollsToTop={false}
>
{this.props.children}
</ScrollView>;
},
});
module.exports = CarouselPager;