From 0f0a3cfce29c75d0a37d90767157f5d0795db593 Mon Sep 17 00:00:00 2001 From: Peter Abbondanzo Date: Tue, 5 Aug 2025 09:42:36 -0700 Subject: [PATCH] Provide ReactContext to experimental JSTouchDispatcher method (#53003) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53003 The new `onChildStartedNativeGesture` method accepts a nullable `ReactContext` value for the purpose of flushing active touch events. This change updates all callsites of that method to pass a `ReactContext` Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D79258727 fbshipit-source-id: 7b2950f514295dbe26822442c98079b8121cb3bf --- .../src/main/java/com/facebook/react/ReactRootView.java | 9 +++++++-- .../com/facebook/react/views/modal/ReactModalHostView.kt | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 8909f548371..cf143a7c6a6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -205,10 +205,15 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot { return; } + @Nullable ReactContext reactContext = getCurrentReactContext(); + if (reactContext == null) { + return; + } + EventDispatcher eventDispatcher = - UIManagerHelper.getEventDispatcher(getCurrentReactContext(), getUIManagerType()); + UIManagerHelper.getEventDispatcher(reactContext, getUIManagerType()); if (eventDispatcher != null) { - mJSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher); + mJSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher, reactContext); if (childView != null && mJSPointerDispatcher != null) { mJSPointerDispatcher.onChildStartedNativeGesture(childView, ev, eventDispatcher); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt index 1126b992da0..4e82b62376c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt @@ -37,6 +37,7 @@ import com.facebook.react.bridge.ReactContext import com.facebook.react.bridge.UiThreadUtil import com.facebook.react.bridge.WritableMap import com.facebook.react.bridge.WritableNativeMap +import com.facebook.react.common.annotations.UnstableReactNativeAPI import com.facebook.react.common.annotations.VisibleForTesting import com.facebook.react.common.build.ReactBuildConfig import com.facebook.react.config.ReactFeatureFlags @@ -619,9 +620,10 @@ public class ReactModalHostView(context: ThemedReactContext) : return super.onHoverEvent(event) } + @OptIn(UnstableReactNativeAPI::class) override fun onChildStartedNativeGesture(childView: View?, ev: MotionEvent) { eventDispatcher?.let { eventDispatcher -> - jSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher) + jSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher, reactContext) jSPointerDispatcher?.onChildStartedNativeGesture(childView, ev, eventDispatcher) } }