Skip to content

Commit

Permalink
Cancel the post touch fling when new touch is registered
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryancat authored and facebook-github-bot committed Mar 4, 2022
1 parent ab45138 commit 0368081
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0368081

Please sign in to comment.