From 143a0f74b86bf2593dd29ce3c85d73d703d7a9f5 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Wed, 20 Jul 2022 17:58:01 -0700 Subject: [PATCH] Fix (Pointer|Touch)Events not firing after drag and scroll for ScrollView and HorizontalScrollView Summary: Changelog: [Android][Fixed] - Fix such that when the scrollviews call `onChildStartedNativeGesture`, they appropriately call `onChildEndedNativeGesture` to unlock the native gesture such that `JSTouchDispatcher` or `JSPointerDispatcher` will continue to emit events. ### How did we find this issue? As React Native is adding pointer event support for different input types, we noticed after pressing and dragging on a ScrollView, hover events would not fire. ### Why was this not an issue before? This was always an issue -- it was just that `JSTouchDispatcher` worked its way around it by explicitly setting `mChildIsHandlingNativeGesture = false` on a `ACTION_DOWN` event, [code pointer](https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java#L76). Similarly, `JSPointerDispatcher` [copied this logic](https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java#L106). With new hover support in `JSPointerDispatcher` no similar workaround was put in (or even a good place to insert). ### What's next? * As a follow-up, we should look at removing this workaround (at least for `JSPointerDispatcher`) * By searching for usages of where we `notifyNativeGestureStarted`, it looks like `ReactDrawerLayout` and `ReactSwipeRefreshLayout` both do and don't call the symmetric `notifyNativeGestureEnded`. This will likely be an issue in the future (or maybe if we remove the workaround) Reviewed By: mdvacca Differential Revision: D37977982 fbshipit-source-id: 0d18767f4debbf24cfb24b54df1310f6f96a0d03 --- .../facebook/react/views/scroll/ReactHorizontalScrollView.java | 1 + .../java/com/facebook/react/views/scroll/ReactScrollView.java | 1 + 2 files changed, 2 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 964c8d721ba8ff..3c962f03565a12 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 @@ -532,6 +532,7 @@ public boolean onTouchEvent(MotionEvent ev) { float velocityX = mVelocityHelper.getXVelocity(); float velocityY = mVelocityHelper.getYVelocity(); ReactScrollViewHelper.emitScrollEndDragEvent(this, velocityX, velocityY); + NativeGestureUtil.notifyNativeGestureEnded(this, ev); mDragging = false; // After the touch finishes, we may need to do some scrolling afterwards either as a result // of a fling or because we need to page align the content 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 7f44e14e432ff9..69da5b3af197a4 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 @@ -404,6 +404,7 @@ public boolean onTouchEvent(MotionEvent ev) { float velocityX = mVelocityHelper.getXVelocity(); float velocityY = mVelocityHelper.getYVelocity(); ReactScrollViewHelper.emitScrollEndDragEvent(this, velocityX, velocityY); + NativeGestureUtil.notifyNativeGestureEnded(this, ev); mDragging = false; // After the touch finishes, we may need to do some scrolling afterwards either as a result // of a fling or because we need to page align the content