mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
Add ability to disable scroll on android ViewPager
Summary: Similar to ScrollView, adds ability to set scrollEnabled={false}, which prevents dragging. Paging is still possible by updating initialPage. Reviewed By: AaaChiuuu Differential Revision: D3209743 fb-gh-sync-id: ce4140323a03f2257a9bb310c7285418b01abae7 fbshipit-source-id: ce4140323a03f2257a9bb310c7285418b01abae7
This commit is contained in:
parent
a0f6704d44
commit
5a93877673
@ -123,6 +123,12 @@ var ViewPagerAndroid = React.createClass({
|
||||
'none', // default
|
||||
'on-drag',
|
||||
]),
|
||||
|
||||
/**
|
||||
* When false, the content does not scroll.
|
||||
* The default value is true.
|
||||
*/
|
||||
scrollEnabled: React.PropTypes.bool,
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
|
@ -125,6 +125,7 @@ import com.facebook.react.uimanager.events.NativeGestureUtil;
|
||||
|
||||
private final EventDispatcher mEventDispatcher;
|
||||
private boolean mIsCurrentItemFromJs;
|
||||
private boolean mScrollEnabled = true;
|
||||
|
||||
public ReactViewPager(ReactContext reactContext) {
|
||||
super(reactContext);
|
||||
@ -141,19 +142,31 @@ import com.facebook.react.uimanager.events.NativeGestureUtil;
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if (super.onInterceptTouchEvent(ev)) {
|
||||
if (mScrollEnabled && super.onInterceptTouchEvent(ev)) {
|
||||
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (!mScrollEnabled) {
|
||||
return false;
|
||||
}
|
||||
return super.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
public void setCurrentItemFromJs(int item, boolean animated) {
|
||||
mIsCurrentItemFromJs = true;
|
||||
setCurrentItem(item, animated);
|
||||
mIsCurrentItemFromJs = false;
|
||||
}
|
||||
|
||||
public void setScrollEnabled(boolean scrollEnabled) {
|
||||
mScrollEnabled = scrollEnabled;
|
||||
}
|
||||
|
||||
/*package*/ void addViewToAdapter(View child, int index) {
|
||||
getAdapter().addView(child, index);
|
||||
}
|
||||
|
@ -43,6 +43,12 @@ public class ReactViewPagerManager extends ViewGroupManager<ReactViewPager> {
|
||||
return new ReactViewPager(reactContext);
|
||||
}
|
||||
|
||||
|
||||
@ReactProp(name = "scrollEnabled", defaultBoolean = true)
|
||||
public void setScrollEnabled(ReactViewPager viewPager, boolean value) {
|
||||
viewPager.setScrollEnabled(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsCustomLayoutForChildren() {
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user