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
This commit is contained in:
Kevin Gozali
2022-06-06 10:51:58 -07:00
committed by Facebook GitHub Bot
parent 086c13dd5f
commit f0b5d42b50
2 changed files with 3 additions and 2 deletions
@@ -72,10 +72,11 @@ public abstract class Event<T extends Event> {
// 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.
@@ -86,7 +86,7 @@ public class ReactEventEmitter implements RCTModernEventEmitter {
@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) {