From 3232021b46b7620e21423ec722f992030a8abd25 Mon Sep 17 00:00:00 2001 From: James Ide Date: Fri, 4 Dec 2026 01:47:58 -0800 Subject: [PATCH] Enable iterator-based Fabric props parsing by default Enable `enableCppPropsIteratorSetter` by default. For components that support the iterator setter, Fabric copies the source props and calls `setProp` only for the supplied keys. Other components continue to use the classic constructor. Make the two paths agree for the core components that support the iterator setter. The View setter reads the public `shouldRasterizeIOS` key instead of `shouldRasterize`, which JavaScript never sends. The TextInput setter reads `minimumFontScale`, `lineBreak`, `wordBreak` and `experimental_textWidthMode`, as the classic constructor does; AndroidTextInput sends `minimumFontScale`. When JavaScript removes `width`, `height` or the ScrollView `horizontal` prop, the classic constructor now restores the declared default that the setter restores: `auto` instead of an undefined length, and `false` instead of `true`. Parity tests build View, Paragraph, Text, Image, ScrollView and the cross-platform TextInput props from the same values with the classic constructor and with the setter. Each test gives a non-default value to every key that the type's own setter handles (for View, a selection across its categories), checks that each value takes effect, and checks that the two paths agree after setting the values and after removing them. The tests live with their components and share a helper in `react/test_utils`. Reverting any of the fixes above, or removing the setter case of a tested key, fails the matching check. The Android setters of View, ScrollView, Paragraph and AndroidTextInput do not build on this host; a comparison of the keys that their constructors and setters read finds no difference. All ReactCommon C++ tests pass, built as the Fantom tester build does with this tree's generated code. A full `yarn fantom` run passes; two component-stack cases in `LogBox-itest.js` fail intermittently on this base with either flag value. The repository's C++ format check, `yarn flow-check` and `yarn lint` pass, and the C++ API snapshots validate. An optimized C++ benchmark on Apple M6 clones `ViewProps` with six supplied props through `ConcreteComponentDescriptor::cloneProps`, running one binary with each flag value. Median retired instructions fall from 38,432 to 6,893 per clone. Signed-off-by: James Ide --- .../ReactNativeFeatureFlagsDefaults.kt | 4 +- .../ReactNativeFeatureFlagsDefaults.h | 4 +- .../ImagePropsIteratorSetterParityTest.cpp | 50 ++++++++ .../scrollview/BaseScrollViewProps.cpp | 2 +- ...crollViewPropsIteratorSetterParityTest.cpp | 87 +++++++++++++ .../TextPropsIteratorSetterParityTest.cpp | 106 ++++++++++++++++ .../textinput/BaseTextInputProps.cpp | 16 +++ ...TextInputPropsIteratorSetterParityTest.cpp | 73 +++++++++++ .../components/view/BaseViewProps.cpp | 2 +- .../components/view/propsConversions.h | 14 ++- .../ViewPropsIteratorSetterParityTest.cpp | 70 +++++++++++ .../test_utils/PropsIteratorSetterParity.h | 115 ++++++++++++++++++ .../ReactNativeFeatureFlags.config.js | 2 +- .../featureflags/ReactNativeFeatureFlags.js | 4 +- 14 files changed, 538 insertions(+), 11 deletions(-) create mode 100644 packages/react-native/ReactCommon/react/renderer/components/image/tests/ImagePropsIteratorSetterParityTest.cpp create mode 100644 packages/react-native/ReactCommon/react/renderer/components/scrollview/tests/ScrollViewPropsIteratorSetterParityTest.cpp create mode 100644 packages/react-native/ReactCommon/react/renderer/components/text/tests/TextPropsIteratorSetterParityTest.cpp create mode 100644 packages/react-native/ReactCommon/react/renderer/components/textinput/tests/BaseTextInputPropsIteratorSetterParityTest.cpp create mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewPropsIteratorSetterParityTest.cpp create mode 100644 packages/react-native/ReactCommon/react/test_utils/PropsIteratorSetterParity.h diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt index 0a9a0d6c6c38..8f485ba90cea 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<1f047ac222ceead081665ebb2d3f60e7>> */ /** @@ -55,7 +55,7 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi override fun enableBridgelessArchitecture(): Boolean = true - override fun enableCppPropsIteratorSetter(): Boolean = false + override fun enableCppPropsIteratorSetter(): Boolean = true override fun enableCustomFocusSearchOnClippedElementsAndroid(): Boolean = true diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h index 51adc60a0256..f00a06da4586 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<148e6fe8cf82e6d05a04cf8c12131c40>> */ /** @@ -94,7 +94,7 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider { } bool enableCppPropsIteratorSetter() override { - return false; + return true; } bool enableCustomFocusSearchOnClippedElementsAndroid() override { diff --git a/packages/react-native/ReactCommon/react/renderer/components/image/tests/ImagePropsIteratorSetterParityTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/image/tests/ImagePropsIteratorSetterParityTest.cpp new file mode 100644 index 000000000000..19284e64f51e --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/image/tests/ImagePropsIteratorSetterParityTest.cpp @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#include + +#include +#include + +namespace facebook::react { + +using folly::dynamic; + +TEST(ImagePropsIteratorSetterParityTest, setsAndClearsImageProps) { + const auto parity = buildIteratorSetterParity(dynamic::object( + "source", + dynamic::array( + dynamic::object("uri", "https://example.com/a.png")("width", 10)( + "height", 20)))( + "defaultSource", dynamic::object("uri", "https://example.com/b.png"))( + "loadingIndicatorSrc", + dynamic::object("uri", "https://example.com/c.png"))( + "resizeMode", "contain")("blurRadius", 2)( + "capInsets", + dynamic::object("top", 1)("left", 2)("bottom", 3)("right", 4))( + "tintColor", 0xFF00FF00)("internal_analyticTag", "tag")( + "resizeMethod", "resize")("resizeMultiplier", 2)( + "shouldNotifyLoadEvents", true)("overlayColor", 0xFFFF0000)( + "fadeDuration", 100)("progressiveRenderingEnabled", true)); + + EXPECT_ITERATOR_SETTER_PARITY(parity, sources); + EXPECT_ITERATOR_SETTER_PARITY(parity, defaultSource); + EXPECT_ITERATOR_SETTER_PARITY(parity, loadingIndicatorSource); + EXPECT_ITERATOR_SETTER_PARITY(parity, resizeMode); + EXPECT_ITERATOR_SETTER_PARITY(parity, blurRadius); + EXPECT_ITERATOR_SETTER_PARITY(parity, capInsets); + EXPECT_ITERATOR_SETTER_PARITY(parity, tintColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, internal_analyticTag); + EXPECT_ITERATOR_SETTER_PARITY(parity, resizeMethod); + EXPECT_ITERATOR_SETTER_PARITY(parity, resizeMultiplier); + EXPECT_ITERATOR_SETTER_PARITY(parity, shouldNotifyLoadEvents); + EXPECT_ITERATOR_SETTER_PARITY(parity, overlayColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, fadeDuration); + EXPECT_ITERATOR_SETTER_PARITY(parity, progressiveRenderingEnabled); +} + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp index 5b6f28634352..fe9ca993b42b 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp @@ -170,7 +170,7 @@ BaseScrollViewProps::BaseScrollViewProps( rawProps, "horizontal", sourceProps.horizontal, - true)), + false)), scrollEventThrottle(convertRawProp( context, rawProps, diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/tests/ScrollViewPropsIteratorSetterParityTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/scrollview/tests/ScrollViewPropsIteratorSetterParityTest.cpp new file mode 100644 index 000000000000..ce1c0a4bb8c7 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/tests/ScrollViewPropsIteratorSetterParityTest.cpp @@ -0,0 +1,87 @@ +/* + * 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. + */ + +#include + +#include +#include + +namespace facebook::react { + +using folly::dynamic; + +TEST(ScrollViewPropsIteratorSetterParityTest, setsAndClearsScrollViewProps) { + const dynamic edgeInsets = + dynamic::object("top", 1)("left", 2)("bottom", 3)("right", 4); + const auto parity = buildIteratorSetterParity( + dynamic::object("alwaysBounceHorizontal", true)( + "alwaysBounceVertical", true)("bounces", false)("bouncesZoom", false)( + "canCancelContentTouches", false)("centerContent", true)( + "automaticallyAdjustContentInsets", true)( + "automaticallyAdjustsScrollIndicatorInsets", false)( + "automaticallyAdjustKeyboardInsets", true)("decelerationRate", 0.5)( + "directionalLockEnabled", true)("indicatorStyle", "black")( + "keyboardDismissMode", "on-drag")( + "maintainVisibleContentPosition", + dynamic::object("minIndexForVisible", 1))("maximumZoomScale", 3)( + "minimumZoomScale", 0.5)("scrollEnabled", false)( + "endDraggingSensitivityMultiplier", 2)("pagingEnabled", true)( + "pinchGestureEnabled", false)("scrollsToTop", false)( + "showsHorizontalScrollIndicator", false)( + "showsVerticalScrollIndicator", false)("persistentScrollbar", true)( + "horizontal", true)("scrollEventThrottle", 16)("zoomScale", 2)( + "contentInset", edgeInsets)( + "contentOffset", dynamic::object("x", 5)("y", 6))( + "scrollIndicatorInsets", edgeInsets)("snapToInterval", 50)( + "snapToAlignment", "center")("disableIntervalMomentum", true)( + "snapToOffsets", dynamic::array(10, 20))("snapToStart", false)( + "snapToEnd", false)("contentInsetAdjustmentBehavior", "always")( + "scrollToOverflowEnabled", true)("isInvertedVirtualizedList", true)); + + EXPECT_ITERATOR_SETTER_PARITY(parity, alwaysBounceHorizontal); + EXPECT_ITERATOR_SETTER_PARITY(parity, alwaysBounceVertical); + EXPECT_ITERATOR_SETTER_PARITY(parity, bounces); + EXPECT_ITERATOR_SETTER_PARITY(parity, bouncesZoom); + EXPECT_ITERATOR_SETTER_PARITY(parity, canCancelContentTouches); + EXPECT_ITERATOR_SETTER_PARITY(parity, centerContent); + EXPECT_ITERATOR_SETTER_PARITY(parity, automaticallyAdjustContentInsets); + EXPECT_ITERATOR_SETTER_PARITY( + parity, automaticallyAdjustsScrollIndicatorInsets); + EXPECT_ITERATOR_SETTER_PARITY(parity, automaticallyAdjustKeyboardInsets); + EXPECT_ITERATOR_SETTER_PARITY(parity, decelerationRate); + EXPECT_ITERATOR_SETTER_PARITY(parity, directionalLockEnabled); + EXPECT_ITERATOR_SETTER_PARITY(parity, indicatorStyle); + EXPECT_ITERATOR_SETTER_PARITY(parity, keyboardDismissMode); + EXPECT_ITERATOR_SETTER_PARITY(parity, maintainVisibleContentPosition); + EXPECT_ITERATOR_SETTER_PARITY(parity, maximumZoomScale); + EXPECT_ITERATOR_SETTER_PARITY(parity, minimumZoomScale); + EXPECT_ITERATOR_SETTER_PARITY(parity, scrollEnabled); + EXPECT_ITERATOR_SETTER_PARITY(parity, endDraggingSensitivityMultiplier); + EXPECT_ITERATOR_SETTER_PARITY(parity, pagingEnabled); + EXPECT_ITERATOR_SETTER_PARITY(parity, pinchGestureEnabled); + EXPECT_ITERATOR_SETTER_PARITY(parity, scrollsToTop); + EXPECT_ITERATOR_SETTER_PARITY(parity, showsHorizontalScrollIndicator); + EXPECT_ITERATOR_SETTER_PARITY(parity, showsVerticalScrollIndicator); + EXPECT_ITERATOR_SETTER_PARITY(parity, persistentScrollbar); + EXPECT_ITERATOR_SETTER_PARITY(parity, horizontal); + EXPECT_ITERATOR_SETTER_PARITY(parity, scrollEventThrottle); + EXPECT_ITERATOR_SETTER_PARITY(parity, zoomScale); + EXPECT_ITERATOR_SETTER_PARITY(parity, contentInset); + EXPECT_ITERATOR_SETTER_PARITY(parity, contentOffset); + EXPECT_ITERATOR_SETTER_PARITY(parity, scrollIndicatorInsets); + EXPECT_ITERATOR_SETTER_PARITY(parity, snapToInterval); + EXPECT_ITERATOR_SETTER_PARITY(parity, snapToAlignment); + EXPECT_ITERATOR_SETTER_PARITY(parity, disableIntervalMomentum); + EXPECT_ITERATOR_SETTER_PARITY(parity, snapToOffsets); + EXPECT_ITERATOR_SETTER_PARITY(parity, snapToStart); + EXPECT_ITERATOR_SETTER_PARITY(parity, snapToEnd); + EXPECT_ITERATOR_SETTER_PARITY(parity, contentInsetAdjustmentBehavior); + EXPECT_ITERATOR_SETTER_PARITY(parity, scrollToOverflowEnabled); + EXPECT_ITERATOR_SETTER_PARITY(parity, isInvertedVirtualizedList); +} + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/tests/TextPropsIteratorSetterParityTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/text/tests/TextPropsIteratorSetterParityTest.cpp new file mode 100644 index 000000000000..0a8bdca9be55 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/text/tests/TextPropsIteratorSetterParityTest.cpp @@ -0,0 +1,106 @@ +/* + * 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. + */ + +#include + +#include +#include +#include + +namespace facebook::react { + +using folly::dynamic; + +TEST(TextPropsIteratorSetterParityTest, setsAndClearsTextProps) { + const auto parity = buildIteratorSetterParity(dynamic::object( + "color", 0xFF00FF00)("fontFamily", "Menlo")("fontSize", 18)( + "fontSizeMultiplier", 2)("fontWeight", "bold")("fontStyle", "italic")( + "fontVariant", dynamic::array("small-caps"))( + "fontVariationSettings", "'wght' 700")("allowFontScaling", false)( + "maxFontSizeMultiplier", 3)("dynamicTypeRamp", "body")( + "letterSpacing", 1.5)("textTransform", "uppercase")("lineHeight", 22)( + "textAlign", "center")("writingDirection", "rtl")( + "lineBreakStrategyIOS", "standard")("lineBreakModeIOS", "clipping")( + "textDecorationColor", 0xFFFF0000)("textDecorationLine", "underline")( + "textDecorationStyle", "dashed")( + "textShadowOffset", dynamic::object("width", 1)("height", 2))( + "textShadowRadius", 3)("textShadowColor", 0xFF0000FF)( + "isHighlighted", true)("isPressable", true)("accessibilityRole", "link")( + "role", "button")("opacity", 0.5)("backgroundColor", 0xFF00FFFF)); + + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.foregroundColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontFamily); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontSize); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontSizeMultiplier); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontWeight); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontStyle); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontVariant); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontVariationSettings); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.allowFontScaling); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.maxFontSizeMultiplier); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.dynamicTypeRamp); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.letterSpacing); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.textTransform); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.lineHeight); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.alignment); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.baseWritingDirection); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.lineBreakStrategy); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.lineBreakMode); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.textDecorationColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.textDecorationLineType); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.textDecorationStyle); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.textShadowOffset); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.textShadowRadius); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.textShadowColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.isHighlighted); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.isPressable); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.accessibilityRole); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.role); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.opacity); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.backgroundColor); +} + +TEST(TextPropsIteratorSetterParityTest, setsAndClearsParagraphProps) { + const auto parity = buildIteratorSetterParity( + dynamic::object("numberOfLines", 2)("ellipsizeMode", "middle")( + "textBreakStrategy", "simple")( + "experimental_textWidthMode", "longest-line")( + "adjustsFontSizeToFit", true)("minimumFontScale", 0.5)( + "minimumFontSize", 8)("includeFontPadding", false)( + "android_hyphenationFrequency", "full")("lineBreak", "strict")( + "wordBreak", "auto-phrase")("textAlignVertical", "center")( + "selectable", true)("onTextLayout", true)("fontSize", 18)( + "opacity", 0.5)("backgroundColor", 0xFF00FFFF)); + + EXPECT_ITERATOR_SETTER_PARITY( + parity, paragraphAttributes.maximumNumberOfLines); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.ellipsizeMode); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.textBreakStrategy); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.textWidthMode); + EXPECT_ITERATOR_SETTER_PARITY( + parity, paragraphAttributes.adjustsFontSizeToFit); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.minimumFontScale); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.minimumFontSize); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.includeFontPadding); + EXPECT_ITERATOR_SETTER_PARITY( + parity, paragraphAttributes.android_hyphenationFrequency); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.lineBreak); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.wordBreak); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.textAlignVertical); + EXPECT_ITERATOR_SETTER_PARITY(parity, isSelectable); + EXPECT_ITERATOR_SETTER_PARITY(parity, onTextLayout); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontSize); + EXPECT_ITERATOR_SETTER_PARITY(parity, opacity); + EXPECT_ITERATOR_SETTER_PARITY(parity, backgroundColor); + + // Paragraph applies `opacity` and `backgroundColor` to its view, not to its + // text attributes + EXPECT_TRUE(std::isnan(parity.iterator.textAttributes.opacity)); + EXPECT_EQ(parity.iterator.textAttributes.backgroundColor, SharedColor{}); +} + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp index c85f11971acc..976cca9e8ad9 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp @@ -167,12 +167,24 @@ void BaseTextInputProps::setProp( paragraphAttributes, textBreakStrategy, "textBreakStrategy"); + REBUILD_FIELD_SWITCH_CASE( + paDefaults, + value, + paragraphAttributes, + textWidthMode, + "experimental_textWidthMode"); REBUILD_FIELD_SWITCH_CASE( paDefaults, value, paragraphAttributes, adjustsFontSizeToFit, "adjustsFontSizeToFit"); + REBUILD_FIELD_SWITCH_CASE( + paDefaults, + value, + paragraphAttributes, + minimumFontScale, + "minimumFontScale"); REBUILD_FIELD_SWITCH_CASE( paDefaults, value, @@ -191,6 +203,10 @@ void BaseTextInputProps::setProp( paragraphAttributes, android_hyphenationFrequency, "android_hyphenationFrequency"); + REBUILD_FIELD_SWITCH_CASE( + paDefaults, value, paragraphAttributes, lineBreak, "lineBreak"); + REBUILD_FIELD_SWITCH_CASE( + paDefaults, value, paragraphAttributes, wordBreak, "wordBreak"); REBUILD_FIELD_SWITCH_CASE( paDefaults, value, diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/BaseTextInputPropsIteratorSetterParityTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/BaseTextInputPropsIteratorSetterParityTest.cpp new file mode 100644 index 000000000000..4fec66b7a5f2 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/BaseTextInputPropsIteratorSetterParityTest.cpp @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#include + +#include +#include + +namespace facebook::react { + +using folly::dynamic; + +TEST(BaseTextInputPropsIteratorSetterParityTest, setsAndClearsTextInputProps) { + const auto parity = buildIteratorSetterParity( + dynamic::object("numberOfLines", 2)("ellipsizeMode", "middle")( + "textBreakStrategy", "simple")( + "experimental_textWidthMode", "longest-line")( + "adjustsFontSizeToFit", true)("minimumFontScale", 0.5)( + "minimumFontSize", 8)("includeFontPadding", false)( + "android_hyphenationFrequency", "full")("lineBreak", "strict")( + "wordBreak", "auto-phrase")("textAlignVertical", "center")( + "underlineColorAndroid", 0xFF00FF00)("autoFocus", true)( + "maxLength", 10)("placeholder", "placeholder")( + "placeholderTextColor", 0xFFFF0000)("selectionColor", 0xFF0000FF)( + "selectionHandleColor", 0xFF00FFFF)("defaultValue", "default")( + "cursorColor", 0xFFFFFF00)("text", "text")("mostRecentEventCount", 3)( + "autoCapitalize", "words")("editable", false)("readOnly", true)( + "submitBehavior", "submit")("multiline", true)( + "disableKeyboardShortcuts", true)( + "acceptDragAndDropTypes", dynamic::array("text/plain"))( + "fontSize", 18)); + + EXPECT_ITERATOR_SETTER_PARITY( + parity, paragraphAttributes.maximumNumberOfLines); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.ellipsizeMode); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.textBreakStrategy); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.textWidthMode); + EXPECT_ITERATOR_SETTER_PARITY( + parity, paragraphAttributes.adjustsFontSizeToFit); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.minimumFontScale); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.minimumFontSize); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.includeFontPadding); + EXPECT_ITERATOR_SETTER_PARITY( + parity, paragraphAttributes.android_hyphenationFrequency); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.lineBreak); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.wordBreak); + EXPECT_ITERATOR_SETTER_PARITY(parity, paragraphAttributes.textAlignVertical); + EXPECT_ITERATOR_SETTER_PARITY(parity, underlineColorAndroid); + EXPECT_ITERATOR_SETTER_PARITY(parity, autoFocus); + EXPECT_ITERATOR_SETTER_PARITY(parity, maxLength); + EXPECT_ITERATOR_SETTER_PARITY(parity, placeholder); + EXPECT_ITERATOR_SETTER_PARITY(parity, placeholderTextColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, selectionColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, selectionHandleColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, defaultValue); + EXPECT_ITERATOR_SETTER_PARITY(parity, cursorColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, text); + EXPECT_ITERATOR_SETTER_PARITY(parity, mostRecentEventCount); + EXPECT_ITERATOR_SETTER_PARITY(parity, autoCapitalize); + EXPECT_ITERATOR_SETTER_PARITY(parity, editable); + EXPECT_ITERATOR_SETTER_PARITY(parity, readOnly); + EXPECT_ITERATOR_SETTER_PARITY(parity, submitBehavior); + EXPECT_ITERATOR_SETTER_PARITY(parity, multiline); + EXPECT_ITERATOR_SETTER_PARITY(parity, disableKeyboardShortcuts); + EXPECT_ITERATOR_SETTER_PARITY(parity, acceptDragAndDropTypes); + EXPECT_ITERATOR_SETTER_PARITY(parity, textAttributes.fontSize); +} + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp index 98332197d3fb..4a5249cad336 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp @@ -379,7 +379,7 @@ void BaseViewProps::setProp( RAW_SET_PROP_SWITCH_CASE_BASIC(transform); RAW_SET_PROP_SWITCH_CASE_BASIC(transformOrigin); RAW_SET_PROP_SWITCH_CASE_BASIC(backfaceVisibility); - RAW_SET_PROP_SWITCH_CASE_BASIC(shouldRasterize); + RAW_SET_PROP_SWITCH_CASE(shouldRasterize, "shouldRasterizeIOS"); RAW_SET_PROP_SWITCH_CASE_BASIC(zIndex); RAW_SET_PROP_SWITCH_CASE_BASIC(pointerEvents); RAW_SET_PROP_SWITCH_CASE_BASIC(isolation); diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h b/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h index 9d4fc75dfeb7..4ab67b8e6fbb 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h @@ -336,11 +336,21 @@ convertRawProp(const PropsParserContext &context, const RawProps &rawProps, cons yogaStyle.setDimension( yoga::Dimension::Width, - convertRawProp(context, rawProps, "width", sourceValue.dimension(yoga::Dimension::Width), {})); + convertRawProp( + context, + rawProps, + "width", + sourceValue.dimension(yoga::Dimension::Width), + yogaStyle.dimension(yoga::Dimension::Width))); yogaStyle.setDimension( yoga::Dimension::Height, - convertRawProp(context, rawProps, "height", sourceValue.dimension(yoga::Dimension::Height), {})); + convertRawProp( + context, + rawProps, + "height", + sourceValue.dimension(yoga::Dimension::Height), + yogaStyle.dimension(yoga::Dimension::Height))); yogaStyle.setMinDimension( yoga::Dimension::Width, diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewPropsIteratorSetterParityTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewPropsIteratorSetterParityTest.cpp new file mode 100644 index 000000000000..9e17fb8061f0 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewPropsIteratorSetterParityTest.cpp @@ -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. + */ + +#include + +#include +#include + +namespace facebook::react { + +using folly::dynamic; + +TEST(ViewPropsIteratorSetterParityTest, setsAndClearsViewProps) { + const auto parity = buildIteratorSetterParity(dynamic::object( + "opacity", 0.5)("backgroundColor", 0xFF00FF00)("shadowColor", 0xFF0000FF)( + "shadowOpacity", 0.25)("shadowRadius", 4)( + "transform", dynamic::array(dynamic::object("rotate", "45deg")))( + "backfaceVisibility", "hidden")("shouldRasterizeIOS", true)("zIndex", 3)( + "pointerEvents", "box-none")( + "hitSlop", dynamic::object("top", 1)("left", 2)("bottom", 3)("right", 4))( + "collapsable", false)("removeClippedSubviews", true)( + "outlineColor", 0xFFFF0000)("outlineWidth", 2)("borderTopLeftRadius", 6)( + "borderColor", 0xFF00FFFF)("padding", 10)("width", 100)("height", 50)( + "nativeID", "native")("testID", "test")("accessible", true)( + "accessibilityLabel", "label")("onPointerUp", true)); + + EXPECT_ITERATOR_SETTER_PARITY(parity, opacity); + EXPECT_ITERATOR_SETTER_PARITY(parity, backgroundColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, shadowColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, shadowOpacity); + EXPECT_ITERATOR_SETTER_PARITY(parity, shadowRadius); + EXPECT_ITERATOR_SETTER_PARITY(parity, transform); + EXPECT_ITERATOR_SETTER_PARITY(parity, backfaceVisibility); + EXPECT_ITERATOR_SETTER_PARITY(parity, shouldRasterize); + EXPECT_ITERATOR_SETTER_PARITY(parity, zIndex); + EXPECT_ITERATOR_SETTER_PARITY(parity, pointerEvents); + EXPECT_ITERATOR_SETTER_PARITY(parity, hitSlop); + EXPECT_ITERATOR_SETTER_PARITY(parity, collapsable); + EXPECT_ITERATOR_SETTER_PARITY(parity, removeClippedSubviews); + EXPECT_ITERATOR_SETTER_PARITY(parity, outlineColor); + EXPECT_ITERATOR_SETTER_PARITY(parity, outlineWidth); + EXPECT_ITERATOR_SETTER_PARITY(parity, borderRadii); + EXPECT_ITERATOR_SETTER_PARITY(parity, borderColors); + EXPECT_ITERATOR_SETTER_PARITY(parity, yogaStyle); + EXPECT_ITERATOR_SETTER_PARITY(parity, nativeId); + EXPECT_ITERATOR_SETTER_PARITY(parity, testId); + EXPECT_ITERATOR_SETTER_PARITY(parity, accessible); + EXPECT_ITERATOR_SETTER_PARITY(parity, accessibilityLabel); + EXPECT_ITERATOR_SETTER_PARITY(parity, events); +} + +TEST(ViewPropsIteratorSetterParityTest, keepsPropsAnUpdateOmits) { + const auto source = + buildClassicAndIteratorProps( + ViewProps{}, dynamic::object("opacity", 0.5)("nativeID", "initial")) + .first; + const auto [updatedClassic, updatedIterator] = buildClassicAndIteratorProps( + source, dynamic::object("nativeID", "updated")); + + EXPECT_EQ(updatedIterator.opacity, 0.5); + EXPECT_EQ(updatedIterator.opacity, updatedClassic.opacity); + EXPECT_EQ(updatedIterator.nativeId, "updated"); + EXPECT_EQ(updatedIterator.nativeId, updatedClassic.nativeId); +} + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/test_utils/PropsIteratorSetterParity.h b/packages/react-native/ReactCommon/react/test_utils/PropsIteratorSetterParity.h new file mode 100644 index 000000000000..86fa916955f2 --- /dev/null +++ b/packages/react-native/ReactCommon/react/test_utils/PropsIteratorSetterParity.h @@ -0,0 +1,115 @@ +/* + * 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. + */ + +#pragma once + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace facebook::react { + +/* + * Builds `PropsT` from `source` and `values` with the classic constructor and + * with the iterator setter that `ConcreteComponentDescriptor::cloneProps` uses + * when `enableCppPropsIteratorSetter` is on, and returns both. + */ +template +std::pair buildClassicAndIteratorProps(const PropsT &source, const folly::dynamic &values) +{ + ContextContainer contextContainer{}; + PropsParserContext context{-1, contextContainer}; + + RawPropsParser parser; + parser.template prepare(); + RawProps classicRawProps{values}; + classicRawProps.parse(parser); + PropsT classic{context, source, classicRawProps}; + + PropsT iterator{source}; + RawProps{values}.forEachItem([&](std::string_view name, const RawValue &value) { + iterator.setProp(context, RAW_PROPS_KEY_HASH(name), name.data(), value); + }); + return {std::move(classic), std::move(iterator)}; +} + +/* + * Props built from the same values by `buildClassicAndIteratorProps`. + * `classic` and `iterator` start from default props. `clearedClassic` and + * `clearedIterator` start from `classic` and receive null for every key, as + * when JS removes the props. + */ +template +struct IteratorSetterParity { + PropsT defaults; + PropsT classic; + PropsT iterator; + PropsT clearedClassic; + PropsT clearedIterator; +}; + +namespace detail { + +// Compares floating-point values with NaN equal to NaN, since NaN is the +// default of several props +template +bool isSamePropValue(const T &a, const T &b) +{ + if constexpr (std::is_floating_point_v) { + return a == b || (std::isnan(a) && std::isnan(b)); + } else { + return a == b; + } +} + +} // namespace detail + +template +IteratorSetterParity buildIteratorSetterParity(const folly::dynamic &values) +{ + folly::dynamic nullValues = folly::dynamic::object(); + for (const auto &key : values.keys()) { + nullValues[key] = nullptr; + } + + PropsT defaults{}; + auto [classic, iterator] = buildClassicAndIteratorProps(defaults, values); + auto [clearedClassic, clearedIterator] = buildClassicAndIteratorProps(classic, nullValues); + return { + .defaults = std::move(defaults), + .classic = std::move(classic), + .iterator = std::move(iterator), + .clearedClassic = std::move(clearedClassic), + .clearedIterator = std::move(clearedIterator), + }; +} + +} // namespace facebook::react + +/* + * Expects the values given to `buildIteratorSetterParity` to set `field` away + * from its default, and both paths to agree on `field` after setting and after + * clearing. `field` may be a member path such as `paragraphAttributes.lineBreak`. + */ +#define EXPECT_ITERATOR_SETTER_PARITY(parity, field) \ + do { \ + EXPECT_FALSE(facebook::react::detail::isSamePropValue((parity).classic.field, (parity).defaults.field)) \ + << "The values do not set `" #field "`"; \ + EXPECT_TRUE(facebook::react::detail::isSamePropValue((parity).classic.field, (parity).iterator.field)) \ + << "The iterator setter sets `" #field "` differently"; \ + EXPECT_TRUE( \ + facebook::react::detail::isSamePropValue((parity).clearedClassic.field, (parity).clearedIterator.field)) \ + << "The iterator setter clears `" #field "` differently"; \ + } while (false) diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index ea7af7e6f9f6..23cc0baafef3 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -225,7 +225,7 @@ const definitions: FeatureFlagDefinitions = { }, enableCppPropsIteratorSetter: { dangerouslyExposeInPublicCppHeaders: true, - defaultValue: false, + defaultValue: true, metadata: { dateAdded: '2024-09-13', description: diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 555b30cbada4..3112495f7bad 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<1f215e8de26f9c642b5749a0d05b6e86>> * @flow strict * @noformat */ @@ -294,7 +294,7 @@ export const enableBridgelessArchitecture: Getter = createNativeFlagGet /** * Enable prop iterator setter-style construction of Props in C++ (this flag is not used in Java). */ -export const enableCppPropsIteratorSetter: Getter = createNativeFlagGetter('enableCppPropsIteratorSetter', false); +export const enableCppPropsIteratorSetter: Getter = createNativeFlagGetter('enableCppPropsIteratorSetter', true); /** * This enables the fabric implementation of focus search so that we can focus clipped elements */