Skip to content

Commit

Permalink
Android: Dispatch root view touch events to the right dispatcher
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fkgozali authored and facebook-github-bot committed Jun 6, 2022
1 parent 086c13d commit f0b5d42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f0b5d42

Please sign in to comment.