From 62260bbf067d1612829e83b34e9bf0f72dbffc5b Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Tue, 7 May 2024 04:06:32 -0700 Subject: [PATCH] Migrate fabric.mounting.mountitems subset to Kotlin Summary: # Changelog: [Internal] - As in the title, note that there are more files there to migrate, will come separately, to make reviewing easier. Differential Revision: D57046953 --- .../ReactAndroid/api/ReactAndroid.api | 14 ++-- .../mounting/mountitems/BatchMountItem.java | 16 ----- .../mounting/mountitems/BatchMountItem.kt | 13 ++++ .../FabricNameComponentMapping.java | 54 -------------- .../mountitems/FabricNameComponentMapping.kt | 46 ++++++++++++ .../fabric/mounting/mountitems/MountItem.java | 25 ------- .../fabric/mounting/mountitems/MountItem.kt | 21 ++++++ .../mounting/mountitems/MountItemFactory.java | 69 ------------------ .../mounting/mountitems/MountItemFactory.kt | 70 +++++++++++++++++++ 9 files changed, 157 insertions(+), 171 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchMountItem.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchMountItem.kt delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.kt delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItem.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItem.kt delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index d4e9ddf113cb41..702754269d514a 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2802,13 +2802,13 @@ public abstract interface class com/facebook/react/fabric/mounting/mountitems/Mo public abstract fun getSurfaceId ()I } -public class com/facebook/react/fabric/mounting/mountitems/MountItemFactory { - public fun ()V - public static fun createDispatchCommandMountItem (IIILcom/facebook/react/bridge/ReadableArray;)Lcom/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem; - public static fun createDispatchCommandMountItem (IILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)Lcom/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem; - public static fun createIntBufferBatchMountItem (I[I[Ljava/lang/Object;I)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; - public static fun createPreAllocateViewMountItem (IILjava/lang/String;Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/uimanager/StateWrapper;Lcom/facebook/react/fabric/events/EventEmitterWrapper;Z)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; - public static fun createSendAccessibilityEventMountItem (III)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; +public final class com/facebook/react/fabric/mounting/mountitems/MountItemFactory { + public static final field INSTANCE Lcom/facebook/react/fabric/mounting/mountitems/MountItemFactory; + public static final fun createDispatchCommandMountItem (IIILcom/facebook/react/bridge/ReadableArray;)Lcom/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem; + public static final fun createDispatchCommandMountItem (IILjava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)Lcom/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem; + public static final fun createIntBufferBatchMountItem (I[I[Ljava/lang/Object;I)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; + public static final fun createPreAllocateViewMountItem (IILjava/lang/String;Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/uimanager/StateWrapper;Lcom/facebook/react/fabric/events/EventEmitterWrapper;Z)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; + public static final fun createSendAccessibilityEventMountItem (III)Lcom/facebook/react/fabric/mounting/mountitems/MountItem; } public abstract interface class com/facebook/react/interfaces/TaskInterface { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchMountItem.java deleted file mode 100644 index 7d6ae64c24765f..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchMountItem.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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; - -public interface BatchMountItem extends MountItem { - - /** - * @return if the BatchMountItem contains any MountItem - */ - boolean isBatchEmpty(); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchMountItem.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchMountItem.kt new file mode 100644 index 00000000000000..1450d791b87460 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchMountItem.kt @@ -0,0 +1,13 @@ +/* + * 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 + +public interface BatchMountItem : MountItem { + /** @return if the BatchMountItem contains any MountItem */ + public fun isBatchEmpty(): Boolean +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java deleted file mode 100644 index 8d675ef99599ec..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 com.facebook.infer.annotation.Nullsafe; -import java.util.HashMap; -import java.util.Map; - -/** - * Utility class for Fabric components, this will be removed - * - *

TODO T97384889: remove this class when the component names are unified between JS - Android - - * iOS - C++ - */ -@Nullsafe(Nullsafe.Mode.LOCAL) -class FabricNameComponentMapping { - - private static @NonNull final Map sComponentNames = new HashMap<>(); - - static { - // TODO T97384889: unify component names between JS - Android - iOS - C++ - sComponentNames.put("View", "RCTView"); - sComponentNames.put("Image", "RCTImageView"); - sComponentNames.put("ScrollView", "RCTScrollView"); - sComponentNames.put("Slider", "RCTSlider"); - sComponentNames.put("ModalHostView", "RCTModalHostView"); - sComponentNames.put("Paragraph", "RCTText"); - sComponentNames.put("Text", "RCText"); - sComponentNames.put("RawText", "RCTRawText"); - sComponentNames.put("ActivityIndicatorView", "AndroidProgressBar"); - sComponentNames.put("ShimmeringView", "RKShimmeringView"); - sComponentNames.put("TemplateView", "RCTTemplateView"); - sComponentNames.put("AxialGradientView", "RCTAxialGradientView"); - sComponentNames.put("Video", "RCTVideo"); - sComponentNames.put("Map", "RCTMap"); - sComponentNames.put("WebView", "RCTWebView"); - sComponentNames.put("Keyframes", "RCTKeyframes"); - sComponentNames.put("ImpressionTrackingView", "RCTImpressionTrackingView"); - } - - /** - * @return the name of component in the Fabric environment - */ - static String getFabricComponentName(String componentName) { - String component = sComponentNames.get(componentName); - return component != null ? component : componentName; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.kt new file mode 100644 index 00000000000000..3dbdcb699327d9 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.kt @@ -0,0 +1,46 @@ +/* + * 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 + +/** + * Utility class for Fabric components, this will be removed + * + * TODO T97384889: remove this class when the component names are unified between JS - Android - + * iOS - C++ + */ +internal object FabricNameComponentMapping { + private val componentNames: MutableMap = HashMap() + + init { + // TODO T97384889: unify component names between JS - Android - iOS - C++ + componentNames["View"] = "RCTView" + componentNames["Image"] = "RCTImageView" + componentNames["ScrollView"] = "RCTScrollView" + componentNames["Slider"] = "RCTSlider" + componentNames["ModalHostView"] = "RCTModalHostView" + componentNames["Paragraph"] = "RCTText" + componentNames["Text"] = "RCText" + componentNames["RawText"] = "RCTRawText" + componentNames["ActivityIndicatorView"] = "AndroidProgressBar" + componentNames["ShimmeringView"] = "RKShimmeringView" + componentNames["TemplateView"] = "RCTTemplateView" + componentNames["AxialGradientView"] = "RCTAxialGradientView" + componentNames["Video"] = "RCTVideo" + componentNames["Map"] = "RCTMap" + componentNames["WebView"] = "RCTWebView" + componentNames["Keyframes"] = "RCTKeyframes" + componentNames["ImpressionTrackingView"] = "RCTImpressionTrackingView" + } + + /** @return the name of component in the Fabric environment */ + @JvmStatic + fun getFabricComponentName(componentName: String): String { + val component = componentNames[componentName] + return component ?: componentName + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItem.java deleted file mode 100644 index d966f5445e5cd3..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItem.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.AnyThread; -import androidx.annotation.NonNull; -import androidx.annotation.UiThread; -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.fabric.mounting.MountingManager; - -@DoNotStrip -public interface MountItem { - - /** Execute this {@link MountItem} into the operation queue received by parameter. */ - @UiThread - void execute(@NonNull MountingManager mountingManager); - - @AnyThread - int getSurfaceId(); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItem.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItem.kt new file mode 100644 index 00000000000000..37181775b21b79 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItem.kt @@ -0,0 +1,21 @@ +/* + * 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.AnyThread +import androidx.annotation.UiThread +import com.facebook.proguard.annotations.DoNotStripAny +import com.facebook.react.fabric.mounting.MountingManager + +@DoNotStripAny +public interface MountItem { + /** Execute this [MountItem] into the operation queue received by parameter. */ + @UiThread public fun execute(mountingManager: MountingManager) + + @AnyThread public fun getSurfaceId(): Int +} 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 deleted file mode 100644 index 74871ade50136e..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.infer.annotation.Nullsafe; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.fabric.events.EventEmitterWrapper; -import com.facebook.react.uimanager.StateWrapper; - -/** Factory class that expose creation of {@link MountItem} */ -@Nullsafe(Nullsafe.Mode.LOCAL) -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); - } - - /** - * @return a {@link MountItem} that will control the execution of an AccessibilityEvent - */ - public static MountItem createSendAccessibilityEventMountItem( - int surfaceId, int reactTag, int eventType) { - return new SendAccessibilityEventMountItem(surfaceId, reactTag, eventType); - } - - /** - * @return a {@link MountItem} that will be used to preallocate views - */ - public static MountItem createPreAllocateViewMountItem( - int surfaceId, - int reactTag, - @NonNull String component, - @Nullable ReadableMap props, - @Nullable StateWrapper stateWrapper, - @Nullable EventEmitterWrapper eventEmitterWrapper, - boolean isLayoutable) { - return new PreAllocateViewMountItem( - surfaceId, reactTag, component, props, stateWrapper, eventEmitterWrapper, isLayoutable); - } - - /** - * @return a {@link MountItem} that will be read and execute a collection of MountItems serialized - * in the int[] and Object[] received by parameter - */ - public static MountItem createIntBufferBatchMountItem( - int surfaceId, int[] intBuf, Object[] objBuf, int commitNumber) { - return new IntBufferBatchMountItem(surfaceId, intBuf, objBuf, commitNumber); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt new file mode 100644 index 00000000000000..15ab152d1ee6b4 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/MountItemFactory.kt @@ -0,0 +1,70 @@ +/* + * 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 com.facebook.react.bridge.ReadableArray +import com.facebook.react.bridge.ReadableMap +import com.facebook.react.fabric.events.EventEmitterWrapper +import com.facebook.react.uimanager.StateWrapper + +/** Factory class that expose creation of [MountItem] */ +public object MountItemFactory { + /** @return a [DispatchCommandMountItem] for commands identified by an int */ + @JvmStatic + public fun createDispatchCommandMountItem( + surfaceId: Int, + reactTag: Int, + commandId: Int, + commandArgs: ReadableArray? + ): DispatchCommandMountItem = + DispatchIntCommandMountItem(surfaceId, reactTag, commandId, commandArgs) + + /** @return a [DispatchCommandMountItem] for commands identified by a String */ + @JvmStatic + public fun createDispatchCommandMountItem( + surfaceId: Int, + reactTag: Int, + commandId: String, + commandArgs: ReadableArray? + ): DispatchCommandMountItem = + DispatchStringCommandMountItem(surfaceId, reactTag, commandId, commandArgs) + + /** @return a [MountItem] that will control the execution of an AccessibilityEvent */ + @JvmStatic + public fun createSendAccessibilityEventMountItem( + surfaceId: Int, + reactTag: Int, + eventType: Int + ): MountItem = SendAccessibilityEventMountItem(surfaceId, reactTag, eventType) + + /** @return a [MountItem] that will be used to preallocate views */ + @JvmStatic + public fun createPreAllocateViewMountItem( + surfaceId: Int, + reactTag: Int, + component: String, + props: ReadableMap?, + stateWrapper: StateWrapper?, + eventEmitterWrapper: EventEmitterWrapper?, + isLayoutable: Boolean + ): MountItem = + PreAllocateViewMountItem( + surfaceId, reactTag, component, props, stateWrapper, eventEmitterWrapper, isLayoutable) + + /** + * @return a [MountItem] that will be read and execute a collection of MountItems serialized in + * the int[] and Object[] received by parameter + */ + @JvmStatic + public fun createIntBufferBatchMountItem( + surfaceId: Int, + intBuf: IntArray?, + objBuf: Array?, + commitNumber: Int + ): MountItem = IntBufferBatchMountItem(surfaceId, intBuf, objBuf, commitNumber) +}