diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index 879acf55a78e66..1317c6e43de921 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -531,7 +531,7 @@ public boolean onTouchEvent(MotionEvent ev) { } mVelocityHelper.calculateVelocity(ev); - int action = ev.getAction() & MotionEvent.ACTION_MASK; + int action = ev.getActionMasked(); if (action == MotionEvent.ACTION_UP && mDragging) { ReactScrollViewHelper.updateFabricScrollState(this); @@ -544,6 +544,10 @@ public boolean onTouchEvent(MotionEvent ev) { handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY)); } + if (action == MotionEvent.ACTION_DOWN) { + cancelPostTouchScrolling(); + } + return super.onTouchEvent(ev); } @@ -821,6 +825,12 @@ public void run() { this, mPostTouchRunnable, ReactScrollViewHelper.MOMENTUM_DELAY); } + private void cancelPostTouchScrolling() { + if (mPostTouchRunnable != null) { + removeCallbacks(mPostTouchRunnable); + } + } + private int predictFinalScrollPosition(int velocityX) { // predict where a fling would end up so we can scroll to the nearest snap offset final int maximumOffset = Math.max(0, computeHorizontalScrollRange() - getWidth()); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index 4c832ab6f09f23..3fbfb7a4d52e55 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -369,7 +369,7 @@ public boolean onTouchEvent(MotionEvent ev) { } mVelocityHelper.calculateVelocity(ev); - int action = ev.getAction() & MotionEvent.ACTION_MASK; + int action = ev.getActionMasked(); if (action == MotionEvent.ACTION_UP && mDragging) { ReactScrollViewHelper.updateFabricScrollState(this); @@ -382,6 +382,10 @@ public boolean onTouchEvent(MotionEvent ev) { handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY)); } + if (action == MotionEvent.ACTION_DOWN) { + cancelPostTouchScrolling(); + } + return super.onTouchEvent(ev); } @@ -611,6 +615,12 @@ public void run() { this, mPostTouchRunnable, ReactScrollViewHelper.MOMENTUM_DELAY); } + private void cancelPostTouchScrolling() { + if (mPostTouchRunnable != null) { + removeCallbacks(mPostTouchRunnable); + } + } + private int predictFinalScrollPosition(int velocityY) { // predict where a fling would end up so we can scroll to the nearest snap offset // TODO(T106335409): Existing prediction still uses overscroller. Consider change this to use