From fca3f9f5683cfcd649e4837d6f2c893dcf5dbfe1 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 23 Sep 2024 02:44:57 -0700 Subject: [PATCH 1/2] Remove unused FabricComponents mapping Differential Revision: D63099721 --- .../ReactAndroid/api/ReactAndroid.api | 5 --- .../facebook/react/fabric/FabricComponents.kt | 45 ------------------- .../mountitems/FabricNameComponentMapping.kt | 12 ++--- 3 files changed, 3 insertions(+), 59 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 79ae4e24dd0..c4a2cd600a3 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2672,11 +2672,6 @@ public final class com/facebook/react/fabric/EmptyReactNativeConfig : com/facebo public fun getString (Ljava/lang/String;)Ljava/lang/String; } -public final class com/facebook/react/fabric/FabricComponents { - public static final field INSTANCE Lcom/facebook/react/fabric/FabricComponents; - public static final fun getFabricComponentName (Ljava/lang/String;)Ljava/lang/String; -} - public final class com/facebook/react/fabric/FabricSoLoader { public static final field INSTANCE Lcom/facebook/react/fabric/FabricSoLoader; public static final fun staticInit ()V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.kt deleted file mode 100644 index ee1c5570171..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricComponents.kt +++ /dev/null @@ -1,45 +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 - -/** - * 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++ - */ -public object FabricComponents { - - // TODO T97384889: unify component names between JS - Android - iOS - C++ - private val componentNames: Map = - mapOf( - "View" to "RCTView", - "Image" to "RCTImageView", - "ScrollView" to "RCTScrollView", - "Slider" to "RCTSlider", - "ModalHostView" to "RCTModalHostView", - "Paragraph" to "RCTText", - "Text" to "RCText", - "RawText" to "RCTRawText", - "ActivityIndicatorView" to "AndroidProgressBar", - "ShimmeringView" to "RKShimmeringView", - "TemplateView" to "RCTTemplateView", - "AxialGradientView" to "RCTAxialGradientView", - "Video" to "RCTVideo", - "Map" to "RCTMap", - "WebView" to "RCTWebView", - "Keyframes" to "RCTKeyframes", - "ImpressionTrackingView" to "RCTImpressionTrackingView", - "SafeAreaView" to "RCTSafeAreaView", - ) - - /** @return the name of component in the Fabric environment */ - @JvmStatic - public fun getFabricComponentName(componentName: String): String = - componentNames.get(componentName) ?: 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 index 4775a788f5e..c032448a7a3 100644 --- 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 @@ -7,12 +7,7 @@ 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++ - */ +/** Utility class for Fabric components, this will be removed */ internal object FabricNameComponentMapping { private val componentNames: Map = mapOf( @@ -23,7 +18,7 @@ internal object FabricNameComponentMapping { "Slider" to "RCTSlider", "ModalHostView" to "RCTModalHostView", "Paragraph" to "RCTText", - "Text" to "RCText", + "Text" to "RCTText", "RawText" to "RCTRawText", "ActivityIndicatorView" to "AndroidProgressBar", "ShimmeringView" to "RKShimmeringView", @@ -39,7 +34,6 @@ internal object FabricNameComponentMapping { /** @return the name of component in the Fabric environment */ @JvmStatic fun getFabricComponentName(componentName: String): String { - val component = componentNames[componentName] - return component ?: componentName + return componentNames[componentName] ?: componentName } } From 04fbd773908b2928a8ff17725720b45143ddd2ce Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 23 Sep 2024 05:16:36 -0700 Subject: [PATCH 2/2] Move ShadowNodePair to Differentiator (#46590) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46590 This API should not be part of the ShadowView header, since the class is only used by Differentiator. The ShadowView header should contain public API's that the mounting layer can consume. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D63148522 --- .../renderer/mounting/Differentiator.cpp | 10 +++++ .../react/renderer/mounting/Differentiator.h | 43 +++++++++++++++++- .../react/renderer/mounting/ShadowView.cpp | 8 ---- .../react/renderer/mounting/ShadowView.h | 44 ------------------- .../react/renderer/mounting/stubs/stubs.cpp | 2 +- 5 files changed, 53 insertions(+), 54 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp index 761644ee204..10bcfa53312 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp @@ -39,6 +39,16 @@ enum class NoBreadcrumb {}; namespace facebook::react { +enum class ReparentMode { Flatten, Unflatten }; + +bool ShadowViewNodePair::operator==(const ShadowViewNodePair& rhs) const { + return this->shadowNode == rhs.shadowNode; +} + +bool ShadowViewNodePair::operator!=(const ShadowViewNodePair& rhs) const { + return !(*this == rhs); +} + /* * Extremely simple and naive implementation of a map. * The map is simple but it's optimized for particular constraints that we have diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.h b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.h index f78fb229587..c564b0a94ba 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.h +++ b/packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.h @@ -14,7 +14,48 @@ namespace facebook::react { -enum class ReparentMode { Flatten, Unflatten }; +/* + * Describes pair of a `ShadowView` and a `ShadowNode`. + * This is not exposed to the mounting layer. + */ +struct ShadowViewNodePair final { + using NonOwningList = std::vector; + + ShadowView shadowView; + const ShadowNode* shadowNode; + + /** + * The ShadowNode does not form a stacking context, and the native views + * corresponding to its children may be parented to an ancestor. + */ + bool flattened{false}; + + /** + * Whether this ShadowNode should create a corresponding native view. + */ + bool isConcreteView{true}; + Point contextOrigin{0, 0}; + + size_t mountIndex{0}; + + /** + * This is nullptr unless `inOtherTree` is set to true. + * We rely on this only for marginal cases. TODO: could we + * rely on this more heavily to simplify the diffing algorithm + * overall? + */ + mutable const ShadowViewNodePair* otherTreePair{nullptr}; + + /* + * The stored pointer to `ShadowNode` represents an identity of the pair. + */ + bool operator==(const ShadowViewNodePair& rhs) const; + bool operator!=(const ShadowViewNodePair& rhs) const; + + bool inOtherTree() const { + return this->otherTreePair != nullptr; + } +}; /** * During differ, we need to keep some `ShadowViewNodePair`s in memory. diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowView.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowView.cpp index d1db123889b..d681e942a16 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowView.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowView.cpp @@ -77,12 +77,4 @@ std::vector getDebugProps( #endif -bool ShadowViewNodePair::operator==(const ShadowViewNodePair& rhs) const { - return this->shadowNode == rhs.shadowNode; -} - -bool ShadowViewNodePair::operator!=(const ShadowViewNodePair& rhs) const { - return !(*this == rhs); -} - } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowView.h b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowView.h index 6c776f31bab..36dd55d37a5 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowView.h +++ b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowView.h @@ -57,50 +57,6 @@ std::vector getDebugProps( #endif -/* - * Describes pair of a `ShadowView` and a `ShadowNode`. - * This is not exposed to the mounting layer. - * - */ -struct ShadowViewNodePair final { - using NonOwningList = std::vector; - - ShadowView shadowView; - const ShadowNode* shadowNode; - - /** - * The ShadowNode does not form a stacking context, and the native views - * corresponding to its children may be parented to an ancestor. - */ - bool flattened{false}; - - /** - * Whether this ShadowNode should create a corresponding native view. - */ - bool isConcreteView{true}; - Point contextOrigin{0, 0}; - - size_t mountIndex{0}; - - /** - * This is nullptr unless `inOtherTree` is set to true. - * We rely on this only for marginal cases. TODO: could we - * rely on this more heavily to simplify the diffing algorithm - * overall? - */ - mutable const ShadowViewNodePair* otherTreePair{nullptr}; - - /* - * The stored pointer to `ShadowNode` represents an identity of the pair. - */ - bool operator==(const ShadowViewNodePair& rhs) const; - bool operator!=(const ShadowViewNodePair& rhs) const; - - bool inOtherTree() const { - return this->otherTreePair != nullptr; - } -}; - } // namespace facebook::react namespace std { diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.cpp index b6de0a7ba7a..3e96aa93f89 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/stubs.cpp @@ -43,7 +43,7 @@ static void calculateShadowViewMutationsForNewTree( ShadowViewMutation::List& mutations, ViewNodePairScope& scope, const ShadowView& parentShadowView, - std::vector newChildPairs) { + ShadowViewNodePair::NonOwningList newChildPairs) { // Sorting pairs based on `orderIndex` if needed. reorderInPlaceIfNeeded(newChildPairs);