diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt index 0948dc932ee..a4e0807fbea 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt @@ -116,7 +116,8 @@ public class ReactSurfaceView(context: Context?, private val surface: ReactSurfa */ override fun onChildStartedNativeGesture(childView: View?, ev: MotionEvent) { val eventDispatcher = surface.eventDispatcher ?: return - jsTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher) + jsTouchDispatcher.onChildStartedNativeGesture( + ev, eventDispatcher, surface.reactHost?.currentReactContext) childView?.let { jsPointerDispatcher?.onChildStartedNativeGesture(it, ev, eventDispatcher) } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.kt index 86250eaa604..b28b674581a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.kt @@ -13,6 +13,8 @@ import com.facebook.common.logging.FLog import com.facebook.infer.annotation.Assertions import com.facebook.react.bridge.ReactContext import com.facebook.react.common.ReactConstants +import com.facebook.react.common.annotations.UnstableReactNativeAPI +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags import com.facebook.react.uimanager.common.UIManagerType import com.facebook.react.uimanager.events.EventDispatcher import com.facebook.react.uimanager.events.TouchEvent @@ -33,9 +35,19 @@ public class JSTouchDispatcher(private val viewGroup: ViewGroup) { private val touchEventCoalescingKeyHelper: TouchEventCoalescingKeyHelper = TouchEventCoalescingKeyHelper() + @OptIn(UnstableReactNativeAPI::class) public fun onChildStartedNativeGesture( androidEvent: MotionEvent, eventDispatcher: EventDispatcher + ) { + onChildStartedNativeGesture(androidEvent, eventDispatcher, null) + } + + @UnstableReactNativeAPI + public fun onChildStartedNativeGesture( + androidEvent: MotionEvent, + eventDispatcher: EventDispatcher, + reactContext: ReactContext?, ) { if (childIsHandlingNativeGesture) { // This means we previously had another child start handling this native gesture and now a @@ -46,6 +58,12 @@ public class JSTouchDispatcher(private val viewGroup: ViewGroup) { dispatchCancelEvent(androidEvent, eventDispatcher) childIsHandlingNativeGesture = true + + if (targetTag != -1 && ReactNativeFeatureFlags.sweepActiveTouchOnChildNativeGesturesAndroid()) { + val surfaceId = UIManagerHelper.getSurfaceId(viewGroup) + sweepActiveTouchForTag(surfaceId, targetTag, reactContext) + } + targetTag = -1 }