|
53 | 53 | import com.facebook.react.common.build.ReactBuildConfig;
|
54 | 54 | import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
|
55 | 55 | import com.facebook.react.config.ReactFeatureFlags;
|
56 |
| -import com.facebook.react.fabric.events.EventBeatManager; |
57 | 56 | import com.facebook.react.fabric.events.EventEmitterWrapper;
|
58 | 57 | import com.facebook.react.fabric.events.FabricEventEmitter;
|
59 | 58 | import com.facebook.react.fabric.interop.InteropEventEmitter;
|
60 | 59 | import com.facebook.react.fabric.mounting.MountItemDispatcher;
|
61 | 60 | import com.facebook.react.fabric.mounting.MountingManager;
|
62 | 61 | import com.facebook.react.fabric.mounting.SurfaceMountingManager;
|
63 | 62 | import com.facebook.react.fabric.mounting.SurfaceMountingManager.ViewEvent;
|
| 63 | +import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem; |
64 | 64 | import com.facebook.react.fabric.mounting.mountitems.DispatchIntCommandMountItem;
|
65 | 65 | import com.facebook.react.fabric.mounting.mountitems.DispatchStringCommandMountItem;
|
66 | 66 | import com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem;
|
|
79 | 79 | import com.facebook.react.uimanager.UIManagerHelper;
|
80 | 80 | import com.facebook.react.uimanager.ViewManagerPropertyUpdater;
|
81 | 81 | import com.facebook.react.uimanager.ViewManagerRegistry;
|
| 82 | +import com.facebook.react.uimanager.events.BatchEventDispatchedListener; |
82 | 83 | import com.facebook.react.uimanager.events.EventCategoryDef;
|
83 | 84 | import com.facebook.react.uimanager.events.EventDispatcher;
|
84 | 85 | import com.facebook.react.uimanager.events.EventDispatcherImpl;
|
@@ -168,7 +169,7 @@ public void onFabricCommitEnd(DevToolsReactPerfLogger.FabricCommitPoint commitPo
|
168 | 169 | @NonNull private final MountItemDispatcher mMountItemDispatcher;
|
169 | 170 | @NonNull private final ViewManagerRegistry mViewManagerRegistry;
|
170 | 171 |
|
171 |
| - @NonNull private final EventBeatManager mEventBeatManager; |
| 172 | + @NonNull private final BatchEventDispatchedListener mBatchEventDispatchedListener; |
172 | 173 |
|
173 | 174 | @NonNull
|
174 | 175 | private final CopyOnWriteArrayList<UIManagerListener> mListeners = new CopyOnWriteArrayList<>();
|
@@ -208,16 +209,16 @@ public void executeItems(Queue<MountItem> items) {
|
208 | 209 | };
|
209 | 210 |
|
210 | 211 | public FabricUIManager(
|
211 |
| - ReactApplicationContext reactContext, |
212 |
| - ViewManagerRegistry viewManagerRegistry, |
213 |
| - EventBeatManager eventBeatManager) { |
| 212 | + @NonNull ReactApplicationContext reactContext, |
| 213 | + @NonNull ViewManagerRegistry viewManagerRegistry, |
| 214 | + @NonNull BatchEventDispatchedListener batchEventDispatchedListener) { |
214 | 215 | mDispatchUIFrameCallback = new DispatchUIFrameCallback(reactContext);
|
215 | 216 | mReactApplicationContext = reactContext;
|
216 | 217 | mMountingManager = new MountingManager(viewManagerRegistry, mMountItemExecutor);
|
217 | 218 | mMountItemDispatcher =
|
218 | 219 | new MountItemDispatcher(mMountingManager, new MountItemDispatchListener());
|
219 | 220 | mEventDispatcher = new EventDispatcherImpl(reactContext);
|
220 |
| - mEventBeatManager = eventBeatManager; |
| 221 | + mBatchEventDispatchedListener = batchEventDispatchedListener; |
221 | 222 | mReactApplicationContext.addLifecycleEventListener(this);
|
222 | 223 |
|
223 | 224 | mViewManagerRegistry = viewManagerRegistry;
|
@@ -385,7 +386,7 @@ public void stopSurface(final int surfaceID) {
|
385 | 386 | @Override
|
386 | 387 | public void initialize() {
|
387 | 388 | mEventDispatcher.registerEventEmitter(FABRIC, new FabricEventEmitter(this));
|
388 |
| - mEventDispatcher.addBatchEventDispatchedListener(mEventBeatManager); |
| 389 | + mEventDispatcher.addBatchEventDispatchedListener(mBatchEventDispatchedListener); |
389 | 390 | if (ENABLE_FABRIC_PERF_LOGS) {
|
390 | 391 | mDevToolsReactPerfLogger = new DevToolsReactPerfLogger();
|
391 | 392 | mDevToolsReactPerfLogger.addDevToolsReactPerfLoggerListener(FABRIC_PERF_LOGGER);
|
@@ -424,7 +425,7 @@ public void onCatalystInstanceDestroy() {
|
424 | 425 | // memory immediately.
|
425 | 426 | mDispatchUIFrameCallback.stop();
|
426 | 427 |
|
427 |
| - mEventDispatcher.removeBatchEventDispatchedListener(mEventBeatManager); |
| 428 | + mEventDispatcher.removeBatchEventDispatchedListener(mBatchEventDispatchedListener); |
428 | 429 | mEventDispatcher.unregisterEventEmitter(FABRIC);
|
429 | 430 |
|
430 | 431 | mReactApplicationContext.unregisterComponentCallbacks(mViewManagerRegistry);
|
@@ -1039,8 +1040,16 @@ public void dispatchCommand(
|
1039 | 1040 | final int reactTag,
|
1040 | 1041 | final String commandId,
|
1041 | 1042 | @Nullable final ReadableArray commandArgs) {
|
1042 |
| - mMountItemDispatcher.dispatchCommandMountItem( |
1043 |
| - new DispatchStringCommandMountItem(surfaceId, reactTag, commandId, commandArgs)); |
| 1043 | + if (ReactFeatureFlags.unstable_useFabricInterop) { |
| 1044 | + // For Fabric Interop, we check if the commandId is an integer. If it is, we use the integer |
| 1045 | + // overload of dispatchCommand. Otherwise, we use the string overload. |
| 1046 | + // and the events won't be correctly dispatched. |
| 1047 | + mMountItemDispatcher.dispatchCommandMountItem( |
| 1048 | + createDispatchCommandMountItemForInterop(surfaceId, reactTag, commandId, commandArgs)); |
| 1049 | + } else { |
| 1050 | + mMountItemDispatcher.dispatchCommandMountItem( |
| 1051 | + new DispatchStringCommandMountItem(surfaceId, reactTag, commandId, commandArgs)); |
| 1052 | + } |
1044 | 1053 | }
|
1045 | 1054 |
|
1046 | 1055 | @Override
|
@@ -1200,6 +1209,24 @@ public void didDispatchMountItems() {
|
1200 | 1209 | }
|
1201 | 1210 | }
|
1202 | 1211 |
|
| 1212 | + /** |
| 1213 | + * Util function that takes care of handling commands for Fabric Interop. If the command is a |
| 1214 | + * string that represents a number (say "42"), it will be parsed as an integer and the |
| 1215 | + * corresponding dispatch command mount item will be created. |
| 1216 | + */ |
| 1217 | + /* package */ DispatchCommandMountItem createDispatchCommandMountItemForInterop( |
| 1218 | + final int surfaceId, |
| 1219 | + final int reactTag, |
| 1220 | + final String commandId, |
| 1221 | + @Nullable final ReadableArray commandArgs) { |
| 1222 | + try { |
| 1223 | + int commandIdInteger = Integer.parseInt(commandId); |
| 1224 | + return new DispatchIntCommandMountItem(surfaceId, reactTag, commandIdInteger, commandArgs); |
| 1225 | + } catch (NumberFormatException e) { |
| 1226 | + return new DispatchStringCommandMountItem(surfaceId, reactTag, commandId, commandArgs); |
| 1227 | + } |
| 1228 | + } |
| 1229 | + |
1203 | 1230 | private class DispatchUIFrameCallback extends GuardedFrameCallback {
|
1204 | 1231 |
|
1205 | 1232 | private volatile boolean mIsMountingEnabled = true;
|
|
0 commit comments