Skip to content

Commit 0368081

Browse files
ryancatfacebook-github-bot
authored andcommitted
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 (a3146e41a259175f0c79e3c213523a0fb21613d7)?dst_version_fbid=507451319451602&transaction_fbid=1615731455398227) in an old diff D3207608 (a3146e4). 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
1 parent ab45138 commit 0368081

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public boolean onTouchEvent(MotionEvent ev) {
531531
}
532532

533533
mVelocityHelper.calculateVelocity(ev);
534-
int action = ev.getAction() & MotionEvent.ACTION_MASK;
534+
int action = ev.getActionMasked();
535535
if (action == MotionEvent.ACTION_UP && mDragging) {
536536
ReactScrollViewHelper.updateFabricScrollState(this);
537537

@@ -544,6 +544,10 @@ public boolean onTouchEvent(MotionEvent ev) {
544544
handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY));
545545
}
546546

547+
if (action == MotionEvent.ACTION_DOWN) {
548+
cancelPostTouchScrolling();
549+
}
550+
547551
return super.onTouchEvent(ev);
548552
}
549553

@@ -821,6 +825,12 @@ public void run() {
821825
this, mPostTouchRunnable, ReactScrollViewHelper.MOMENTUM_DELAY);
822826
}
823827

828+
private void cancelPostTouchScrolling() {
829+
if (mPostTouchRunnable != null) {
830+
removeCallbacks(mPostTouchRunnable);
831+
}
832+
}
833+
824834
private int predictFinalScrollPosition(int velocityX) {
825835
// predict where a fling would end up so we can scroll to the nearest snap offset
826836
final int maximumOffset = Math.max(0, computeHorizontalScrollRange() - getWidth());

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public boolean onTouchEvent(MotionEvent ev) {
369369
}
370370

371371
mVelocityHelper.calculateVelocity(ev);
372-
int action = ev.getAction() & MotionEvent.ACTION_MASK;
372+
int action = ev.getActionMasked();
373373
if (action == MotionEvent.ACTION_UP && mDragging) {
374374
ReactScrollViewHelper.updateFabricScrollState(this);
375375

@@ -382,6 +382,10 @@ public boolean onTouchEvent(MotionEvent ev) {
382382
handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY));
383383
}
384384

385+
if (action == MotionEvent.ACTION_DOWN) {
386+
cancelPostTouchScrolling();
387+
}
388+
385389
return super.onTouchEvent(ev);
386390
}
387391

@@ -611,6 +615,12 @@ public void run() {
611615
this, mPostTouchRunnable, ReactScrollViewHelper.MOMENTUM_DELAY);
612616
}
613617

618+
private void cancelPostTouchScrolling() {
619+
if (mPostTouchRunnable != null) {
620+
removeCallbacks(mPostTouchRunnable);
621+
}
622+
}
623+
614624
private int predictFinalScrollPosition(int velocityY) {
615625
// predict where a fling would end up so we can scroll to the nearest snap offset
616626
// TODO(T106335409): Existing prediction still uses overscroller. Consider change this to use

0 commit comments

Comments
 (0)