diff --git a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index 0ffff5edabe..e9ad457d3e9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -79,6 +79,9 @@ public class ReactFeatureFlags { /** Enables or disables MapBuffer Serialization */ public static boolean mapBufferSerializationEnabled = false; + /* Enables or disables MapBuffer use in Props infrastructure. */ + public static boolean useMapBufferProps = false; + /** Enables or disables calculation of Transformed Frames */ public static boolean calculateTransformedFramesEnabled = false; diff --git a/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp b/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp index bc584166eb7..4d11993a38e 100644 --- a/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp +++ b/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp @@ -51,9 +51,9 @@ FabricMountingManager::FabricMountingManager( "react_fabric:disable_revision_check_for_preallocation")), useOverflowInset_(getFeatureFlagValue("useOverflowInset")), shouldRememberAllocatedViews_( - getFeatureFlagValue("shouldRememberAllocatedViews")), - useMapBufferForViewProps_(config->getBool( - "react_native_new_architecture:use_mapbuffer_for_viewprops")) {} + getFeatureFlagValue("shouldRememberAllocatedViews")) { + Props::enableMapBuffer = getFeatureFlagValue("useMapBufferProps"); +} void FabricMountingManager::onSurfaceStart(SurfaceId surfaceId) { std::lock_guard lock(allocatedViewsMutex_); @@ -258,8 +258,9 @@ static inline float scale(Float value, Float pointScaleFactor) { local_ref FabricMountingManager::getProps( ShadowView const &oldShadowView, ShadowView const &newShadowView) { - if (useMapBufferForViewProps_ && - newShadowView.traits.check(ShadowNodeTraits::Trait::View)) { + if (Props::enableMapBuffer && + newShadowView.traits.check( + ShadowNodeTraits::Trait::AndroidMapBufferPropsSupported)) { react_native_assert( newShadowView.props->rawProps.empty() && "Raw props must be empty when views are using mapbuffer"); diff --git a/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h b/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h index b1162d290dc..1c04213873b 100644 --- a/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h +++ b/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h @@ -77,7 +77,6 @@ class FabricMountingManager final { bool const disableRevisionCheckForPreallocation_{false}; bool const useOverflowInset_{false}; bool const shouldRememberAllocatedViews_{false}; - bool const useMapBufferForViewProps_{false}; jni::local_ref getProps( ShadowView const &oldShadowView, diff --git a/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp b/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp index 61661c1af41..b3cba2a0f2c 100644 --- a/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp +++ b/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp @@ -14,36 +14,11 @@ namespace react { char const ViewComponentName[] = "View"; -static inline bool keepRawValuesInViewProps(PropsParserContext const &context) { - static bool shouldUseRawProps = true; - -#ifdef ANDROID - static bool initialized = false; - - if (!initialized) { - auto config = - context.contextContainer.find>( - "ReactNativeConfig"); - if (config.has_value()) { - initialized = true; - shouldUseRawProps = !config.value()->getBool( - "react_native_new_architecture:use_mapbuffer_for_viewprops"); - } - } -#endif - - return shouldUseRawProps; -} - ViewShadowNodeProps::ViewShadowNodeProps( PropsParserContext const &context, ViewShadowNodeProps const &sourceProps, RawProps const &rawProps) - : ViewProps( - context, - sourceProps, - rawProps, - keepRawValuesInViewProps(context)){}; + : ViewProps(context, sourceProps, rawProps, !Props::enableMapBuffer){}; ViewShadowNode::ViewShadowNode( ShadowNodeFragment const &fragment, @@ -106,6 +81,10 @@ void ViewShadowNode::initialize() noexcept { } else { traits_.unset(ShadowNodeTraits::Trait::FormsStackingContext); } + +#ifdef ANDROID + traits_.set(ShadowNodeTraits::Trait::AndroidMapBufferPropsSupported); +#endif } } // namespace react diff --git a/ReactCommon/react/renderer/core/Props.cpp b/ReactCommon/react/renderer/core/Props.cpp index 0e2af101fd8..cdca7cc8fbe 100644 --- a/ReactCommon/react/renderer/core/Props.cpp +++ b/ReactCommon/react/renderer/core/Props.cpp @@ -14,6 +14,7 @@ namespace facebook { namespace react { bool Props::enablePropIteratorSetter = false; +bool Props::enableMapBuffer = false; Props::Props( const PropsParserContext &context, diff --git a/ReactCommon/react/renderer/core/Props.h b/ReactCommon/react/renderer/core/Props.h index 9c073569506..a6f4113caad 100644 --- a/ReactCommon/react/renderer/core/Props.h +++ b/ReactCommon/react/renderer/core/Props.h @@ -36,6 +36,12 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible { static bool enablePropIteratorSetter; + // This is used as a feature flag for *all* PropsX structs. + // For MapBuffer to be used for a particular component instance, + // its ShadowNode traits must set the MapBuffer trait; and this + // must be set to "true" globally. + static bool enableMapBuffer; + /** * Set a prop value via iteration (see enableIterator above). * If setProp is defined for a particular props struct, it /must/ diff --git a/ReactCommon/react/renderer/core/ShadowNodeTraits.h b/ReactCommon/react/renderer/core/ShadowNodeTraits.h index d222f74d896..d4f78368cb9 100644 --- a/ReactCommon/react/renderer/core/ShadowNodeTraits.h +++ b/ReactCommon/react/renderer/core/ShadowNodeTraits.h @@ -59,42 +59,47 @@ class ShadowNodeTraits { // Yoga styles in the constructor (or later) *after* the `ShadowNode` // is cloned must set this trait. // Any Yoga node (not only Leaf ones) can have this trait. - DirtyYogaNode = 1 << 9, + DirtyYogaNode = 1 << 7, // Inherits `YogaLayoutableShadowNode` and enforces that the `YGNode` is a // leaf. - LeafYogaNode = 1 << 10, + LeafYogaNode = 1 << 8, // Inherits `YogaLayoutableShadowNode` and has a custom measure function. // Only Leaf nodes can have this trait. - MeasurableYogaNode = 1 << 11, + MeasurableYogaNode = 1 << 9, // Indicates that the `ShadowNode` must form a stacking context. // A Stacking Context forms a level of a `ShadowView` hierarchy (in contrast // with a level of a `ShadowNode` hierarchy). // See W3C standard for more details: https://www.w3.org/TR/CSS2/zindex.html - FormsStackingContext = 1 << 13, + FormsStackingContext = 1 << 10, // Indicates that the node must form a `ShadowView`. - FormsView = 1 << 14, + FormsView = 1 << 11, // Internal to `ShadowNode`; do not use it outside. // Indicates that `children` list is shared between nodes and need // to be cloned before the first mutation. - ChildrenAreShared = 1 << 15, + ChildrenAreShared = 1 << 12, // Inherits 'RawTextShadowNode' - RawText = 1 << 16, + RawText = 1 << 13, // Inherits 'TextShadowNode' - Text = 1 << 17, + Text = 1 << 14, + + // Temporary (?) to indicate MapBuffer support on Android + AndroidMapBufferPropsSupported = 1 << 15, // Reserved - ReservedTrait1 = 1 << 18, - ReservedTrait2 = 1 << 19, - ReservedTrait3 = 1 << 20, - ReservedTrait4 = 1 << 21, - ReservedTrait5 = 1 << 22, + ReservedTrait0 = 1 << 16, + ReservedTrait1 = 1 << 17, + ReservedTrait2 = 1 << 18, + ReservedTrait3 = 1 << 19, + ReservedTrait4 = 1 << 20, + ReservedTrait5 = 1 << 21, + ReservedTrait6 = 1 << 22, // Unserved - alias these for local usage UnreservedTrait1 = 1 << 23