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 8bb0c758ffcb..a1dbcc6b3b14 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<> */ /** @@ -57,7 +57,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 bcada3ac19e9..65ebde88de42 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<<27603b5ebd0d0ced33789cc995cee9c1>> + * @generated SignedSource<<5ea58a9bc8cf405df4d60e2080621c85>> */ /** @@ -98,7 +98,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 fd7776fac490..16010cc3e225 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -236,7 +236,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 ce26327cf2a7..b3787c14b431 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<<19928f42843899212bc6ff3bc8a08ba9>> + * @generated SignedSource<<32b7a910b52890d350563a76712dc2ac>> * @flow strict * @noformat */ @@ -299,7 +299,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 */