From 983beee67bc4be7642a9c04d3a51e9768bcc5335 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 9 Nov 2023 19:13:05 -0800 Subject: [PATCH] Remove yoga::Style::BitfieldRef (#41393) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41393 X-link: https://github.com/facebook/yoga/pull/1459 Removes the last of the non setter-style style setters. Differential Revision: D51155925 fbshipit-source-id: 3311be4d2592425a3703e213de99ec41ead2737d --- .../Text/RCTParagraphComponentViewTests.mm | 8 +- .../view/YogaLayoutableShadowNode.cpp | 2 +- .../components/view/YogaStylableProps.cpp | 47 +++---- .../components/view/propsConversions.h | 54 ++++--- .../components/view/tests/LayoutTest.cpp | 12 +- .../components/view/tests/ViewTest.cpp | 8 +- .../mounting/tests/StackingContextTest.cpp | 24 ++-- .../ReactCommon/yoga/yoga/YGNodeStyle.cpp | 132 +++++++----------- .../ReactCommon/yoga/yoga/node/Node.h | 4 +- .../ReactCommon/yoga/yoga/style/Style.h | 81 +++++------ 10 files changed, 169 insertions(+), 203 deletions(-) diff --git a/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm b/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm index 2d8e5de1fb5c00..f23f353e121288 100644 --- a/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm +++ b/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm @@ -133,7 +133,7 @@ - (void)setUp auto &props = *sharedProps; props.accessible = true; auto &yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0)); yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(0)); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); @@ -213,7 +213,7 @@ - (void)setUp auto &props = *sharedProps; props.accessible = true; auto &yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0)); yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(30)); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); @@ -257,7 +257,7 @@ - (void)setUp auto &props = *sharedProps; props.accessible = true; auto &yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0)); yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(90)); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); @@ -431,7 +431,7 @@ - (void)testEntireParagraphLink props.accessible = true; props.accessibilityTraits = AccessibilityTraits::Link; auto &yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0)); yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(90)); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp index 94bb5f612a69db..8b2ff09be47003 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -563,7 +563,7 @@ void YogaLayoutableShadowNode::setPositionType( ensureUnsealed(); auto style = yogaNode_.getStyle(); - style.positionType() = yoga::scopedEnum(positionType); + style.setPositionType(yoga::scopedEnum(positionType)); yogaNode_.setStyle(style); yogaNode_.setDirty(true); } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp index 7ae0f11bfa4ff0..db6e30449f4249 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp @@ -164,22 +164,15 @@ static inline T const getFieldValue( return defaultValue; } -#define REBUILD_FIELD_SWITCH_CASE2(field, fieldName) \ - case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \ - yogaStyle.field() = getFieldValue(context, value, ygDefaults.field()); \ - return; \ - } - -// @lint-ignore CLANGTIDY cppcoreguidelines-macro-usage -#define REBUILD_FIELD_SWITCH_CASE_YSP(field) \ - REBUILD_FIELD_SWITCH_CASE2(field, #field) - -#define REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(field, setter) \ - case CONSTEXPR_RAW_PROPS_KEY_HASH(#field): { \ +#define REBUILD_FIELD_SWITCH_CASE2(field, setter, fieldName) \ + case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \ yogaStyle.setter(getFieldValue(context, value, ygDefaults.field())); \ return; \ } +#define REBUILD_FIELD_SWITCH_CASE_YSP(field, setter) \ + REBUILD_FIELD_SWITCH_CASE2(field, setter, #field) + #define REBUILD_YG_FIELD_SWITCH_CASE_INDEXED(field, setter, index, fieldName) \ case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \ yogaStyle.setter( \ @@ -253,22 +246,22 @@ void YogaStylableProps::setProp( Props::setProp(context, hash, propName, value); switch (hash) { - REBUILD_FIELD_SWITCH_CASE_YSP(direction); - REBUILD_FIELD_SWITCH_CASE_YSP(flexDirection); - REBUILD_FIELD_SWITCH_CASE_YSP(justifyContent); - REBUILD_FIELD_SWITCH_CASE_YSP(alignContent); - REBUILD_FIELD_SWITCH_CASE_YSP(alignItems); - REBUILD_FIELD_SWITCH_CASE_YSP(alignSelf); - REBUILD_FIELD_SWITCH_CASE_YSP(flexWrap); - REBUILD_FIELD_SWITCH_CASE_YSP(overflow); - REBUILD_FIELD_SWITCH_CASE_YSP(display); - REBUILD_FIELD_SWITCH_CASE_YSP(flex); - REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(flexGrow, setFlexGrow); - REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(flexShrink, setFlexShrink); - REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(flexBasis, setFlexBasis); - REBUILD_FIELD_SWITCH_CASE2(positionType, "position"); + REBUILD_FIELD_SWITCH_CASE_YSP(direction, setDirection); + REBUILD_FIELD_SWITCH_CASE_YSP(flexDirection, setFlexDirection); + REBUILD_FIELD_SWITCH_CASE_YSP(justifyContent, setJustifyContent); + REBUILD_FIELD_SWITCH_CASE_YSP(alignContent, setAlignContent); + REBUILD_FIELD_SWITCH_CASE_YSP(alignItems, setAlignItems); + REBUILD_FIELD_SWITCH_CASE_YSP(alignSelf, setAlignSelf); + REBUILD_FIELD_SWITCH_CASE_YSP(flexWrap, setFlexWrap); + REBUILD_FIELD_SWITCH_CASE_YSP(overflow, setOverflow); + REBUILD_FIELD_SWITCH_CASE_YSP(display, setDisplay); + REBUILD_FIELD_SWITCH_CASE_YSP(flex, setFlex); + REBUILD_FIELD_SWITCH_CASE_YSP(flexGrow, setFlexGrow); + REBUILD_FIELD_SWITCH_CASE_YSP(flexShrink, setFlexShrink); + REBUILD_FIELD_SWITCH_CASE_YSP(flexBasis, setFlexBasis); + REBUILD_FIELD_SWITCH_CASE2(positionType, setPositionType, "position"); REBUILD_FIELD_YG_GUTTER(gap, setGap, "rowGap", "columnGap", "gap"); - REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(aspectRatio, setAspectRatio); + REBUILD_FIELD_SWITCH_CASE_YSP(aspectRatio, setAspectRatio); REBUILD_FIELD_YG_DIMENSION(dimension, setDimension, "width", "height"); REBUILD_FIELD_YG_DIMENSION( minDimension, setMinDimension, "minWidth", "minHeight"); 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 fc236455fa8f8e..7b078053b74607 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h @@ -23,62 +23,76 @@ static inline yoga::Style convertRawProp( const RawProps& rawProps, const yoga::Style& sourceValue) { yoga::Style yogaStyle{}; - yogaStyle.direction() = convertRawProp( + + yogaStyle.setDirection(convertRawProp( context, rawProps, "direction", sourceValue.direction(), - yogaStyle.direction()); - yogaStyle.flexDirection() = convertRawProp( + yogaStyle.direction())); + + yogaStyle.setFlexDirection(convertRawProp( context, rawProps, "flexDirection", sourceValue.flexDirection(), - yogaStyle.flexDirection()); - yogaStyle.justifyContent() = convertRawProp( + yogaStyle.flexDirection())); + + yogaStyle.setJustifyContent(convertRawProp( context, rawProps, "justifyContent", sourceValue.justifyContent(), - yogaStyle.justifyContent()); - yogaStyle.alignContent() = convertRawProp( + yogaStyle.justifyContent())); + + yogaStyle.setAlignContent(convertRawProp( context, rawProps, "alignContent", sourceValue.alignContent(), - yogaStyle.alignContent()); - yogaStyle.alignItems() = convertRawProp( + yogaStyle.alignContent())); + + yogaStyle.setAlignItems(convertRawProp( context, rawProps, "alignItems", sourceValue.alignItems(), - yogaStyle.alignItems()); - yogaStyle.alignSelf() = convertRawProp( + yogaStyle.alignItems())); + + yogaStyle.setAlignSelf(convertRawProp( context, rawProps, "alignSelf", sourceValue.alignSelf(), - yogaStyle.alignSelf()); - yogaStyle.positionType() = convertRawProp( + yogaStyle.alignSelf())); + + yogaStyle.setPositionType(convertRawProp( context, rawProps, "position", sourceValue.positionType(), - yogaStyle.positionType()); - yogaStyle.flexWrap() = convertRawProp( + yogaStyle.positionType())); + + yogaStyle.setFlexWrap(convertRawProp( context, rawProps, "flexWrap", sourceValue.flexWrap(), - yogaStyle.flexWrap()); - yogaStyle.overflow() = convertRawProp( + yogaStyle.flexWrap())); + + yogaStyle.setOverflow(convertRawProp( context, rawProps, "overflow", sourceValue.overflow(), - yogaStyle.overflow()); - yogaStyle.display() = convertRawProp( - context, rawProps, "display", sourceValue.display(), yogaStyle.display()); + yogaStyle.overflow())); + + yogaStyle.setDisplay(convertRawProp( + context, + rawProps, + "display", + sourceValue.display(), + yogaStyle.display())); yogaStyle.setFlex(convertRawProp( context, rawProps, "flex", sourceValue.flex(), yogaStyle.flex())); diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp index bdb879a974598e..9933cce9f47ed7 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp @@ -89,7 +89,7 @@ class LayoutTest : public ::testing::Test { auto sharedProps = std::make_shared(); auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(50)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50)); return sharedProps; @@ -102,7 +102,7 @@ class LayoutTest : public ::testing::Test { auto sharedProps = std::make_shared(); auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(10)); yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(10)); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(30)); @@ -132,10 +132,10 @@ class LayoutTest : public ::testing::Test { auto &yogaStyle = props.yogaStyle; if (testCase == CLIPPING) { - yogaStyle.overflow() = yoga::Overflow::Hidden; + yogaStyle.setOverflow(yoga::Overflow::Hidden); } - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(10)); yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(10)); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(110)); @@ -150,7 +150,7 @@ class LayoutTest : public ::testing::Test { auto sharedProps = std::make_shared(); auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(70)); yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(-50)); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(30)); @@ -165,7 +165,7 @@ class LayoutTest : public ::testing::Test { auto sharedProps = std::make_shared(); auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(-60)); yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(50)); yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(70)); diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp index f948248c680eef..f0302ffc06f9bd 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp @@ -52,8 +52,8 @@ class YogaDirtyFlagTest : public ::testing::Test { auto &props = *mutableViewProps; props.nativeId = "native Id"; props.opacity = 0.5; - props.yogaStyle.alignContent() = yoga::Align::Baseline; - props.yogaStyle.flexDirection() = yoga::FlexDirection::RowReverse; + props.yogaStyle.setAlignContent(yoga::Align::Baseline); + props.yogaStyle.setFlexDirection(yoga::FlexDirection::RowReverse); return mutableViewProps; }), Element() @@ -136,8 +136,8 @@ TEST_F(YogaDirtyFlagTest, changingLayoutSubPropsMustDirtyYogaNode) { auto viewProps = std::make_shared(); auto& props = *viewProps; - props.yogaStyle.alignContent() = yoga::Align::Baseline; - props.yogaStyle.display() = yoga::Display::None; + props.yogaStyle.setAlignContent(yoga::Align::Baseline); + props.yogaStyle.setDisplay(yoga::Display::None); return oldShadowNode.clone(ShadowNodeFragment{viewProps}); }); diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp index f09dabda6d332e..e1eabecd057ad2 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp @@ -253,7 +253,7 @@ TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) { auto& yogaStyle = props.yogaStyle; yogaStyle.setPadding(yoga::Edge::All, yoga::value::points(42)); yogaStyle.setMargin(yoga::Edge::All, yoga::value::points(42)); - yogaStyle.positionType() = yoga::PositionType::Absolute; + yogaStyle.setPositionType(yoga::PositionType::Absolute); props.shadowRadius = 42; props.shadowOffset = Size{42, 42}; props.backgroundColor = clearColor(); @@ -269,7 +269,7 @@ TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) { mutateViewShadowNodeProps_(nodeBBA_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.borderRadii.all = 42; props.borderColors.all = blackColor(); @@ -456,7 +456,7 @@ TEST_F(StackingContextTest, somePropsForceViewsToMaterialize2) { mutateViewShadowNodeProps_(nodeBBB_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.zIndex = 42; }); @@ -538,37 +538,37 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) { mutateViewShadowNodeProps_(nodeAA_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.zIndex = 9001; }); mutateViewShadowNodeProps_(nodeBA_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.zIndex = 9000; }); mutateViewShadowNodeProps_(nodeBBA_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.zIndex = 8999; }); mutateViewShadowNodeProps_(nodeBBB_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.zIndex = 8998; }); mutateViewShadowNodeProps_(nodeBC_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.zIndex = 8997; }); mutateViewShadowNodeProps_(nodeBD_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.zIndex = 8996; }); @@ -652,7 +652,7 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) { mutateViewShadowNodeProps_(nodeBB_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Relative; + yogaStyle.setPositionType(yoga::PositionType::Relative); props.zIndex = 42; }); @@ -680,7 +680,7 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) { mutateViewShadowNodeProps_(nodeBB_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.positionType() = yoga::PositionType::Static; + yogaStyle.setPositionType(yoga::PositionType::Static); props.zIndex = {}; }); @@ -764,7 +764,7 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) { mutateViewShadowNodeProps_(nodeBB_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.display() = yoga::Display::None; + yogaStyle.setDisplay(yoga::Display::None); }); testViewTree_([](const StubViewTree& viewTree) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp index 441b7797f776fb..14f2dc3062270e 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp @@ -14,54 +14,26 @@ using namespace facebook::yoga; namespace { -template -void updateStyle( - yoga::Node* node, - T value, - NeedsUpdate&& needsUpdate, - Update&& update) { - if (needsUpdate(node->getStyle(), value)) { - update(node->getStyle(), value); - node->markDirtyAndPropagate(); - } -} - -template -void updateStyle(YGNodeRef node, Ref (Style::*prop)(), ValueT value) { - updateStyle( - resolveRef(node), - value, - [prop](Style& s, ValueT x) { return (s.*prop)() != x; }, - [prop](Style& s, ValueT x) { (s.*prop)() = x; }); -} - template void updateStyle(YGNodeRef node, ValueT value) { - updateStyle( - resolveRef(node), - value, - [](Style& s, ValueT x) { return (s.*GetterT)() != x; }, - [](Style& s, ValueT x) { (s.*SetterT)(x); }); + auto& style = resolveRef(node)->getStyle(); + if ((style.*GetterT)() != value) { + (style.*SetterT)(value); + resolveRef(node)->markDirtyAndPropagate(); + } } template -void updateIndexedStyleProp(YGNodeRef node, IdxT idx, ValueT value) { - updateStyle( - resolveRef(node), - value, - [idx](Style& s, ValueT x) { return (s.*GetterT)(idx) != x; }, - [idx](Style& s, ValueT x) { (s.*SetterT)(idx, x); }); +void updateStyle(YGNodeRef node, IdxT idx, ValueT value) { + auto& style = resolveRef(node)->getStyle(); + if ((style.*GetterT)(idx) != value) { + (style.*SetterT)(idx, value); + resolveRef(node)->markDirtyAndPropagate(); + } } } // namespace -// MSVC has trouble inferring the return type of pointer to member functions -// with const and non-const overloads, instead of preferring the non-const -// overload like clang and GCC. For the purposes of updateStyle(), we can help -// MSVC by specifying that return type explicitly. In combination with -// decltype, MSVC will prefer the non-const version. -#define MSVC_HINT(PROP) decltype(Style{}.PROP()) - void YGNodeCopyStyle( const YGNodeRef dstNodeRef, const YGNodeConstRef srcNodeRef) { @@ -75,7 +47,7 @@ void YGNodeCopyStyle( } void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) { - updateStyle(node, &Style::direction, scopedEnum(value)); + updateStyle<&Style::direction, &Style::setDirection>(node, scopedEnum(value)); } YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { @@ -85,8 +57,8 @@ YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { void YGNodeStyleSetFlexDirection( const YGNodeRef node, const YGFlexDirection flexDirection) { - updateStyle( - node, &Style::flexDirection, scopedEnum(flexDirection)); + updateStyle<&Style::flexDirection, &Style::setFlexDirection>( + node, scopedEnum(flexDirection)); } YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { @@ -96,8 +68,8 @@ YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { void YGNodeStyleSetJustifyContent( const YGNodeRef node, const YGJustify justifyContent) { - updateStyle( - node, &Style::justifyContent, scopedEnum(justifyContent)); + updateStyle<&Style::justifyContent, &Style::setJustifyContent>( + node, scopedEnum(justifyContent)); } YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { @@ -107,8 +79,8 @@ YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { void YGNodeStyleSetAlignContent( const YGNodeRef node, const YGAlign alignContent) { - updateStyle( - node, &Style::alignContent, scopedEnum(alignContent)); + updateStyle<&Style::alignContent, &Style::setAlignContent>( + node, scopedEnum(alignContent)); } YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { @@ -116,8 +88,8 @@ YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { } void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) { - updateStyle( - node, &Style::alignItems, scopedEnum(alignItems)); + updateStyle<&Style::alignItems, &Style::setAlignItems>( + node, scopedEnum(alignItems)); } YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { @@ -125,8 +97,8 @@ YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { } void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) { - updateStyle( - node, &Style::alignSelf, scopedEnum(alignSelf)); + updateStyle<&Style::alignSelf, &Style::setAlignSelf>( + node, scopedEnum(alignSelf)); } YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { @@ -136,8 +108,8 @@ YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { void YGNodeStyleSetPositionType( const YGNodeRef node, const YGPositionType positionType) { - updateStyle( - node, &Style::positionType, scopedEnum(positionType)); + updateStyle<&Style::positionType, &Style::setPositionType>( + node, scopedEnum(positionType)); } YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) { @@ -145,8 +117,8 @@ YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) { } void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) { - updateStyle( - node, &Style::flexWrap, scopedEnum(flexWrap)); + updateStyle<&Style::flexWrap, &Style::setFlexWrap>( + node, scopedEnum(flexWrap)); } YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { @@ -154,8 +126,8 @@ YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { } void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { - updateStyle( - node, &Style::overflow, scopedEnum(overflow)); + updateStyle<&Style::overflow, &Style::setOverflow>( + node, scopedEnum(overflow)); } YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { @@ -163,7 +135,7 @@ YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { } void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { - updateStyle(node, &Style::display, scopedEnum(display)); + updateStyle<&Style::display, &Style::setDisplay>(node, scopedEnum(display)); } YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { @@ -231,12 +203,12 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { } void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) { - updateIndexedStyleProp<&Style::position, &Style::setPosition>( + updateStyle<&Style::position, &Style::setPosition>( node, scopedEnum(edge), value::points(points)); } void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) { - updateIndexedStyleProp<&Style::position, &Style::setPosition>( + updateStyle<&Style::position, &Style::setPosition>( node, scopedEnum(edge), value::percent(percent)); } @@ -245,17 +217,17 @@ YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { } void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) { - updateIndexedStyleProp<&Style::margin, &Style::setMargin>( + updateStyle<&Style::margin, &Style::setMargin>( node, scopedEnum(edge), value::points(points)); } void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) { - updateIndexedStyleProp<&Style::margin, &Style::setMargin>( + updateStyle<&Style::margin, &Style::setMargin>( node, scopedEnum(edge), value::percent(percent)); } void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { - updateIndexedStyleProp<&Style::margin, &Style::setMargin>( + updateStyle<&Style::margin, &Style::setMargin>( node, scopedEnum(edge), value::ofAuto()); } @@ -264,12 +236,12 @@ YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { } void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) { - updateIndexedStyleProp<&Style::padding, &Style::setPadding>( + updateStyle<&Style::padding, &Style::setPadding>( node, scopedEnum(edge), value::points(points)); } void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) { - updateIndexedStyleProp<&Style::padding, &Style::setPadding>( + updateStyle<&Style::padding, &Style::setPadding>( node, scopedEnum(edge), value::percent(percent)); } @@ -281,7 +253,7 @@ void YGNodeStyleSetBorder( const YGNodeRef node, const YGEdge edge, const float border) { - updateIndexedStyleProp<&Style::border, &Style::setBorder>( + updateStyle<&Style::border, &Style::setBorder>( node, scopedEnum(edge), value::points(border)); } @@ -298,7 +270,7 @@ void YGNodeStyleSetGap( const YGNodeRef node, const YGGutter gutter, const float gapLength) { - updateIndexedStyleProp<&Style::gap, &Style::setGap>( + updateStyle<&Style::gap, &Style::setGap>( node, scopedEnum(gutter), value::points(gapLength)); } @@ -322,17 +294,17 @@ float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { } void YGNodeStyleSetWidth(YGNodeRef node, float points) { - updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( + updateStyle<&Style::dimension, &Style::setDimension>( node, Dimension::Width, value::points(points)); } void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { - updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( + updateStyle<&Style::dimension, &Style::setDimension>( node, Dimension::Width, value::percent(percent)); } void YGNodeStyleSetWidthAuto(YGNodeRef node) { - updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( + updateStyle<&Style::dimension, &Style::setDimension>( node, Dimension::Width, value::ofAuto()); } @@ -341,17 +313,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { } void YGNodeStyleSetHeight(YGNodeRef node, float points) { - updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( + updateStyle<&Style::dimension, &Style::setDimension>( node, Dimension::Height, value::points(points)); } void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { - updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( + updateStyle<&Style::dimension, &Style::setDimension>( node, Dimension::Height, value::percent(percent)); } void YGNodeStyleSetHeightAuto(YGNodeRef node) { - updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( + updateStyle<&Style::dimension, &Style::setDimension>( node, Dimension::Height, value::ofAuto()); } @@ -360,12 +332,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { } void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) { - updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>( + updateStyle<&Style::minDimension, &Style::setMinDimension>( node, Dimension::Width, value::points(minWidth)); } void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) { - updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>( + updateStyle<&Style::minDimension, &Style::setMinDimension>( node, Dimension::Width, value::percent(minWidth)); } @@ -374,14 +346,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { } void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) { - updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>( + updateStyle<&Style::minDimension, &Style::setMinDimension>( node, Dimension::Height, value::points(minHeight)); } void YGNodeStyleSetMinHeightPercent( const YGNodeRef node, const float minHeight) { - updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>( + updateStyle<&Style::minDimension, &Style::setMinDimension>( node, Dimension::Height, value::percent(minHeight)); } @@ -390,12 +362,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { } void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) { - updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>( + updateStyle<&Style::maxDimension, &Style::setMaxDimension>( node, Dimension::Width, value::points(maxWidth)); } void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) { - updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>( + updateStyle<&Style::maxDimension, &Style::setMaxDimension>( node, Dimension::Width, value::percent(maxWidth)); } @@ -404,14 +376,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { } void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) { - updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>( + updateStyle<&Style::maxDimension, &Style::setMaxDimension>( node, Dimension::Height, value::points(maxHeight)); } void YGNodeStyleSetMaxHeightPercent( const YGNodeRef node, const float maxHeight) { - updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>( + updateStyle<&Style::maxDimension, &Style::setMaxDimension>( node, Dimension::Height, value::percent(maxHeight)); } diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h index d01a1ed4ca6da2..0cb9fabc8ea8af 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h @@ -61,8 +61,8 @@ class YG_EXPORT Node : public ::YGNode { Direction direction) const; void useWebDefaults() { - style_.flexDirection() = FlexDirection::Row; - style_.alignContent() = Align::Stretch; + style_.setFlexDirection(FlexDirection::Row); + style_.setAlignContent(Align::Stretch); } template diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h index 09f5c3c1fb88ca..74736d27b9bec4 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h @@ -55,22 +55,9 @@ class YG_EXPORT Style { static constexpr float DefaultFlexShrink = 0.0f; static constexpr float WebDefaultFlexShrink = 1.0f; - template - struct BitfieldRef { - Style& style; - uint8_t offset; - operator T() const { - return getEnumData(style.flags, offset); - } - BitfieldRef& operator=(T x) { - setEnumData(style.flags, offset, x); - return *this; - } - }; - Style() { - alignContent() = Align::FlexStart; - alignItems() = Align::Stretch; + setAlignContent(Align::FlexStart); + setAlignItems(Align::Stretch); } ~Style() = default; @@ -99,7 +86,7 @@ class YG_EXPORT Style { static constexpr uint8_t displayOffset = overflowOffset + minimumBitCount(); - uint32_t flags = 0; + uint32_t flags_ = 0; FloatOptional flex_ = {}; FloatOptional flexGrow_ = {}; @@ -118,73 +105,73 @@ class YG_EXPORT Style { public: Direction direction() const { - return getEnumData(flags, directionOffset); + return getEnumData(flags_, directionOffset); } - BitfieldRef direction() { - return {*this, directionOffset}; + void setDirection(Direction value) { + setEnumData(flags_, directionOffset, value); } FlexDirection flexDirection() const { - return getEnumData(flags, flexdirectionOffset); + return getEnumData(flags_, flexdirectionOffset); } - BitfieldRef flexDirection() { - return {*this, flexdirectionOffset}; + void setFlexDirection(FlexDirection value) { + setEnumData(flags_, flexdirectionOffset, value); } Justify justifyContent() const { - return getEnumData(flags, justifyContentOffset); + return getEnumData(flags_, justifyContentOffset); } - BitfieldRef justifyContent() { - return {*this, justifyContentOffset}; + void setJustifyContent(Justify value) { + setEnumData(flags_, justifyContentOffset, value); } Align alignContent() const { - return getEnumData(flags, alignContentOffset); + return getEnumData(flags_, alignContentOffset); } - BitfieldRef alignContent() { - return {*this, alignContentOffset}; + void setAlignContent(Align value) { + setEnumData(flags_, alignContentOffset, value); } Align alignItems() const { - return getEnumData(flags, alignItemsOffset); + return getEnumData(flags_, alignItemsOffset); } - BitfieldRef alignItems() { - return {*this, alignItemsOffset}; + void setAlignItems(Align value) { + setEnumData(flags_, alignItemsOffset, value); } Align alignSelf() const { - return getEnumData(flags, alignSelfOffset); + return getEnumData(flags_, alignSelfOffset); } - BitfieldRef alignSelf() { - return {*this, alignSelfOffset}; + void setAlignSelf(Align value) { + setEnumData(flags_, alignSelfOffset, value); } PositionType positionType() const { - return getEnumData(flags, positionTypeOffset); + return getEnumData(flags_, positionTypeOffset); } - BitfieldRef positionType() { - return {*this, positionTypeOffset}; + void setPositionType(PositionType value) { + setEnumData(flags_, positionTypeOffset, value); } Wrap flexWrap() const { - return getEnumData(flags, flexWrapOffset); + return getEnumData(flags_, flexWrapOffset); } - BitfieldRef flexWrap() { - return {*this, flexWrapOffset}; + void setFlexWrap(Wrap value) { + setEnumData(flags_, flexWrapOffset, value); } Overflow overflow() const { - return getEnumData(flags, overflowOffset); + return getEnumData(flags_, overflowOffset); } - BitfieldRef overflow() { - return {*this, overflowOffset}; + void setOverflow(Overflow value) { + setEnumData(flags_, overflowOffset, value); } Display display() const { - return getEnumData(flags, displayOffset); + return getEnumData(flags_, displayOffset); } - BitfieldRef display() { - return {*this, displayOffset}; + void setDisplay(Display value) { + setEnumData(flags_, displayOffset, value); } FloatOptional flex() const { @@ -295,7 +282,7 @@ class YG_EXPORT Style { } bool operator==(const Style& other) const { - return flags == other.flags && inexactEquals(flex_, other.flex_) && + return flags_ == other.flags_ && inexactEquals(flex_, other.flex_) && inexactEquals(flexGrow_, other.flexGrow_) && inexactEquals(flexShrink_, other.flexShrink_) && inexactEquals(flexBasis_, other.flexBasis_) &&