Add scrollEnabled prop to Android ScrollView
Summary: Perhaps there is a better way to do this, curious to hear it! - If momentum scroll is active when `scrollEnabled` is toggled, the momentum scroll continues and the onMomentumScrollEnd event fires, which is the same as on iOS. Closes https://github.com/facebook/react-native/pull/5656 Reviewed By: svcscm Differential Revision: D2889897 Pulled By: dmmiller fb-gh-sync-id: b2f44d2bcb48373f9945f6afd966447a118df717
This commit is contained in:
parent
98373ac6e3
commit
82b0df9d2a
|
@ -227,7 +227,6 @@ var ScrollView = React.createClass({
|
|||
/**
|
||||
* When false, the content does not scroll.
|
||||
* The default value is true.
|
||||
* @platform ios
|
||||
*/
|
||||
scrollEnabled: PropTypes.bool,
|
||||
/**
|
||||
|
|
|
@ -31,13 +31,13 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
|
|||
|
||||
private final OnScrollDispatchHelper mOnScrollDispatchHelper = new OnScrollDispatchHelper();
|
||||
|
||||
private boolean mRemoveClippedSubviews;
|
||||
private boolean mSendMomentumEvents;
|
||||
private @Nullable Rect mClippingRect;
|
||||
private boolean mDoneFlinging;
|
||||
private boolean mDragging;
|
||||
private boolean mFlinging;
|
||||
private boolean mDoneFlinging;
|
||||
|
||||
private @Nullable Rect mClippingRect;
|
||||
private boolean mRemoveClippedSubviews;
|
||||
private boolean mScrollEnabled = true;
|
||||
private boolean mSendMomentumEvents;
|
||||
|
||||
public ReactHorizontalScrollView(Context context) {
|
||||
super(context);
|
||||
|
@ -61,6 +61,10 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
|
|||
mSendMomentumEvents = sendMomentumEvents;
|
||||
}
|
||||
|
||||
public void setScrollEnabled(boolean scrollEnabled) {
|
||||
mScrollEnabled = scrollEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
MeasureSpecAssertions.assertExplicitMeasureSpec(widthMeasureSpec, heightMeasureSpec);
|
||||
|
@ -95,6 +99,10 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
|
|||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if (!mScrollEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (super.onInterceptTouchEvent(ev)) {
|
||||
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
|
||||
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
|
||||
|
@ -107,6 +115,10 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
|
|||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (!mScrollEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int action = ev.getAction() & MotionEvent.ACTION_MASK;
|
||||
if (action == MotionEvent.ACTION_UP && mDragging) {
|
||||
ReactScrollViewHelper.emitScrollEndDragEvent(this);
|
||||
|
|
|
@ -39,17 +39,21 @@ public class ReactHorizontalScrollViewManager
|
|||
return new ReactHorizontalScrollView(context);
|
||||
}
|
||||
|
||||
@ReactProp(name = ReactClippingViewGroupHelper.PROP_REMOVE_CLIPPED_SUBVIEWS)
|
||||
public void setRemoveClippedSubviews(ReactHorizontalScrollView view, boolean removeClippedSubviews) {
|
||||
view.setRemoveClippedSubviews(removeClippedSubviews);
|
||||
@ReactProp(name = "scrollEnabled", defaultBoolean = true)
|
||||
public void setScrollEnabled(ReactHorizontalScrollView view, boolean value) {
|
||||
view.setScrollEnabled(value);
|
||||
}
|
||||
|
||||
|
||||
@ReactProp(name = "showsHorizontalScrollIndicator")
|
||||
public void setShowsHorizontalScrollIndicator(ReactHorizontalScrollView view, boolean value) {
|
||||
view.setHorizontalScrollBarEnabled(value);
|
||||
}
|
||||
|
||||
@ReactProp(name = ReactClippingViewGroupHelper.PROP_REMOVE_CLIPPED_SUBVIEWS)
|
||||
public void setRemoveClippedSubviews(ReactHorizontalScrollView view, boolean removeClippedSubviews) {
|
||||
view.setRemoveClippedSubviews(removeClippedSubviews);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computing momentum events is potentially expensive since we post a runnable on the UI thread
|
||||
* to see when it is done. We only do that if {@param sendMomentumEvents} is set to true. This
|
||||
|
|
|
@ -34,12 +34,13 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou
|
|||
|
||||
private final OnScrollDispatchHelper mOnScrollDispatchHelper = new OnScrollDispatchHelper();
|
||||
|
||||
private boolean mRemoveClippedSubviews;
|
||||
private @Nullable Rect mClippingRect;
|
||||
private boolean mSendMomentumEvents;
|
||||
private boolean mDoneFlinging;
|
||||
private boolean mDragging;
|
||||
private boolean mFlinging;
|
||||
private boolean mDoneFlinging;
|
||||
private boolean mRemoveClippedSubviews;
|
||||
private boolean mScrollEnabled = true;
|
||||
private boolean mSendMomentumEvents;
|
||||
|
||||
public ReactScrollView(Context context) {
|
||||
super(context);
|
||||
|
@ -49,6 +50,10 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou
|
|||
mSendMomentumEvents = sendMomentumEvents;
|
||||
}
|
||||
|
||||
public void setScrollEnabled(boolean scrollEnabled) {
|
||||
mScrollEnabled = scrollEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
MeasureSpecAssertions.assertExplicitMeasureSpec(widthMeasureSpec, heightMeasureSpec);
|
||||
|
@ -99,6 +104,10 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou
|
|||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if (!mScrollEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (super.onInterceptTouchEvent(ev)) {
|
||||
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
|
||||
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
|
||||
|
@ -111,6 +120,10 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou
|
|||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (!mScrollEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int action = ev.getAction() & MotionEvent.ACTION_MASK;
|
||||
if (action == MotionEvent.ACTION_UP && mDragging) {
|
||||
ReactScrollViewHelper.emitScrollEndDragEvent(this);
|
||||
|
|
|
@ -42,6 +42,11 @@ public class ReactScrollViewManager
|
|||
return new ReactScrollView(context);
|
||||
}
|
||||
|
||||
@ReactProp(name = "scrollEnabled", defaultBoolean = true)
|
||||
public void setScrollEnabled(ReactScrollView view, boolean value) {
|
||||
view.setScrollEnabled(value);
|
||||
}
|
||||
|
||||
@ReactProp(name = "showsVerticalScrollIndicator")
|
||||
public void setShowsVerticalScrollIndicator(ReactScrollView view, boolean value) {
|
||||
view.setVerticalScrollBarEnabled(value);
|
||||
|
|
Loading…
Reference in New Issue