Add onPageScrollStateChanged for ViewPagerAndroid

Summary:
I have an issue when combining `PullToRefreshViewAndroid` and `ViewPagerAndroid`.
`ViewPagerAndroid` will not able to scroll that gesture handler is being taken by `PullToRefreshViewAndroid`
One solution is to disable `PullToRefreshViewAndroid` if `ViewPagerAndroid` is scrolling (i.e. not idle).
[Reference solution here](http://stackoverflow.com/a/29946734/2590265)

So here need to expose the `onPageScrollStateChanged` event.
Some code referenced from  DrawerLayoutAndroid, especially the `VIEWPAGER_PAGE_SCROLL_STATES` array.
Please feel free give me comments.
Thanks.
Closes https://github.com/facebook/react-native/pull/5026

Reviewed By: svcscm

Differential Revision: D2830623

Pulled By: andreicoman11

fb-gh-sync-id: c2a6920c6f4c7daab0115f13864db83b93b31abf
This commit is contained in:
Kudo Chien
2016-01-29 01:16:40 -08:00
committed by facebook-github-bot-9
parent 5e82094fcb
commit 8de86a0d65
5 changed files with 102 additions and 1 deletions

View File

@@ -19,6 +19,14 @@ var requireNativeComponent = require('requireNativeComponent');
var VIEWPAGER_REF = 'viewPager';
type Event = Object;
export type ViewPagerScrollState = $Enum<{
idle: string;
dragging: string;
settling: string;
}>;
/**
* Container that allows to flip left and right between child views. Each
* child view of the `ViewPagerAndroid` will be treated as a separate page
@@ -78,6 +86,16 @@ var ViewPagerAndroid = React.createClass({
*/
onPageScroll: ReactPropTypes.func,
/**
* Function called when the page scrolling state has changed.
* The page scrolling state can be in 3 states:
* - idle, meaning there is no interaction with the page scroller happening at the time
* - dragging, meaning there is currently an interaction with the page scroller
* - settling, meaning that there was an interaction with the page scroller, and the
* page scroller is now finishing it's closing or opening animation
*/
onPageScrollStateChanged: ReactPropTypes.func,
/**
* This callback will be called once ViewPager finish navigating to selected page
* (when user swipes between pages). The `event.nativeEvent` object passed to this
@@ -147,6 +165,12 @@ var ViewPagerAndroid = React.createClass({
}
},
_onPageScrollStateChanged: function(e: Event) {
if (this.props.onPageScrollStateChanged) {
this.props.onPageScrollStateChanged(e.nativeEvent.pageScrollState);
}
},
_onPageSelected: function(e: Event) {
if (this.props.onPageSelected) {
this.props.onPageSelected(e);
@@ -183,6 +207,7 @@ var ViewPagerAndroid = React.createClass({
ref={VIEWPAGER_REF}
style={this.props.style}
onPageScroll={this._onPageScroll}
onPageScrollStateChanged={this._onPageScrollStateChanged}
onPageSelected={this._onPageSelected}
children={this._childrenWithOverridenStyle()}
/>