diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java index d494c6a0aefe46..d3b8043d6550a7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java @@ -12,7 +12,6 @@ import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; import com.facebook.react.common.ReactConstants; -import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.TouchEvent; import com.facebook.react.uimanager.events.TouchEventCoalescingKeyHelper; @@ -75,7 +74,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) { mTargetTag = findTargetTagAndSetCoordinates(ev); eventDispatcher.dispatchEvent( TouchEvent.obtain( - Event.getSurfaceIdForView(mRootViewGroup), + UIManagerHelper.getSurfaceId(mRootViewGroup), mTargetTag, TouchEventType.START, ev, @@ -100,7 +99,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) { findTargetTagAndSetCoordinates(ev); eventDispatcher.dispatchEvent( TouchEvent.obtain( - Event.getSurfaceIdForView(mRootViewGroup), + UIManagerHelper.getSurfaceId(mRootViewGroup), mTargetTag, TouchEventType.END, ev, @@ -115,7 +114,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) { findTargetTagAndSetCoordinates(ev); eventDispatcher.dispatchEvent( TouchEvent.obtain( - Event.getSurfaceIdForView(mRootViewGroup), + UIManagerHelper.getSurfaceId(mRootViewGroup), mTargetTag, TouchEventType.MOVE, ev, @@ -127,7 +126,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) { // New pointer goes down, this can only happen after ACTION_DOWN is sent for the first pointer eventDispatcher.dispatchEvent( TouchEvent.obtain( - Event.getSurfaceIdForView(mRootViewGroup), + UIManagerHelper.getSurfaceId(mRootViewGroup), mTargetTag, TouchEventType.START, ev, @@ -139,7 +138,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) { // Exactly one of the pointers goes up eventDispatcher.dispatchEvent( TouchEvent.obtain( - Event.getSurfaceIdForView(mRootViewGroup), + UIManagerHelper.getSurfaceId(mRootViewGroup), mTargetTag, TouchEventType.END, ev, @@ -188,7 +187,7 @@ private void dispatchCancelEvent(MotionEvent androidEvent, EventDispatcher event Assertions.assertNotNull(eventDispatcher) .dispatchEvent( TouchEvent.obtain( - Event.getSurfaceIdForView(mRootViewGroup), + UIManagerHelper.getSurfaceId(mRootViewGroup), mTargetTag, TouchEventType.CANCEL, androidEvent, diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java index 9effc356f7f018..76a0fc08dbd096 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.java @@ -160,10 +160,18 @@ public static ReactContext getReactContext(View view) { } /** - * @return Get the ThemedReactContext associated with a View, if possible, and then call - * getSurfaceId on it. See above (getReactContext) for additional context. + * @return Gets the surfaceId for the {@link ThemedReactContext} associated with a View, if + * possible, and then call getSurfaceId on it. See above (getReactContext) for additional + * context. + *
For RootViews, the root's rootViewTag is returned + *
Returns -1 for non-Fabric views
*/
public static int getSurfaceId(View view) {
+ if (view instanceof ReactRoot) {
+ ReactRoot rootView = (ReactRoot) view;
+ return rootView.getUIManagerType() == UIManagerType.FABRIC ? rootView.getRootViewTag() : -1;
+ }
+
int reactTag = view.getId();
// In non-Fabric we don't have (or use) SurfaceId
@@ -177,9 +185,8 @@ public static int getSurfaceId(View view) {
}
int surfaceId = getSurfaceId(context);
-
- // All Fabric-managed Views (should) have a ThemedReactContext attached.
if (surfaceId == -1) {
+ // All Fabric-managed Views (should) have a ThemedReactContext attached.
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalStateException(
diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java
index bf7b9a4150eccc..b205bdeb3c76fb 100644
--- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java
+++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java
@@ -7,13 +7,10 @@
package com.facebook.react.uimanager.events;
-import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.SystemClock;
import com.facebook.react.uimanager.IllegalViewOperationException;
-import com.facebook.react.uimanager.ReactRoot;
-import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.common.UIManagerType;
/**
@@ -43,23 +40,6 @@ public abstract class Event