mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Cancel the post touch fling when new touch is registered
Summary: This diff aims to fix an issue I found while working on T113264056. It's to address the [comment](https://www.internalfb.com/diff/D3207608 (https://github.com/facebook/react-native/commit/a3146e41a259175f0c79e3c213523a0fb21613d7)?dst_version_fbid=507451319451602&transaction_fbid=1615731455398227) in an old diff D3207608 (https://github.com/facebook/react-native/commit/a3146e41a259175f0c79e3c213523a0fb21613d7). That issue begins to surface after I made the change in the next diff, which is discussed in detail in the task description (T113385381). The fix here is to cancel the post touch processing when a new touch down is received. This should've cancel any previous post touch processing as the new touch should take full control of scrolling. Changelog: [Android][Fixed] - Cancel post touch process when new touch is received Reviewed By: javache Differential Revision: D34627330 fbshipit-source-id: 1fb8cfc1a4d94349b5290915a0a9f190186f2af3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ab45138394
commit
0368081858
+11
-1
@@ -531,7 +531,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
}
|
||||
|
||||
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 class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY));
|
||||
}
|
||||
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
cancelPostTouchScrolling();
|
||||
}
|
||||
|
||||
return super.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
@@ -821,6 +825,12 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
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());
|
||||
|
||||
@@ -369,7 +369,7 @@ public class ReactScrollView extends ScrollView
|
||||
}
|
||||
|
||||
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 class ReactScrollView extends ScrollView
|
||||
handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY));
|
||||
}
|
||||
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
cancelPostTouchScrolling();
|
||||
}
|
||||
|
||||
return super.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
@@ -611,6 +615,12 @@ public class ReactScrollView extends ScrollView
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user