From 361b9a808c0097225ee7d3007f329e066cd80a03 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Tue, 19 Apr 2022 15:22:00 -0700 Subject: [PATCH] PointerEvents: Reset childHandlingNativeGesture on first ACTION_DOWN Summary: Changelog: [Internal] - Reset the mChildHandlingNativeGesture on the first ACTION_DOWN after it's been set. I noticed this issue when scrolling sometimes in the event log for the W3CPointerEvents example, none of the pointer events would get captured because we'd call [`notifyNativeGestureStarted`](https://www.internalfb.com/code/fbsource/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/NativeGestureUtil.java?lines=25-25) which would prevent any pointerevents being fired. Reviewed By: vincentriemer Differential Revision: D35685378 fbshipit-source-id: 01fc255afc5e22dc6c42f7eb11a8aa5a9a091b87 --- .../react/uimanager/JSPointerDispatcher.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java index 0bf85474793..71e06856e03 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java @@ -69,12 +69,6 @@ public class JSPointerDispatcher { } public void handleMotionEvent(MotionEvent motionEvent, EventDispatcher eventDispatcher) { - - // Ignore if child is handling native gesture - if (mChildHandlingNativeGesture != -1) { - return; - } - boolean supportsHover = PointerEventHelper.supportsHover(motionEvent.getToolType(motionEvent.getActionIndex())); @@ -101,6 +95,9 @@ public class JSPointerDispatcher { // First down pointer if (action == MotionEvent.ACTION_DOWN) { + // Reset mChildHandlingNativeGesture like JSTouchDispatcher does + mChildHandlingNativeGesture = -1; + // Start a "down" coalescing key mDownStartTime = motionEvent.getEventTime(); mTouchEventCoalescingKeyHelper.addCoalescingKey(mDownStartTime); @@ -119,6 +116,12 @@ public class JSPointerDispatcher { return; } + // If the touch was intercepted by a child, we've already sent a cancel event to JS for this + // gesture, so we shouldn't send any more pointer events related to it. + if (mChildHandlingNativeGesture != -1) { + return; + } + // New pointer goes down, this can only happen after ACTION_DOWN is sent for the first pointer if (action == MotionEvent.ACTION_POINTER_DOWN) { mTouchEventCoalescingKeyHelper.incrementCoalescingKey(mDownStartTime);