From b5696e6172b51426f30d55e16005452806c59dc0 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 28 Oct 2024 18:49:19 -0700 Subject: [PATCH] Migrate PreAllocateViewMountItem to Kotlin (#47258) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47258 Migrate PreAllocateViewMountItem to Kotlin changeLog: [internal] internal Reviewed By: shwanton Differential Revision: D65070220 fbshipit-source-id: 3785f36747ea54304e45234daf377d20381f3c6c --- .../mountitems/PreAllocateViewMountItem.java | 90 ------------------- .../mountitems/PreAllocateViewMountItem.kt | 63 +++++++++++++ 2 files changed, 63 insertions(+), 90 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java deleted file mode 100644 index 2dca9060a0c..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.java +++ /dev/null @@ -1,90 +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 static com.facebook.react.fabric.FabricUIManager.IS_DEVELOPMENT_ENVIRONMENT; -import static com.facebook.react.fabric.FabricUIManager.TAG; -import static com.facebook.react.fabric.mounting.mountitems.FabricNameComponentMapping.getFabricComponentName; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import com.facebook.common.logging.FLog; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.fabric.mounting.MountingManager; -import com.facebook.react.fabric.mounting.SurfaceMountingManager; -import com.facebook.react.uimanager.StateWrapper; - -/** {@link MountItem} that is used to pre-allocate views for JS components. */ -@Nullsafe(Nullsafe.Mode.LOCAL) -final class PreAllocateViewMountItem implements MountItem { - - private final @NonNull String mComponent; - private final int mSurfaceId; - private final int mReactTag; - private final @Nullable ReadableMap mProps; - private final @Nullable StateWrapper mStateWrapper; - private final boolean mIsLayoutable; - - PreAllocateViewMountItem( - int surfaceId, - int reactTag, - @NonNull String component, - @Nullable ReadableMap props, - @Nullable StateWrapper stateWrapper, - boolean isLayoutable) { - mComponent = getFabricComponentName(component); - mSurfaceId = surfaceId; - mProps = props; - mStateWrapper = stateWrapper; - mReactTag = reactTag; - mIsLayoutable = isLayoutable; - } - - @Override - public int getSurfaceId() { - return mSurfaceId; - } - - @Override - public void execute(@NonNull MountingManager mountingManager) { - SurfaceMountingManager surfaceMountingManager = mountingManager.getSurfaceManager(mSurfaceId); - if (surfaceMountingManager == null) { - FLog.e( - TAG, - "Skipping View PreAllocation; no SurfaceMountingManager found for [" + mSurfaceId + "]"); - return; - } - surfaceMountingManager.preallocateView( - mComponent, mReactTag, mProps, mStateWrapper, mIsLayoutable); - } - - @Override - @NonNull - public String toString() { - StringBuilder result = - new StringBuilder("PreAllocateViewMountItem [") - .append(mReactTag) - .append("] - component: ") - .append(mComponent) - .append(" surfaceId: ") - .append(mSurfaceId) - .append(" isLayoutable: ") - .append(mIsLayoutable); - - if (IS_DEVELOPMENT_ENVIRONMENT) { - result - .append(" props: ") - .append(mProps != null ? mProps.toString() : "") - .append(" state: ") - .append(mStateWrapper != null ? mStateWrapper.toString() : ""); - } - - return result.toString(); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.kt new file mode 100644 index 00000000000..27a03062ce6 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/PreAllocateViewMountItem.kt @@ -0,0 +1,63 @@ +/* + * 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.common.logging.FLog +import com.facebook.react.bridge.ReadableMap +import com.facebook.react.fabric.FabricUIManager +import com.facebook.react.fabric.mounting.MountingManager +import com.facebook.react.fabric.mounting.mountitems.FabricNameComponentMapping.getFabricComponentName +import com.facebook.react.uimanager.StateWrapper + +/** [MountItem] that is used to pre-allocate views for JS components. */ +internal class PreAllocateViewMountItem( + private val surfaceId: Int, + private val reactTag: Int, + component: String, + private val props: ReadableMap?, + private val stateWrapper: StateWrapper?, + private val isLayoutable: Boolean +) : MountItem { + private val fabricComponentName = getFabricComponentName(component) + + override fun getSurfaceId(): Int = surfaceId + + override fun execute(mountingManager: MountingManager) { + val surfaceMountingManager = mountingManager.getSurfaceManager(surfaceId) + if (surfaceMountingManager == null) { + FLog.e( + FabricUIManager.TAG, + "Skipping View PreAllocation; no SurfaceMountingManager found for [$surfaceId]") + return + } + surfaceMountingManager.preallocateView( + fabricComponentName, reactTag, props, stateWrapper, isLayoutable) + } + + override fun toString(): String { + val result = + StringBuilder("PreAllocateViewMountItem [") + .append(reactTag) + .append("] - component: ") + .append(fabricComponentName) + .append(" surfaceId: ") + .append(surfaceId) + .append(" isLayoutable: ") + .append(isLayoutable) + + if (FabricUIManager.IS_DEVELOPMENT_ENVIRONMENT) { + result + .append(" props: ") + .append(props?.toString() ?: "") + .append(" state: ") + .append(stateWrapper?.toString() ?: "") + } + + return result.toString() + } +}