diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index e080e6a2b0d..f35195b5b5b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -59,10 +59,9 @@ import com.facebook.react.fabric.mounting.MountItemDispatcher; import com.facebook.react.fabric.mounting.MountingManager; import com.facebook.react.fabric.mounting.SurfaceMountingManager; import com.facebook.react.fabric.mounting.SurfaceMountingManager.ViewEvent; -import com.facebook.react.fabric.mounting.mountitems.DispatchIntCommandMountItem; -import com.facebook.react.fabric.mounting.mountitems.DispatchStringCommandMountItem; import com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem; import com.facebook.react.fabric.mounting.mountitems.MountItem; +import com.facebook.react.fabric.mounting.mountitems.MountItemFactory; import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem; import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent; import com.facebook.react.modules.core.ReactChoreographer; @@ -1021,7 +1020,8 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { final int commandId, @Nullable final ReadableArray commandArgs) { mMountItemDispatcher.dispatchCommandMountItem( - new DispatchIntCommandMountItem(surfaceId, reactTag, commandId, commandArgs)); + MountItemFactory.createDispatchCommandMountItem( + surfaceId, reactTag, commandId, commandArgs)); } @AnyThread @@ -1032,7 +1032,8 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { final String commandId, @Nullable final ReadableArray commandArgs) { mMountItemDispatcher.dispatchCommandMountItem( - new DispatchStringCommandMountItem(surfaceId, reactTag, commandId, commandArgs)); + MountItemFactory.createDispatchCommandMountItem( + surfaceId, reactTag, commandId, commandArgs)); } @Override diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java index b8f81a306ca..c9cc25db8cd 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchIntCommandMountItem.java @@ -12,7 +12,7 @@ import androidx.annotation.Nullable; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.fabric.mounting.MountingManager; -public class DispatchIntCommandMountItem extends DispatchCommandMountItem { +class DispatchIntCommandMountItem extends DispatchCommandMountItem { private final int mSurfaceId; private final int mReactTag; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java index e99671aa355..b72c9ab24b1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchStringCommandMountItem.java @@ -12,7 +12,7 @@ import androidx.annotation.Nullable; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.fabric.mounting.MountingManager; -public class DispatchStringCommandMountItem extends DispatchCommandMountItem { +class DispatchStringCommandMountItem extends DispatchCommandMountItem { private final int mSurfaceId; private final int mReactTag; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java new file mode 100644 index 00000000000..cf2e8b96c27 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.fabric.mounting.mountitems; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableArray; + +/** Factory class that expose creation of {@link MountItem} */ +public class MountItemFactory { + + /** @return a {@link DispatchCommandMountItem} for commands identified by an int */ + public static DispatchCommandMountItem createDispatchCommandMountItem( + int surfaceId, int reactTag, int commandId, @Nullable ReadableArray commandArgs) { + return new DispatchIntCommandMountItem(surfaceId, reactTag, commandId, commandArgs); + } + + /** @return a {@link DispatchCommandMountItem} for commands identified by a String */ + public static DispatchCommandMountItem createDispatchCommandMountItem( + int surfaceId, int reactTag, @NonNull String commandId, @Nullable ReadableArray commandArgs) { + return new DispatchStringCommandMountItem(surfaceId, reactTag, commandId, commandArgs); + } +}