Skip to content

Commit 52b45a4

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Event should infer UIManagerType by presence of SurfaceId
Summary: See comments inline for motivation. It's not safe to use viewtag of an Event to infer whether or not the view is in a Fabric or non-Fabric RootView. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D28365566 fbshipit-source-id: 187ddcc5d5a43a31a71232fdb2f1f5b334bec8c2
1 parent 263478b commit 52b45a4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedNodesManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ private void handleEvent(Event event) {
535535
return;
536536
}
537537
UIManager uiManager =
538-
UIManagerHelper.getUIManagerForReactTag(mReactApplicationContext, event.getViewTag());
538+
UIManagerHelper.getUIManager(mReactApplicationContext, event.getUIManagerType());
539539
if (uiManager == null) {
540540
return;
541541
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.facebook.react.bridge.WritableMap;
1212
import com.facebook.react.common.SystemClock;
1313
import com.facebook.react.uimanager.IllegalViewOperationException;
14+
import com.facebook.react.uimanager.common.UIManagerType;
1415

1516
/**
1617
* A UI event that can be dispatched to JS.
@@ -33,6 +34,7 @@ public abstract class Event<T extends Event> {
3334
private static int sUniqueID = 0;
3435

3536
private boolean mInitialized;
37+
private @UIManagerType int mUIManagerType;
3638
private int mSurfaceId;
3739
private int mViewTag;
3840
private long mTimestampMs;
@@ -67,10 +69,23 @@ protected void init(int viewTag) {
6769
protected void init(int surfaceId, int viewTag) {
6870
mSurfaceId = surfaceId;
6971
mViewTag = viewTag;
70-
mInitialized = true;
72+
73+
// We infer UIManagerType. Even though it's not passed in explicitly, we have a
74+
// contract that Fabric events *always* have a SurfaceId passed in, and non-Fabric events
75+
// NEVER have a SurfaceId passed in (the default/placeholder of -1 is passed in instead).
76+
// Why does this matter?
77+
// Events can be sent to Views that are part of the View hierarchy *but not directly managed
78+
// by React Native*. For example, embedded custom hierachies, Litho hierachies, etc.
79+
// In those cases it's important to konw that the Event should be sent to the Fabric or
80+
// non-Fabric UIManager, and we cannot use the ViewTag for inference since it's not controlled
81+
// by RN and is essentially a random number.
82+
// At some point it would be great to pass the SurfaceContext here instead.
83+
mUIManagerType = (surfaceId == -1 ? UIManagerType.DEFAULT : UIManagerType.FABRIC);
7184

7285
// This is a *relative* time. See `getUnixTimestampMs`.
7386
mTimestampMs = SystemClock.uptimeMillis();
87+
88+
mInitialized = true;
7489
}
7590

7691
/** @return the view id for the view that generated this event */
@@ -142,6 +157,10 @@ public void onDispose() {}
142157
onDispose();
143158
}
144159

160+
public final @UIManagerType int getUIManagerType() {
161+
return mUIManagerType;
162+
}
163+
145164
/** @return the name of this event as registered in JS */
146165
public abstract String getEventName();
147166

0 commit comments

Comments
 (0)