|
55 | 55 | import com.facebook.react.common.build.ReactBuildConfig;
|
56 | 56 | import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
|
57 | 57 | import com.facebook.react.config.ReactFeatureFlags;
|
58 |
| -import com.facebook.react.fabric.events.EventBeatManager; |
59 | 58 | import com.facebook.react.fabric.events.EventEmitterWrapper;
|
60 | 59 | import com.facebook.react.fabric.events.FabricEventEmitter;
|
61 | 60 | import com.facebook.react.fabric.interfaces.SurfaceHandler;
|
|
65 | 64 | import com.facebook.react.fabric.mounting.SurfaceMountingManager;
|
66 | 65 | import com.facebook.react.fabric.mounting.SurfaceMountingManager.ViewEvent;
|
67 | 66 | import com.facebook.react.fabric.mounting.mountitems.BatchMountItem;
|
| 67 | +import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem; |
68 | 68 | import com.facebook.react.fabric.mounting.mountitems.MountItem;
|
69 | 69 | import com.facebook.react.fabric.mounting.mountitems.MountItemFactory;
|
70 | 70 | import com.facebook.react.modules.core.ReactChoreographer;
|
|
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 class FabricUIManager implements UIManager, LifecycleEventListener {
|
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<>();
|
@@ -213,14 +214,14 @@ public void executeItems(Queue<MountItem> items) {
|
213 | 214 | public FabricUIManager(
|
214 | 215 | @NonNull ReactApplicationContext reactContext,
|
215 | 216 | @NonNull ViewManagerRegistry viewManagerRegistry,
|
216 |
| - @NonNull EventBeatManager eventBeatManager) { |
| 217 | + @NonNull BatchEventDispatchedListener batchEventDispatchedListener) { |
217 | 218 | mDispatchUIFrameCallback = new DispatchUIFrameCallback(reactContext);
|
218 | 219 | mReactApplicationContext = reactContext;
|
219 | 220 | mMountingManager = new MountingManager(viewManagerRegistry, mMountItemExecutor);
|
220 | 221 | mMountItemDispatcher =
|
221 | 222 | new MountItemDispatcher(mMountingManager, new MountItemDispatchListener());
|
222 | 223 | mEventDispatcher = new EventDispatcherImpl(reactContext);
|
223 |
| - mEventBeatManager = eventBeatManager; |
| 224 | + mBatchEventDispatchedListener = batchEventDispatchedListener; |
224 | 225 | mReactApplicationContext.addLifecycleEventListener(this);
|
225 | 226 |
|
226 | 227 | mViewManagerRegistry = viewManagerRegistry;
|
@@ -388,7 +389,7 @@ public void stopSurface(final int surfaceID) {
|
388 | 389 | @Override
|
389 | 390 | public void initialize() {
|
390 | 391 | mEventDispatcher.registerEventEmitter(FABRIC, new FabricEventEmitter(this));
|
391 |
| - mEventDispatcher.addBatchEventDispatchedListener(mEventBeatManager); |
| 392 | + mEventDispatcher.addBatchEventDispatchedListener(mBatchEventDispatchedListener); |
392 | 393 | if (ENABLE_FABRIC_PERF_LOGS) {
|
393 | 394 | mDevToolsReactPerfLogger = new DevToolsReactPerfLogger();
|
394 | 395 | mDevToolsReactPerfLogger.addDevToolsReactPerfLoggerListener(FABRIC_PERF_LOGGER);
|
@@ -427,7 +428,7 @@ public void onCatalystInstanceDestroy() {
|
427 | 428 | // memory immediately.
|
428 | 429 | mDispatchUIFrameCallback.stop();
|
429 | 430 |
|
430 |
| - mEventDispatcher.removeBatchEventDispatchedListener(mEventBeatManager); |
| 431 | + mEventDispatcher.removeBatchEventDispatchedListener(mBatchEventDispatchedListener); |
431 | 432 | mEventDispatcher.unregisterEventEmitter(FABRIC);
|
432 | 433 |
|
433 | 434 | mReactApplicationContext.unregisterComponentCallbacks(mViewManagerRegistry);
|
@@ -1047,9 +1048,17 @@ public void dispatchCommand(
|
1047 | 1048 | final int reactTag,
|
1048 | 1049 | final String commandId,
|
1049 | 1050 | @Nullable final ReadableArray commandArgs) {
|
1050 |
| - mMountItemDispatcher.dispatchCommandMountItem( |
1051 |
| - MountItemFactory.createDispatchCommandMountItem( |
1052 |
| - surfaceId, reactTag, commandId, commandArgs)); |
| 1051 | + if (ReactFeatureFlags.unstable_useFabricInterop) { |
| 1052 | + // For Fabric Interop, we check if the commandId is an integer. If it is, we use the integer |
| 1053 | + // overload of dispatchCommand. Otherwise, we use the string overload. |
| 1054 | + // and the events won't be correctly dispatched. |
| 1055 | + mMountItemDispatcher.dispatchCommandMountItem( |
| 1056 | + createDispatchCommandMountItemForInterop(surfaceId, reactTag, commandId, commandArgs)); |
| 1057 | + } else { |
| 1058 | + mMountItemDispatcher.dispatchCommandMountItem( |
| 1059 | + MountItemFactory.createDispatchCommandMountItem( |
| 1060 | + surfaceId, reactTag, commandId, commandArgs)); |
| 1061 | + } |
1053 | 1062 | }
|
1054 | 1063 |
|
1055 | 1064 | @Override
|
@@ -1246,6 +1255,26 @@ public void didDispatchMountItems() {
|
1246 | 1255 | }
|
1247 | 1256 | }
|
1248 | 1257 |
|
| 1258 | + /** |
| 1259 | + * Util function that takes care of handling commands for Fabric Interop. If the command is a |
| 1260 | + * string that represents a number (say "42"), it will be parsed as an integer and the |
| 1261 | + * corresponding dispatch command mount item will be created. |
| 1262 | + */ |
| 1263 | + /* package */ DispatchCommandMountItem createDispatchCommandMountItemForInterop( |
| 1264 | + final int surfaceId, |
| 1265 | + final int reactTag, |
| 1266 | + final String commandId, |
| 1267 | + @Nullable final ReadableArray commandArgs) { |
| 1268 | + try { |
| 1269 | + int commandIdInteger = Integer.parseInt(commandId); |
| 1270 | + return MountItemFactory.createDispatchCommandMountItem( |
| 1271 | + surfaceId, reactTag, commandIdInteger, commandArgs); |
| 1272 | + } catch (NumberFormatException e) { |
| 1273 | + return MountItemFactory.createDispatchCommandMountItem( |
| 1274 | + surfaceId, reactTag, commandId, commandArgs); |
| 1275 | + } |
| 1276 | + } |
| 1277 | + |
1249 | 1278 | private class DispatchUIFrameCallback extends GuardedFrameCallback {
|
1250 | 1279 |
|
1251 | 1280 | private volatile boolean mIsMountingEnabled = true;
|
|
0 commit comments