forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 facebook#5026 Reviewed By: svcscm Differential Revision: D2830623 Pulled By: andreicoman11 fb-gh-sync-id: c2a6920c6f4c7daab0115f13864db83b93b31abf
- Loading branch information
Showing
5 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...Android/src/main/java/com/facebook/react/views/viewpager/PageScrollStateChangedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.views.viewpager; | ||
|
||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.WritableMap; | ||
import com.facebook.react.uimanager.events.Event; | ||
import com.facebook.react.uimanager.events.RCTEventEmitter; | ||
|
||
/** | ||
* Event emitted by {@link ReactViewPager} when user scrolling state changed. | ||
* | ||
* Additional data provided by this event: | ||
* - pageScrollState - {Idle,Dragging,Settling} | ||
*/ | ||
class PageScrollStateChangedEvent extends Event<PageScrollStateChangedEvent> { | ||
|
||
public static final String EVENT_NAME = "topPageScrollStateChanged"; | ||
|
||
private final String mPageScrollState; | ||
|
||
protected PageScrollStateChangedEvent(int viewTag, long timestampMs, String pageScrollState) { | ||
super(viewTag, timestampMs); | ||
mPageScrollState = pageScrollState; | ||
} | ||
|
||
@Override | ||
public String getEventName() { | ||
return EVENT_NAME; | ||
} | ||
|
||
@Override | ||
public void dispatch(RCTEventEmitter rctEventEmitter) { | ||
rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData()); | ||
} | ||
|
||
private WritableMap serializeEventData() { | ||
WritableMap eventData = Arguments.createMap(); | ||
eventData.putString("pageScrollState", mPageScrollState); | ||
return eventData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters