From bb8ff9260fe6a783171f35ce1a459927d8179d08 Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Tue, 8 Mar 2022 18:04:05 -0800 Subject: [PATCH] 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 --- .../facebook/react/views/scroll/ReactHorizontalScrollView.java | 2 ++ .../java/com/facebook/react/views/scroll/ReactScrollView.java | 2 ++ 2 files changed, 4 insertions(+) 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 006feb2ffac7f1..eb0de9d470e043 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 @@ -832,6 +832,8 @@ public void run() { private void cancelPostTouchScrolling() { if (mPostTouchRunnable != null) { removeCallbacks(mPostTouchRunnable); + mPostTouchRunnable = null; + getFlingAnimator().cancel(); } } 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 32261eb3dc967b..9c77f01ddc39b2 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 @@ -622,6 +622,8 @@ public void run() { private void cancelPostTouchScrolling() { if (mPostTouchRunnable != null) { removeCallbacks(mPostTouchRunnable); + mPostTouchRunnable = null; + getFlingAnimator().cancel(); } }