Fix issue with interruptted scroll cause touch in scroll view unresponsive

Summary:
This diff fixed an issue that caused regression in fb4a and React Native panel apps regarding scrolling behavior. When scrolling in either horizontal or vertical scroll view, if the consecutive touch interrupted the previous fling (post touch scrolling), the scroll view would block touch event from dispatching to the content view. Thus, the items in scroll view are not responding to touch events anymore.

The diff that caused this issue is D34627330 (https://github.com/facebook/react-native/commit/0368081858193d7c2537acd9080d11bb701ee98b). In that diff, I added code to cancel the scheduled post touch runnable when touch down is received in scroll view. That is expected as the post touch runnable is to handle snapping scroll case, where [an extra fling](https://fburl.com/code/7qza1ece) is triggered to make sure scroll view stops at the right position. When user touch the screen before the previous scroll fling finishes, this post processing is no longer needed -- the new touch should take full control of scroll view.

However, in D34627330 (https://github.com/facebook/react-native/commit/0368081858193d7c2537acd9080d11bb701ee98b), I failed to reset the runnable instance `mPostTouchRunnable` to null when cancelling it. This caused the future post touch handle logic [stops to run](https://fburl.com/code/lh8pi7l0), as it thinks the runnable is non-null and has been scheduled. This prevents fabric from receiving proper scroll state updates from android side, thus causing a state corruption and affects logic to decide where the scroll offset is and where the child item is after that.

This diff fixed the issue by resetting the runnable instance, as well as making sure if the runnable is already running and the extra fling starts, we are canceling that fling animation properly.

Changelog:
[Android][Fixed] - Fixed regression on content in scroll view not responding to touch when fling got interrupted

Reviewed By: ShikaSD

Differential Revision: D34734129

fbshipit-source-id: 7d7689d203ce76c59cd44e16e31582317bb409bd
This commit is contained in:
Xin Chen
2022-03-08 18:04:05 -08:00
committed by Facebook GitHub Bot
parent c34ef5841c
commit bb8ff9260f
2 changed files with 4 additions and 0 deletions
@@ -832,6 +832,8 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
private void cancelPostTouchScrolling() {
if (mPostTouchRunnable != null) {
removeCallbacks(mPostTouchRunnable);
mPostTouchRunnable = null;
getFlingAnimator().cancel();
}
}
@@ -622,6 +622,8 @@ public class ReactScrollView extends ScrollView
private void cancelPostTouchScrolling() {
if (mPostTouchRunnable != null) {
removeCallbacks(mPostTouchRunnable);
mPostTouchRunnable = null;
getFlingAnimator().cancel();
}
}