From f0b5d42b503256c0bbac177a316e37657819a885 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Mon, 6 Jun 2022 10:51:58 -0700 Subject: [PATCH] Android: Dispatch root view touch events to the right dispatcher Summary: When tapping on ReactRootView and having Fabric enabled, the touch logic mistakenly dispatch the event to JS via the legacy renderer. This is because the destination was computed based on reactTag (odd = legacy, even = Fabric), but root view tag happens to be always odd (always ends with 1). This change uses the right destination based on what the Event itself tells us, instead of deriving from the reactTag. Changelog: [Android][Fixed] Fix Fabric touch event dispatching for root views Reviewed By: JoshuaGross, sshic Differential Revision: D36917300 fbshipit-source-id: 838b4e135d7df07c37040bd47d71370ff10df067 --- .../main/java/com/facebook/react/uimanager/events/Event.java | 3 ++- .../com/facebook/react/uimanager/events/ReactEventEmitter.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 61665a11dd944c..94515d47be1273 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 @@ -72,10 +72,11 @@ protected void init(int surfaceId, int viewTag, long timestampMs) { // We infer UIManagerType. Even though it's not passed in explicitly, we have a // contract that Fabric events *always* have a SurfaceId passed in, and non-Fabric events // NEVER have a SurfaceId passed in (the default/placeholder of -1 is passed in instead). + // // Why does this matter? // Events can be sent to Views that are part of the View hierarchy *but not directly managed // by React Native*. For example, embedded custom hierachies, Litho hierachies, etc. - // In those cases it's important to konw that the Event should be sent to the Fabric or + // In those cases it's important to know that the Event should be sent to the Fabric or // non-Fabric UIManager, and we cannot use the ViewTag for inference since it's not controlled // by RN and is essentially a random number. // At some point it would be great to pass the SurfaceContext here instead. diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java index a1eb560914b6e4..b1098cb0f63e04 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java @@ -86,7 +86,7 @@ public void receiveTouches( @Override public void receiveTouches(TouchEvent event) { int reactTag = event.getViewTag(); - @UIManagerType int uiManagerType = ViewUtil.getUIManagerType(reactTag); + @UIManagerType int uiManagerType = event.getUIManagerType(); if (uiManagerType == UIManagerType.FABRIC && mFabricEventEmitter != null) { mFabricEventEmitter.receiveTouches(event); } else if (uiManagerType == UIManagerType.DEFAULT && getEventEmitter(reactTag) != null) {