Skip to content

Commit f0b5d42

Browse files
fkgozalifacebook-github-bot
authored andcommitted
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
1 parent 086c13d commit f0b5d42

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/events/Event.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ protected void init(int surfaceId, int viewTag, long timestampMs) {
7272
// We infer UIManagerType. Even though it's not passed in explicitly, we have a
7373
// contract that Fabric events *always* have a SurfaceId passed in, and non-Fabric events
7474
// NEVER have a SurfaceId passed in (the default/placeholder of -1 is passed in instead).
75+
//
7576
// Why does this matter?
7677
// Events can be sent to Views that are part of the View hierarchy *but not directly managed
7778
// by React Native*. For example, embedded custom hierachies, Litho hierachies, etc.
78-
// In those cases it's important to konw that the Event should be sent to the Fabric or
79+
// In those cases it's important to know that the Event should be sent to the Fabric or
7980
// non-Fabric UIManager, and we cannot use the ViewTag for inference since it's not controlled
8081
// by RN and is essentially a random number.
8182
// At some point it would be great to pass the SurfaceContext here instead.

ReactAndroid/src/main/java/com/facebook/react/uimanager/events/ReactEventEmitter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void receiveTouches(
8686
@Override
8787
public void receiveTouches(TouchEvent event) {
8888
int reactTag = event.getViewTag();
89-
@UIManagerType int uiManagerType = ViewUtil.getUIManagerType(reactTag);
89+
@UIManagerType int uiManagerType = event.getUIManagerType();
9090
if (uiManagerType == UIManagerType.FABRIC && mFabricEventEmitter != null) {
9191
mFabricEventEmitter.receiveTouches(event);
9292
} else if (uiManagerType == UIManagerType.DEFAULT && getEventEmitter(reactTag) != null) {

0 commit comments

Comments
 (0)