From c12c1ce7f83bcc157c989b0bc662e82140802df9 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Sat, 25 Nov 2023 15:05:27 -0800 Subject: [PATCH 1/3] CompactValue -> LengthValue Differential Revision: https://internalfb.com/D51000389 fbshipit-source-id: fe2b4cbb82658931217b468967c24d582ecc978a --- .../Text/RCTParagraphComponentViewTests.mm | 40 ++++---- .../AndroidTextInputComponentDescriptor.h | 17 ++-- .../view/YogaLayoutableShadowNode.cpp | 56 +++++------ .../view/YogaLayoutableShadowNode.h | 2 - .../components/view/YogaStylableProps.cpp | 32 +++---- .../components/view/YogaStylableProps.h | 34 ++++--- .../renderer/components/view/conversions.h | 10 +- .../components/view/tests/LayoutTest.cpp | 40 ++++---- .../mounting/tests/StackingContextTest.cpp | 6 +- .../ReactCommon/yoga/yoga/YGNodeStyle.cpp | 96 ++++++++----------- .../yoga/yoga/algorithm/ResolveValue.h | 4 +- .../ReactCommon/yoga/yoga/node/Node.cpp | 8 +- .../ReactCommon/yoga/yoga/node/Node.h | 7 +- .../yoga/yoga/style/CompactValue.h | 18 +--- .../ReactCommon/yoga/yoga/style/Style.h | 73 ++++++++------ .../yoga/yoga/style/ValueFactories.h | 42 ++++++++ 16 files changed, 246 insertions(+), 239 deletions(-) create mode 100644 packages/react-native/ReactCommon/yoga/yoga/style/ValueFactories.h diff --git a/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm b/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm index 0f5dc648ded670..f6c1ba3c6ed15f 100644 --- a/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm +++ b/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm @@ -121,8 +121,8 @@ - (void)setUp auto &props = *sharedProps; props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}}; auto &yogaStyle = props.yogaStyle; - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(200)); return sharedProps; }) .children({ @@ -134,10 +134,10 @@ - (void)setUp props.accessible = true; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::of(0)); - yogaStyle.setPosition(YGEdgeTop, yoga::CompactValue::of(0)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(200)); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0)); + yogaStyle.setPosition(YGEdgeTop, yoga::value::points(0)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(200)); return sharedProps; }) .children({ @@ -214,10 +214,10 @@ - (void)setUp props.accessible = true; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::of(0)); - yogaStyle.setPosition(YGEdgeTop, yoga::CompactValue::of(30)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(50)); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0)); + yogaStyle.setPosition(YGEdgeTop, yoga::value::points(30)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50)); return sharedProps; }) .children({ @@ -258,10 +258,10 @@ - (void)setUp props.accessible = true; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::of(0)); - yogaStyle.setPosition(YGEdgeTop, yoga::CompactValue::of(90)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(50)); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0)); + yogaStyle.setPosition(YGEdgeTop, yoga::value::points(90)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50)); return sharedProps; }) .children({ @@ -418,8 +418,8 @@ - (void)testEntireParagraphLink auto &props = *sharedProps; props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}}; auto &yogaStyle = props.yogaStyle; - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(200)); return sharedProps; }) .children({ @@ -432,10 +432,10 @@ - (void)testEntireParagraphLink props.accessibilityTraits = AccessibilityTraits::Link; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::of(0)); - yogaStyle.setPosition(YGEdgeTop, yoga::CompactValue::of(0)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(20)); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0)); + yogaStyle.setPosition(YGEdgeTop, yoga::value::points(90)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(20)); return sharedProps; }) .children({ diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h index 553ba44389a8e1..0ff0f91ea30953 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h @@ -13,7 +13,6 @@ #include #include -#include #include @@ -106,27 +105,23 @@ class AndroidTextInputComponentDescriptor final !textInputProps.hasPaddingLeft && !textInputProps.hasPaddingHorizontal) { changedPadding = true; - style.setPadding( - YGEdgeStart, yoga::CompactValue::of(theme.start)); + style.setPadding(YGEdgeStart, yoga::value::points(theme.start)); } if (!textInputProps.hasPadding && !textInputProps.hasPaddingEnd && !textInputProps.hasPaddingRight && !textInputProps.hasPaddingHorizontal) { changedPadding = true; - style.setPadding( - YGEdgeEnd, yoga::CompactValue::of(theme.end)); + style.setPadding(YGEdgeEnd, yoga::value::points(theme.end)); } if (!textInputProps.hasPadding && !textInputProps.hasPaddingTop && !textInputProps.hasPaddingVertical) { changedPadding = true; - style.setPadding( - YGEdgeTop, yoga::CompactValue::of(theme.top)); + style.setPadding(YGEdgeTop, yoga::value::points(theme.top)); } if (!textInputProps.hasPadding && !textInputProps.hasPaddingBottom && !textInputProps.hasPaddingVertical) { changedPadding = true; - style.setPadding( - YGEdgeBottom, yoga::CompactValue::of(theme.bottom)); + style.setPadding(YGEdgeBottom, yoga::value::points(theme.bottom)); } // If the TextInput initially does not have paddingLeft or paddingStart, a @@ -137,12 +132,12 @@ class AndroidTextInputComponentDescriptor final if ((textInputProps.hasPadding || textInputProps.hasPaddingLeft || textInputProps.hasPaddingHorizontal) && !textInputProps.hasPaddingStart) { - style.setPadding(YGEdgeStart, yoga::CompactValue::ofUndefined()); + style.setPadding(YGEdgeStart, yoga::value::undefined()); } if ((textInputProps.hasPadding || textInputProps.hasPaddingRight || textInputProps.hasPaddingHorizontal) && !textInputProps.hasPaddingEnd) { - style.setPadding(YGEdgeEnd, yoga::CompactValue::ofUndefined()); + style.setPadding(YGEdgeEnd, yoga::value::undefined()); } // Note that this is expensive: on every adopt, we need to set the Yoga 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 ac2e89a618aaab..ed278ac98828ba 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -529,12 +529,8 @@ void YogaLayoutableShadowNode::setSize(Size size) const { ensureUnsealed(); auto style = yogaNode_.getStyle(); - style.setDimension( - yoga::Dimension::Width, - yoga::CompactValue::ofMaybe(size.width)); - style.setDimension( - yoga::Dimension::Height, - yoga::CompactValue::ofMaybe(size.height)); + style.setDimension(yoga::Dimension::Width, yoga::value::points(size.width)); + style.setDimension(yoga::Dimension::Height, yoga::value::points(size.height)); yogaNode_.setStyle(style); yogaNode_.setDirty(true); } @@ -544,23 +540,19 @@ void YogaLayoutableShadowNode::setPadding(RectangleEdges padding) const { auto style = yogaNode_.getStyle(); - auto leftPadding = yoga::CompactValue::ofMaybe(padding.left); - auto topPadding = yoga::CompactValue::ofMaybe(padding.top); - auto rightPadding = yoga::CompactValue::ofMaybe(padding.right); - auto bottomPadding = yoga::CompactValue::ofMaybe(padding.bottom); + auto leftPadding = yoga::value::points(padding.left); + auto topPadding = yoga::value::points(padding.top); + auto rightPadding = yoga::value::points(padding.right); + auto bottomPadding = yoga::value::points(padding.bottom); if (leftPadding != style.padding(YGEdgeLeft) || topPadding != style.padding(YGEdgeTop) || rightPadding != style.padding(YGEdgeRight) || bottomPadding != style.padding(YGEdgeBottom)) { - style.setPadding( - YGEdgeTop, yoga::CompactValue::ofMaybe(padding.top)); - style.setPadding( - YGEdgeLeft, yoga::CompactValue::ofMaybe(padding.left)); - style.setPadding( - YGEdgeRight, yoga::CompactValue::ofMaybe(padding.right)); - style.setPadding( - YGEdgeBottom, yoga::CompactValue::ofMaybe(padding.bottom)); + style.setPadding(YGEdgeTop, yoga::value::points(padding.top)); + style.setPadding(YGEdgeLeft, yoga::value::points(padding.left)); + style.setPadding(YGEdgeRight, yoga::value::points(padding.right)); + style.setPadding(YGEdgeBottom, yoga::value::points(padding.bottom)); yogaNode_.setStyle(style); yogaNode_.setDirty(true); } @@ -630,20 +622,16 @@ void YogaLayoutableShadowNode::layoutTree( auto ownerHeight = yogaFloatFromFloat(maximumSize.height); yogaStyle.setMaxDimension( - yoga::Dimension::Width, - yoga::CompactValue::ofMaybe(maximumSize.width)); + yoga::Dimension::Width, yoga::value::points(maximumSize.width)); yogaStyle.setMaxDimension( - yoga::Dimension::Height, - yoga::CompactValue::ofMaybe(maximumSize.height)); + yoga::Dimension::Height, yoga::value::points(maximumSize.height)); yogaStyle.setMinDimension( - yoga::Dimension::Width, - yoga::CompactValue::ofMaybe(minimumSize.width)); + yoga::Dimension::Width, yoga::value::points(minimumSize.width)); yogaStyle.setMinDimension( - yoga::Dimension::Height, - yoga::CompactValue::ofMaybe(minimumSize.height)); + yoga::Dimension::Height, yoga::value::points(minimumSize.height)); auto direction = yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection); @@ -887,32 +875,32 @@ void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps( if (yogaStyle.position(YGEdgeLeft).isDefined()) { yogaStyle.setPosition(YGEdgeStart, yogaStyle.position(YGEdgeLeft)); - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::ofUndefined()); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::undefined()); } if (yogaStyle.position(YGEdgeRight).isDefined()) { yogaStyle.setPosition(YGEdgeEnd, yogaStyle.position(YGEdgeRight)); - yogaStyle.setPosition(YGEdgeRight, yoga::CompactValue::ofUndefined()); + yogaStyle.setPosition(YGEdgeRight, yoga::value::undefined()); } if (yogaStyle.padding(YGEdgeLeft).isDefined()) { yogaStyle.setPadding(YGEdgeStart, yogaStyle.padding(YGEdgeLeft)); - yogaStyle.setPadding(YGEdgeLeft, yoga::CompactValue::ofUndefined()); + yogaStyle.setPadding(YGEdgeLeft, yoga::value::undefined()); } if (yogaStyle.padding(YGEdgeRight).isDefined()) { yogaStyle.setPadding(YGEdgeEnd, yogaStyle.padding(YGEdgeRight)); - yogaStyle.setPadding(YGEdgeRight, yoga::CompactValue::ofUndefined()); + yogaStyle.setPadding(YGEdgeRight, yoga::value::undefined()); } if (yogaStyle.margin(YGEdgeLeft).isDefined()) { yogaStyle.setMargin(YGEdgeStart, yogaStyle.margin(YGEdgeLeft)); - yogaStyle.setMargin(YGEdgeLeft, yoga::CompactValue::ofUndefined()); + yogaStyle.setMargin(YGEdgeLeft, yoga::value::undefined()); } if (yogaStyle.margin(YGEdgeRight).isDefined()) { yogaStyle.setMargin(YGEdgeEnd, yogaStyle.margin(YGEdgeRight)); - yogaStyle.setMargin(YGEdgeRight, yoga::CompactValue::ofUndefined()); + yogaStyle.setMargin(YGEdgeRight, yoga::value::undefined()); } shadowNode.yogaNode_.setStyle(yogaStyle); @@ -967,12 +955,12 @@ void YogaLayoutableShadowNode::swapLeftAndRightInViewProps( if (props.yogaStyle.border(YGEdgeLeft).isDefined()) { props.yogaStyle.setBorder(YGEdgeStart, props.yogaStyle.border(YGEdgeLeft)); - props.yogaStyle.setBorder(YGEdgeLeft, yoga::CompactValue::ofUndefined()); + props.yogaStyle.setBorder(YGEdgeLeft, yoga::value::undefined()); } if (props.yogaStyle.border(YGEdgeRight).isDefined()) { props.yogaStyle.setBorder(YGEdgeEnd, props.yogaStyle.border(YGEdgeRight)); - props.yogaStyle.setBorder(YGEdgeRight, yoga::CompactValue::ofUndefined()); + props.yogaStyle.setBorder(YGEdgeRight, yoga::value::undefined()); } } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h index 0d31fb56eae31c..f4a9ba794362a8 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h @@ -22,8 +22,6 @@ namespace facebook::react { class YogaLayoutableShadowNode : public LayoutableShadowNode { - using CompactValue = facebook::yoga::CompactValue; - public: using Shared = std::shared_ptr; using ListOfShared = std::vector; 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 39e32c9fa93283..ce472496bedebe 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp @@ -417,98 +417,98 @@ void YogaStylableProps::convertRawPropAliases( rawProps, "insetBlockEnd", sourceProps.insetBlockEnd, - CompactValue::ofUndefined()); + yoga::value::undefined()); insetBlockStart = convertRawProp( context, rawProps, "insetBlockStart", sourceProps.insetBlockStart, - CompactValue::ofUndefined()); + yoga::value::undefined()); insetInlineEnd = convertRawProp( context, rawProps, "insetInlineEnd", sourceProps.insetInlineEnd, - CompactValue::ofUndefined()); + yoga::value::undefined()); insetInlineStart = convertRawProp( context, rawProps, "insetInlineStart", sourceProps.insetInlineStart, - CompactValue::ofUndefined()); + yoga::value::undefined()); marginInline = convertRawProp( context, rawProps, "marginInline", sourceProps.marginInline, - CompactValue::ofUndefined()); + yoga::value::undefined()); marginInlineStart = convertRawProp( context, rawProps, "marginInlineStart", sourceProps.marginInlineStart, - CompactValue::ofUndefined()); + yoga::value::undefined()); marginInlineEnd = convertRawProp( context, rawProps, "marginInlineEnd", sourceProps.marginInlineEnd, - CompactValue::ofUndefined()); + yoga::value::undefined()); marginBlock = convertRawProp( context, rawProps, "marginBlock", sourceProps.marginBlock, - CompactValue::ofUndefined()); + yoga::value::undefined()); marginBlockStart = convertRawProp( context, rawProps, "marginBlockStart", sourceProps.marginBlockStart, - CompactValue::ofUndefined()); + yoga::value::undefined()); marginBlockEnd = convertRawProp( context, rawProps, "marginBlockEnd", sourceProps.marginBlockEnd, - CompactValue::ofUndefined()); + yoga::value::undefined()); paddingInline = convertRawProp( context, rawProps, "paddingInline", sourceProps.paddingInline, - CompactValue::ofUndefined()); + yoga::value::undefined()); paddingInlineStart = convertRawProp( context, rawProps, "paddingInlineStart", sourceProps.paddingInlineStart, - CompactValue::ofUndefined()); + yoga::value::undefined()); paddingInlineEnd = convertRawProp( context, rawProps, "paddingInlineEnd", sourceProps.paddingInlineEnd, - CompactValue::ofUndefined()); + yoga::value::undefined()); paddingBlock = convertRawProp( context, rawProps, "paddingBlock", sourceProps.paddingBlock, - CompactValue::ofUndefined()); + yoga::value::undefined()); paddingBlockStart = convertRawProp( context, rawProps, "paddingBlockStart", sourceProps.paddingBlockStart, - CompactValue::ofUndefined()); + yoga::value::undefined()); paddingBlockEnd = convertRawProp( context, rawProps, "paddingBlockEnd", sourceProps.paddingBlockEnd, - CompactValue::ofUndefined()); + yoga::value::undefined()); } } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h index 9114aa530e7ae8..165209183725ff 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h @@ -16,8 +16,6 @@ namespace facebook::react { class YogaStylableProps : public Props { - using CompactValue = facebook::yoga::CompactValue; - public: YogaStylableProps() = default; YogaStylableProps( @@ -41,30 +39,30 @@ class YogaStylableProps : public Props { // Duplicates of existing properties with different names, taking // precedence. E.g. "marginBlock" instead of "marginVertical" - CompactValue insetInlineStart; - CompactValue insetInlineEnd; + yoga::Style::Length insetInlineStart; + yoga::Style::Length insetInlineEnd; - CompactValue marginInline; - CompactValue marginInlineStart; - CompactValue marginInlineEnd; - CompactValue marginBlock; + yoga::Style::Length marginInline; + yoga::Style::Length marginInlineStart; + yoga::Style::Length marginInlineEnd; + yoga::Style::Length marginBlock; - CompactValue paddingInline; - CompactValue paddingInlineStart; - CompactValue paddingInlineEnd; - CompactValue paddingBlock; + yoga::Style::Length paddingInline; + yoga::Style::Length paddingInlineStart; + yoga::Style::Length paddingInlineEnd; + yoga::Style::Length paddingBlock; // BlockEnd/BlockStart map to top/bottom (no writing mode), but we preserve // Yoga's precedence and prefer specific edges (e.g. top) to ones which are // flow relative (e.g. blockStart). - CompactValue insetBlockStart; - CompactValue insetBlockEnd; + yoga::Style::Length insetBlockStart; + yoga::Style::Length insetBlockEnd; - CompactValue marginBlockStart; - CompactValue marginBlockEnd; + yoga::Style::Length marginBlockStart; + yoga::Style::Length marginBlockEnd; - CompactValue paddingBlockStart; - CompactValue paddingBlockEnd; + yoga::Style::Length paddingBlockStart; + yoga::Style::Length paddingBlockEnd; #if RN_DEBUG_STRING_CONVERTIBLE diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h index 2a82a16e85a1ce..58a898fb1027d1 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h @@ -395,9 +395,9 @@ inline void fromRawValue( inline void fromRawValue( const PropsParserContext& context, const RawValue& value, - yoga::CompactValue& result) { + yoga::Style::Length& result) { if (value.hasType()) { - result = yoga::CompactValue::ofMaybe((float)value); + result = yoga::value::points((float)value); return; } else if (value.hasType()) { const auto stringValue = (std::string)value; @@ -409,13 +409,13 @@ inline void fromRawValue( auto tryValue = folly::tryTo( std::string_view(stringValue).substr(0, stringValue.length() - 1)); if (tryValue.hasValue()) { - result = YGValue{tryValue.value(), YGUnitPercent}; + result = yoga::value::percent(tryValue.value()); return; } } else { auto tryValue = folly::tryTo(stringValue); if (tryValue.hasValue()) { - result = YGValue{tryValue.value(), YGUnitPoint}; + result = yoga::value::points(tryValue.value()); return; } } @@ -428,7 +428,7 @@ inline void fromRawValue( const PropsParserContext& context, const RawValue& value, YGValue& result) { - yoga::CompactValue ygValue{}; + yoga::Style::Length ygValue{}; fromRawValue(context, value, ygValue); result = ygValue; } 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 b0be9bc7f1e32d..5e44e2d5044293 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 @@ -77,8 +77,8 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; props.layoutConstraints = LayoutConstraints{{0,0}, {500, 500}}; auto &yogaStyle = props.yogaStyle; - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(200)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(200)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(200)); return sharedProps; }) .children({ @@ -90,8 +90,8 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(50)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(50)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(50)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50)); return sharedProps; }) .children({ @@ -103,10 +103,10 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::of(10)); - yogaStyle.setPosition(YGEdgeTop, yoga::CompactValue::of(10)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(30)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(90)); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(10)); + yogaStyle.setPosition(YGEdgeTop, yoga::value::points(10)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(30)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(90)); if (testCase == TRANSFORM_SCALE) { props.transform = props.transform * Transform::Scale(2, 2, 1); @@ -136,10 +136,10 @@ class LayoutTest : public ::testing::Test { } yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::of(10)); - yogaStyle.setPosition(YGEdgeTop, yoga::CompactValue::of(10)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(110)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(20)); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(10)); + yogaStyle.setPosition(YGEdgeTop, yoga::value::points(10)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(110)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(20)); return sharedProps; }) .children({ @@ -151,10 +151,10 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::of(70)); - yogaStyle.setPosition(YGEdgeTop, yoga::CompactValue::of(-50)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(30)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(60)); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(70)); + yogaStyle.setPosition(YGEdgeTop, yoga::value::points(-50)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(30)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(60)); return sharedProps; }) }), @@ -166,10 +166,10 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::CompactValue::of(-60)); - yogaStyle.setPosition(YGEdgeTop, yoga::CompactValue::of(50)); - yogaStyle.setDimension(yoga::Dimension::Width, yoga::CompactValue::of(70)); - yogaStyle.setDimension(yoga::Dimension::Height, yoga::CompactValue::of(20)); + yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(-60)); + yogaStyle.setPosition(YGEdgeTop, yoga::value::points(50)); + yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(70)); + yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(20)); return sharedProps; }) }) 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 ab06e2f8ccce76..ae64dd3393dc34 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp @@ -251,8 +251,8 @@ TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) { mutateViewShadowNodeProps_(nodeAA_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.setPadding(YGEdgeAll, yoga::CompactValue::of(42)); - yogaStyle.setMargin(YGEdgeAll, yoga::CompactValue::of(42)); + yogaStyle.setPadding(YGEdgeAll, yoga::value::points(42)); + yogaStyle.setMargin(YGEdgeAll, yoga::value::points(42)); yogaStyle.positionType() = yoga::PositionType::Absolute; props.shadowRadius = 42; props.shadowOffset = Size{42, 42}; @@ -262,7 +262,7 @@ TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) { mutateViewShadowNodeProps_(nodeBA_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; props.zIndex = 42; - yogaStyle.setMargin(YGEdgeAll, yoga::CompactValue::of(42)); + yogaStyle.setMargin(YGEdgeAll, yoga::value::points(42)); props.shadowColor = clearColor(); props.shadowOpacity = 0.42; }); diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp index 38a55f2c8c8a31..6767e5e8e31969 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp @@ -26,22 +26,22 @@ void updateStyle( } } -template -void updateStyle(YGNodeRef node, Ref (Style::*prop)(), T value) { +template +void updateStyle(YGNodeRef node, Ref (Style::*prop)(), ValueT value) { updateStyle( resolveRef(node), value, - [prop](Style& s, T x) { return (s.*prop)() != x; }, - [prop](Style& s, T x) { (s.*prop)() = x; }); + [prop](Style& s, ValueT x) { return (s.*prop)() != x; }, + [prop](Style& s, ValueT x) { (s.*prop)() = x; }); } -template -void updateIndexedStyleProp(YGNodeRef node, IdxT idx, CompactValue value) { +template +void updateIndexedStyleProp(YGNodeRef node, IdxT idx, ValueT value) { updateStyle( resolveRef(node), value, - [idx](Style& s, CompactValue x) { return (s.*GetterT)(idx) != x; }, - [idx](Style& s, CompactValue x) { (s.*SetterT)(idx, x); }); + [idx](Style& s, ValueT x) { return (s.*GetterT)(idx) != x; }, + [idx](Style& s, ValueT x) { (s.*SetterT)(idx, x); }); } } // namespace @@ -198,20 +198,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) { } void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { - auto value = CompactValue::ofMaybe(flexBasis); - updateStyle(node, &Style::flexBasis, value); + updateStyle( + node, &Style::flexBasis, value::points(flexBasis)); } void YGNodeStyleSetFlexBasisPercent( const YGNodeRef node, const float flexBasisPercent) { - auto value = CompactValue::ofMaybe(flexBasisPercent); - updateStyle(node, &Style::flexBasis, value); + updateStyle( + node, &Style::flexBasis, value::percent(flexBasisPercent)); } void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { - updateStyle( - node, &Style::flexBasis, CompactValue::ofAuto()); + updateStyle(node, &Style::flexBasis, value::ofAuto()); } YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { @@ -223,15 +222,13 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { } void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) { - auto value = CompactValue::ofMaybe(points); updateIndexedStyleProp<&Style::position, &Style::setPosition>( - node, edge, value); + node, edge, value::points(points)); } void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) { - auto value = CompactValue::ofMaybe(percent); updateIndexedStyleProp<&Style::position, &Style::setPosition>( - node, edge, value); + node, edge, value::percent(percent)); } YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { @@ -239,18 +236,18 @@ YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { } void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) { - auto value = CompactValue::ofMaybe(points); - updateIndexedStyleProp<&Style::margin, &Style::setMargin>(node, edge, value); + updateIndexedStyleProp<&Style::margin, &Style::setMargin>( + node, edge, value::points(points)); } void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) { - auto value = CompactValue::ofMaybe(percent); - updateIndexedStyleProp<&Style::margin, &Style::setMargin>(node, edge, value); + updateIndexedStyleProp<&Style::margin, &Style::setMargin>( + node, edge, value::percent(percent)); } void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { updateIndexedStyleProp<&Style::margin, &Style::setMargin>( - node, edge, CompactValue::ofAuto()); + node, edge, value::ofAuto()); } YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { @@ -258,15 +255,13 @@ YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { } void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) { - auto value = CompactValue::ofMaybe(points); updateIndexedStyleProp<&Style::padding, &Style::setPadding>( - node, edge, value); + node, edge, value::points(points)); } void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) { - auto value = CompactValue::ofMaybe(percent); updateIndexedStyleProp<&Style::padding, &Style::setPadding>( - node, edge, value); + node, edge, value::percent(percent)); } YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { @@ -277,8 +272,8 @@ void YGNodeStyleSetBorder( const YGNodeRef node, const YGEdge edge, const float border) { - auto value = CompactValue::ofMaybe(border); - updateIndexedStyleProp<&Style::border, &Style::setBorder>(node, edge, value); + updateIndexedStyleProp<&Style::border, &Style::setBorder>( + node, edge, value::points(border)); } float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) { @@ -294,9 +289,8 @@ void YGNodeStyleSetGap( const YGNodeRef node, const YGGutter gutter, const float gapLength) { - auto length = CompactValue::ofMaybe(gapLength); updateIndexedStyleProp<&Style::gap, &Style::setGap>( - node, scopedEnum(gutter), length); + node, scopedEnum(gutter), value::points(gapLength)); } float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { @@ -319,20 +313,18 @@ float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { } void YGNodeStyleSetWidth(YGNodeRef node, float points) { - auto value = CompactValue::ofMaybe(points); updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, value); + node, Dimension::Width, value::points(points)); } void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { - auto value = CompactValue::ofMaybe(percent); updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, value); + node, Dimension::Width, value::percent(percent)); } void YGNodeStyleSetWidthAuto(YGNodeRef node) { updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( - node, Dimension::Width, CompactValue::ofAuto()); + node, Dimension::Width, value::ofAuto()); } YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { @@ -340,20 +332,18 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { } void YGNodeStyleSetHeight(YGNodeRef node, float points) { - auto value = CompactValue::ofMaybe(points); updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, value); + node, Dimension::Height, value::points(points)); } void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { - auto value = CompactValue::ofMaybe(percent); updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, value); + node, Dimension::Height, value::percent(percent)); } void YGNodeStyleSetHeightAuto(YGNodeRef node) { updateIndexedStyleProp<&Style::dimension, &Style::setDimension>( - node, Dimension::Height, CompactValue::ofAuto()); + node, Dimension::Height, value::ofAuto()); } YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { @@ -361,15 +351,13 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { } void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) { - auto value = CompactValue::ofMaybe(minWidth); updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Width, value); + node, Dimension::Width, value::points(minWidth)); } void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) { - auto value = CompactValue::ofMaybe(minWidth); updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Width, value); + node, Dimension::Width, value::percent(minWidth)); } YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { @@ -377,17 +365,15 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { } void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) { - auto value = CompactValue::ofMaybe(minHeight); updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Height, value); + node, Dimension::Height, value::points(minHeight)); } void YGNodeStyleSetMinHeightPercent( const YGNodeRef node, const float minHeight) { - auto value = CompactValue::ofMaybe(minHeight); updateIndexedStyleProp<&Style::minDimension, &Style::setMinDimension>( - node, Dimension::Height, value); + node, Dimension::Height, value::percent(minHeight)); } YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { @@ -395,15 +381,13 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { } void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) { - auto value = CompactValue::ofMaybe(maxWidth); updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Width, value); + node, Dimension::Width, value::points(maxWidth)); } void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) { - auto value = CompactValue::ofMaybe(maxWidth); updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Width, value); + node, Dimension::Width, value::percent(maxWidth)); } YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { @@ -411,17 +395,15 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { } void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) { - auto value = CompactValue::ofMaybe(maxHeight); updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Height, value); + node, Dimension::Height, value::points(maxHeight)); } void YGNodeStyleSetMaxHeightPercent( const YGNodeRef node, const float maxHeight) { - auto value = CompactValue::ofMaybe(maxHeight); updateIndexedStyleProp<&Style::maxDimension, &Style::setMaxDimension>( - node, Dimension::Height, value); + node, Dimension::Height, value::percent(maxHeight)); } YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/ResolveValue.h b/packages/react-native/ReactCommon/yoga/yoga/algorithm/ResolveValue.h index 4e03d0c50d4d9a..a2d650b237a0cb 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/ResolveValue.h +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/ResolveValue.h @@ -10,7 +10,7 @@ #include #include -#include +#include namespace facebook::yoga { @@ -25,7 +25,7 @@ inline FloatOptional resolveValue(const YGValue value, const float ownerSize) { } } -inline FloatOptional resolveValue(CompactValue value, float ownerSize) { +inline FloatOptional resolveValue(Style::Length value, float ownerSize) { return resolveValue((YGValue)value, ownerSize); } diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp index e5100ee2815137..0781b8e63ab44b 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp @@ -58,7 +58,7 @@ void Node::print() { // TODO: Edge value resolution should be moved to `yoga::Style` template -CompactValue Node::computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const { +Style::Length Node::computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const { if ((style_.*Field)(rowEdge).isDefined()) { return (style_.*Field)(rowEdge); } else if ((style_.*Field)(edge).isDefined()) { @@ -72,7 +72,7 @@ CompactValue Node::computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const { // TODO: Edge value resolution should be moved to `yoga::Style` template -CompactValue Node::computeEdgeValueForColumn(YGEdge edge) const { +Style::Length Node::computeEdgeValueForColumn(YGEdge edge) const { if ((style_.*Field)(edge).isDefined()) { return (style_.*Field)(edge); } else if ((style_.*Field)(YGEdgeVertical).isDefined()) { @@ -497,8 +497,8 @@ void Node::setLayoutHadOverflow(bool hadOverflow) { layout_.setHadOverflow(hadOverflow); } -void Node::setLayoutDimension(float dimensionValue, Dimension dimension) { - layout_.setDimension(dimension, dimensionValue); +void Node::setLayoutDimension(float LengthValue, Dimension dimension) { + layout_.setDimension(dimension, LengthValue); } // If both left and right are defined, then use left. Otherwise return +left or diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h index 9fefcf15aa0b99..1c9acbbe86d23d 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h @@ -20,7 +20,6 @@ #include #include #include -#include #include // Tag struct used to form the opaque YGNodeRef for the public C API @@ -66,10 +65,10 @@ class YG_EXPORT Node : public ::YGNode { } template - CompactValue computeEdgeValueForColumn(YGEdge edge) const; + Style::Length computeEdgeValueForColumn(YGEdge edge) const; template - CompactValue computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const; + Style::Length computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const; // DANGER DANGER DANGER! // If the node assigned to has children, we'd either have to deallocate @@ -327,7 +326,7 @@ class YG_EXPORT Node : public ::YGNode { uint32_t computedFlexBasisGeneration); void setLayoutMeasuredDimension(float measuredDimension, Dimension dimension); void setLayoutHadOverflow(bool hadOverflow); - void setLayoutDimension(float dimensionValue, Dimension dimension); + void setLayoutDimension(float LengthValue, Dimension dimension); void setLayoutDirection(Direction direction); void setLayoutMargin(float margin, YGEdge edge); void setLayoutBorder(float border, YGEdge edge); diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/CompactValue.h b/packages/react-native/ReactCommon/yoga/yoga/style/CompactValue.h index a6ca3f1283e175..c32dd9276f1ede 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/CompactValue.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/CompactValue.h @@ -52,6 +52,10 @@ class YG_EXPORT CompactValue { template static CompactValue of(float value) noexcept { + if (yoga::isUndefined(value) || std::isinf(value)) { + return ofUndefined(); + } + if (value == 0.0f || (value < LOWER_BOUND && value > -LOWER_BOUND)) { constexpr auto zero = Unit == YGUnitPercent ? ZERO_BITS_PERCENT : ZERO_BITS_POINT; @@ -71,16 +75,6 @@ class YG_EXPORT CompactValue { return {data}; } - template - static CompactValue ofMaybe(float value) noexcept { - return std::isnan(value) || std::isinf(value) ? ofUndefined() - : of(value); - } - - static constexpr CompactValue ofZero() noexcept { - return CompactValue{ZERO_BITS_POINT}; - } - static constexpr CompactValue ofUndefined() noexcept { return CompactValue{}; } @@ -168,10 +162,6 @@ template <> CompactValue CompactValue::of(float) noexcept = delete; template <> CompactValue CompactValue::of(float) noexcept = delete; -template <> -CompactValue CompactValue::ofMaybe(float) noexcept = delete; -template <> -CompactValue CompactValue::ofMaybe(float) noexcept = delete; constexpr bool operator==(CompactValue a, CompactValue b) noexcept { return a.repr_ == b.repr_; diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h index d7dbf2f1886b05..835632edd598dc 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h @@ -28,18 +28,29 @@ #include #include #include +#include namespace facebook::yoga { class YG_EXPORT Style { - template - using Values = std::array()>; - - using Dimensions = Values; - using Edges = Values; - using Gutters = Values; - public: + /** + * Style::Length represents a CSS Value which may be one of: + * 1. Undefined + * 2. A keyword (e.g. auto) + * 3. A CSS value: + * a. value (e.g. 10px) + * b. value of a reference + * 4. (soon) A math function which returns a value + * + * References: + * 1. https://www.w3.org/TR/css-values-4/#lengths + * 2. https://www.w3.org/TR/css-values-4/#percentage-value + * 3. https://www.w3.org/TR/css-values-4/#mixed-percentages + * 4. https://www.w3.org/TR/css-values-4/#math + */ + using Length = CompactValue; + static constexpr float DefaultFlexGrow = 0.0f; static constexpr float DefaultFlexShrink = 0.0f; static constexpr float WebDefaultFlexShrink = 1.0f; @@ -76,6 +87,10 @@ class YG_EXPORT Style { ~Style() = default; private: + using Dimensions = std::array()>; + using Edges = std::array()>; + using Gutters = std::array()>; + static constexpr uint8_t directionOffset = 0; static constexpr uint8_t flexdirectionOffset = directionOffset + minimumBitCount(); @@ -101,13 +116,13 @@ class YG_EXPORT Style { FloatOptional flex_ = {}; FloatOptional flexGrow_ = {}; FloatOptional flexShrink_ = {}; - CompactValue flexBasis_ = CompactValue::ofAuto(); + Style::Length flexBasis_ = value::ofAuto(); Edges margin_ = {}; Edges position_ = {}; Edges padding_ = {}; Edges border_ = {}; Gutters gap_ = {}; - Dimensions dimensions_{CompactValue::ofAuto(), CompactValue::ofAuto()}; + Dimensions dimensions_{value::ofAuto(), value::ofAuto()}; Dimensions minDimensions_ = {}; Dimensions maxDimensions_ = {}; // Yoga specific properties, not compatible with flexbox specification @@ -205,66 +220,66 @@ class YG_EXPORT Style { return {*this}; } - CompactValue flexBasis() const { + Style::Length flexBasis() const { return flexBasis_; } - Ref flexBasis() { + Ref flexBasis() { return {*this}; } - CompactValue margin(YGEdge edge) const { + Style::Length margin(YGEdge edge) const { return margin_[edge]; } - void setMargin(YGEdge edge, CompactValue value) { + void setMargin(YGEdge edge, Style::Length value) { margin_[edge] = value; } - CompactValue position(YGEdge edge) const { + Style::Length position(YGEdge edge) const { return position_[edge]; } - void setPosition(YGEdge edge, CompactValue value) { + void setPosition(YGEdge edge, Style::Length value) { position_[edge] = value; } - CompactValue padding(YGEdge edge) const { + Style::Length padding(YGEdge edge) const { return padding_[edge]; } - void setPadding(YGEdge edge, CompactValue value) { + void setPadding(YGEdge edge, Style::Length value) { padding_[edge] = value; } - CompactValue border(YGEdge edge) const { + Style::Length border(YGEdge edge) const { return border_[edge]; } - void setBorder(YGEdge edge, CompactValue value) { + void setBorder(YGEdge edge, Style::Length value) { border_[edge] = value; } - CompactValue gap(Gutter gutter) const { + Style::Length gap(Gutter gutter) const { return gap_[yoga::to_underlying(gutter)]; } - void setGap(Gutter gutter, CompactValue value) { + void setGap(Gutter gutter, Style::Length value) { gap_[yoga::to_underlying(gutter)] = value; } - CompactValue dimension(Dimension axis) const { + Style::Length dimension(Dimension axis) const { return dimensions_[yoga::to_underlying(axis)]; } - void setDimension(Dimension axis, CompactValue value) { + void setDimension(Dimension axis, Style::Length value) { dimensions_[yoga::to_underlying(axis)] = value; } - CompactValue minDimension(Dimension axis) const { + Style::Length minDimension(Dimension axis) const { return minDimensions_[yoga::to_underlying(axis)]; } - void setMinDimension(Dimension axis, CompactValue value) { + void setMinDimension(Dimension axis, Style::Length value) { minDimensions_[yoga::to_underlying(axis)] = value; } - CompactValue maxDimension(Dimension axis) const { + Style::Length maxDimension(Dimension axis) const { return maxDimensions_[yoga::to_underlying(axis)]; } - void setMaxDimension(Dimension axis, CompactValue value) { + void setMaxDimension(Dimension axis, Style::Length value) { maxDimensions_[yoga::to_underlying(axis)] = value; } @@ -276,7 +291,7 @@ class YG_EXPORT Style { return {*this}; } - CompactValue resolveColumnGap() const { + Length resolveColumnGap() const { if (gap_[yoga::to_underlying(Gutter::Column)].isDefined()) { return gap_[yoga::to_underlying(Gutter::Column)]; } else { @@ -284,7 +299,7 @@ class YG_EXPORT Style { } } - CompactValue resolveRowGap() const { + Style::Length resolveRowGap() const { if (gap_[yoga::to_underlying(Gutter::Row)].isDefined()) { return gap_[yoga::to_underlying(Gutter::Row)]; } else { diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/ValueFactories.h b/packages/react-native/ReactCommon/yoga/yoga/style/ValueFactories.h new file mode 100644 index 00000000000000..65486347b0a52c --- /dev/null +++ b/packages/react-native/ReactCommon/yoga/yoga/style/ValueFactories.h @@ -0,0 +1,42 @@ +/* + * 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 + +namespace facebook::yoga::value { + +/** + * Canonical unit (one YGUnitPoint) + */ +inline CompactValue points(float value) { + return CompactValue::of(value); +} + +/** + * Percent of reference + */ +inline CompactValue percent(float value) { + return CompactValue::of(value); +} + +/** + * "auto" keyword + */ +inline CompactValue ofAuto() { + return CompactValue::ofAuto(); +} + +/** + * Undefined + */ +inline CompactValue undefined() { + return CompactValue::ofUndefined(); +} + +} // namespace facebook::yoga::value From 4899ee6034795bf84767b7aff04907797b3da67f Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Sat, 25 Nov 2023 15:05:27 -0800 Subject: [PATCH 2/3] Use CSS terminology for box sizing Summary: Yoga passes `MeasureMode`/`YGMeasureMode` to express constraints in how a box should be measured, given definite or indefinite available space. This is modeled after Android [MeasureSpec](https://developer.android.com/reference/android/view/View.MeasureSpec), with a table above `calculateLayoutImpl()` explaining the CSS terms they map to. This can be confusing when flipping between the spec, and code. This switches internal usages to the CSS terms, but leaves around `YGMeasureMode` since it is the public API passed to measure functions. Differential Revision: D51068417 fbshipit-source-id: 2a4ebd327bb63a97840b987e817e18587b4c06d8 --- .../ReactCommon/yoga/yoga/YGNode.cpp | 8 +- .../ReactCommon/yoga/yoga/YGNode.h | 13 + .../ReactCommon/yoga/yoga/algorithm/Cache.cpp | 70 +-- .../ReactCommon/yoga/yoga/algorithm/Cache.h | 10 +- .../yoga/yoga/algorithm/CalculateLayout.cpp | 428 +++++++++--------- .../yoga/yoga/algorithm/SizingMode.h | 73 +++ .../yoga/yoga/debug/AssertFatal.cpp | 2 + .../ReactCommon/yoga/yoga/debug/AssertFatal.h | 5 +- .../yoga/yoga/node/CachedMeasurement.h | 10 +- 9 files changed, 351 insertions(+), 268 deletions(-) create mode 100644 packages/react-native/ReactCommon/yoga/yoga/algorithm/SizingMode.h diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNode.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGNode.cpp index 38d8f319161cc8..50cfd98f20af3e 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNode.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNode.cpp @@ -351,13 +351,13 @@ bool YGNodeCanUseCachedMeasurement( float marginColumn, YGConfigRef config) { return yoga::canUseCachedMeasurement( - scopedEnum(widthMode), + sizingMode(scopedEnum(widthMode)), availableWidth, - scopedEnum(heightMode), + sizingMode(scopedEnum(heightMode)), availableHeight, - scopedEnum(lastWidthMode), + sizingMode(scopedEnum(lastWidthMode)), lastAvailableWidth, - scopedEnum(lastHeightMode), + sizingMode(scopedEnum(lastHeightMode)), lastAvailableHeight, lastComputedWidth, lastComputedHeight, diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNode.h b/packages/react-native/ReactCommon/yoga/yoga/YGNode.h index 61a2bc4ea5f7f5..b267cde14808d7 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNode.h +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNode.h @@ -186,6 +186,19 @@ typedef struct YGSize { } YGSize; /** + * Returns the computed dimensions of the node, following the contraints of + * `widthMode` and `heightMode`: + * + * YGMeasureModeUndefined: The parent has not imposed any constraint on the + * child. It can be whatever size it wants. + * + * YGMeasureModeAtMost: The child can be as large as it wants up to the + * specified size. + * + * YGMeasureModeExactly: The parent has determined an exact size for the + * child. The child is going to be given those bounds regardless of how big it + * wants to be. + * * @returns the size of the leaf node, measured under the given contraints. */ typedef YGSize (*YGMeasureFunc)( diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Cache.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Cache.cpp index 7496e873e04ce4..9154fc6ce9cc87 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Cache.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Cache.cpp @@ -12,51 +12,52 @@ namespace facebook::yoga { static inline bool sizeIsExactAndMatchesOldMeasuredSize( - MeasureMode sizeMode, + SizingMode sizeMode, float size, float lastComputedSize) { - return sizeMode == MeasureMode::Exactly && + return sizeMode == SizingMode::StretchFit && yoga::inexactEquals(size, lastComputedSize); } -static inline bool oldSizeIsUnspecifiedAndStillFits( - MeasureMode sizeMode, +static inline bool oldSizeIsMaxContentAndStillFits( + SizingMode sizeMode, float size, - MeasureMode lastSizeMode, + SizingMode lastSizeMode, float lastComputedSize) { - return sizeMode == MeasureMode::AtMost && - lastSizeMode == MeasureMode::Undefined && + return sizeMode == SizingMode::FitContent && + lastSizeMode == SizingMode::MaxContent && (size >= lastComputedSize || yoga::inexactEquals(size, lastComputedSize)); } -static inline bool newMeasureSizeIsStricterAndStillValid( - MeasureMode sizeMode, +static inline bool newSizeIsStricterAndStillValid( + SizingMode sizeMode, float size, - MeasureMode lastSizeMode, + SizingMode lastSizeMode, float lastSize, float lastComputedSize) { - return lastSizeMode == MeasureMode::AtMost && - sizeMode == MeasureMode::AtMost && !std::isnan(lastSize) && - !std::isnan(size) && !std::isnan(lastComputedSize) && lastSize > size && + return lastSizeMode == SizingMode::FitContent && + sizeMode == SizingMode::FitContent && yoga::isDefined(lastSize) && + yoga::isDefined(size) && yoga::isDefined(lastComputedSize) && + lastSize > size && (lastComputedSize <= size || yoga::inexactEquals(size, lastComputedSize)); } bool canUseCachedMeasurement( - const MeasureMode widthMode, + const SizingMode widthMode, const float availableWidth, - const MeasureMode heightMode, + const SizingMode heightMode, const float availableHeight, - const MeasureMode lastWidthMode, + const SizingMode lastWidthMode, const float lastAvailableWidth, - const MeasureMode lastHeightMode, + const SizingMode lastHeightMode, const float lastAvailableHeight, const float lastComputedWidth, const float lastComputedHeight, const float marginRow, const float marginColumn, const yoga::Config* const config) { - if ((!std::isnan(lastComputedHeight) && lastComputedHeight < 0) || - (!std::isnan(lastComputedWidth) && lastComputedWidth < 0)) { + if ((yoga::isDefined(lastComputedHeight) && lastComputedHeight < 0) || + ((yoga::isDefined(lastComputedWidth)) && lastComputedWidth < 0)) { return false; } @@ -87,33 +88,32 @@ bool canUseCachedMeasurement( hasSameWidthSpec || sizeIsExactAndMatchesOldMeasuredSize( widthMode, availableWidth - marginRow, lastComputedWidth) || - oldSizeIsUnspecifiedAndStillFits( + oldSizeIsMaxContentAndStillFits( widthMode, availableWidth - marginRow, lastWidthMode, lastComputedWidth) || - newMeasureSizeIsStricterAndStillValid( + newSizeIsStricterAndStillValid( widthMode, availableWidth - marginRow, lastWidthMode, lastAvailableWidth, lastComputedWidth); - const bool heightIsCompatible = - hasSameHeightSpec || + const bool heightIsCompatible = hasSameHeightSpec || sizeIsExactAndMatchesOldMeasuredSize( - heightMode, availableHeight - marginColumn, lastComputedHeight) || - oldSizeIsUnspecifiedAndStillFits( - heightMode, - availableHeight - marginColumn, - lastHeightMode, - lastComputedHeight) || - newMeasureSizeIsStricterAndStillValid( - heightMode, - availableHeight - marginColumn, - lastHeightMode, - lastAvailableHeight, - lastComputedHeight); + heightMode, + availableHeight - marginColumn, + lastComputedHeight) || + oldSizeIsMaxContentAndStillFits(heightMode, + availableHeight - marginColumn, + lastHeightMode, + lastComputedHeight) || + newSizeIsStricterAndStillValid(heightMode, + availableHeight - marginColumn, + lastHeightMode, + lastAvailableHeight, + lastComputedHeight); return widthIsCompatible && heightIsCompatible; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Cache.h b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Cache.h index 31b91d5f791ead..f8857eaf35c947 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Cache.h +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Cache.h @@ -7,19 +7,19 @@ #pragma once +#include #include -#include namespace facebook::yoga { bool canUseCachedMeasurement( - MeasureMode widthMode, + SizingMode widthMode, float availableWidth, - MeasureMode heightMode, + SizingMode heightMode, float availableHeight, - MeasureMode lastWidthMode, + SizingMode lastWidthMode, float lastAvailableWidth, - MeasureMode lastHeightMode, + SizingMode lastHeightMode, float lastAvailableHeight, float lastComputedWidth, float lastComputedHeight, diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index c1026c9adcf823..f066dbdfc45213 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -39,8 +40,8 @@ bool calculateLayoutInternal( const float availableWidth, const float availableHeight, const Direction ownerDirection, - const MeasureMode widthMeasureMode, - const MeasureMode heightMeasureMode, + const SizingMode widthSizingMode, + const SizingMode heightSizingMode, const float ownerWidth, const float ownerHeight, const bool performLayout, @@ -97,22 +98,22 @@ static void constrainMaxSizeForMode( const enum FlexDirection axis, const float ownerAxisSize, const float ownerWidth, - MeasureMode* mode, + SizingMode* mode, float* size) { const FloatOptional maxSize = yoga::resolveValue( node->getStyle().maxDimension(dimension(axis)), ownerAxisSize) + FloatOptional(node->getMarginForAxis(axis, ownerWidth)); switch (*mode) { - case MeasureMode::Exactly: - case MeasureMode::AtMost: + case SizingMode::StretchFit: + case SizingMode::FitContent: *size = (maxSize.isUndefined() || *size < maxSize.unwrap()) ? *size : maxSize.unwrap(); break; - case MeasureMode::Undefined: + case SizingMode::MaxContent: if (maxSize.isDefined()) { - *mode = MeasureMode::AtMost; + *mode = SizingMode::FitContent; *size = maxSize.unwrap(); } break; @@ -123,11 +124,11 @@ static void computeFlexBasisForChild( const yoga::Node* const node, yoga::Node* const child, const float width, - const MeasureMode widthMode, + const SizingMode widthMode, const float height, const float ownerWidth, const float ownerHeight, - const MeasureMode heightMode, + const SizingMode heightMode, const Direction direction, LayoutData& layoutMarkerData, const uint32_t depth, @@ -140,8 +141,8 @@ static void computeFlexBasisForChild( float childWidth; float childHeight; - MeasureMode childWidthMeasureMode; - MeasureMode childHeightMeasureMode; + SizingMode childWidthSizingMode; + SizingMode childHeightSizingMode; const FloatOptional resolvedFlexBasis = yoga::resolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize); @@ -182,8 +183,8 @@ static void computeFlexBasisForChild( // basis). childWidth = YGUndefined; childHeight = YGUndefined; - childWidthMeasureMode = MeasureMode::Undefined; - childHeightMeasureMode = MeasureMode::Undefined; + childWidthSizingMode = SizingMode::MaxContent; + childHeightSizingMode = SizingMode::MaxContent; auto marginRow = child->getMarginForAxis(FlexDirection::Row, ownerWidth); auto marginColumn = @@ -195,7 +196,7 @@ static void computeFlexBasisForChild( child->getResolvedDimension(Dimension::Width), ownerWidth) .unwrap() + marginRow; - childWidthMeasureMode = MeasureMode::Exactly; + childWidthSizingMode = SizingMode::StretchFit; } if (isColumnStyleDimDefined) { childHeight = @@ -203,7 +204,7 @@ static void computeFlexBasisForChild( child->getResolvedDimension(Dimension::Height), ownerHeight) .unwrap() + marginColumn; - childHeightMeasureMode = MeasureMode::Exactly; + childHeightSizingMode = SizingMode::StretchFit; } // The W3C spec doesn't say anything about the 'overflow' property, but all @@ -212,7 +213,7 @@ static void computeFlexBasisForChild( node->getStyle().overflow() != Overflow::Scroll) { if (yoga::isUndefined(childWidth) && yoga::isDefined(width)) { childWidth = width; - childWidthMeasureMode = MeasureMode::AtMost; + childWidthSizingMode = SizingMode::FitContent; } } @@ -220,21 +221,21 @@ static void computeFlexBasisForChild( node->getStyle().overflow() != Overflow::Scroll) { if (yoga::isUndefined(childHeight) && yoga::isDefined(height)) { childHeight = height; - childHeightMeasureMode = MeasureMode::AtMost; + childHeightSizingMode = SizingMode::FitContent; } } const auto& childStyle = child->getStyle(); if (childStyle.aspectRatio().isDefined()) { - if (!isMainAxisRow && childWidthMeasureMode == MeasureMode::Exactly) { + if (!isMainAxisRow && childWidthSizingMode == SizingMode::StretchFit) { childHeight = marginColumn + (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); - childHeightMeasureMode = MeasureMode::Exactly; + childHeightSizingMode = SizingMode::StretchFit; } else if ( - isMainAxisRow && childHeightMeasureMode == MeasureMode::Exactly) { + isMainAxisRow && childHeightSizingMode == SizingMode::StretchFit) { childWidth = marginRow + (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); - childWidthMeasureMode = MeasureMode::Exactly; + childWidthSizingMode = SizingMode::StretchFit; } } @@ -242,35 +243,35 @@ static void computeFlexBasisForChild( // the cross axis to be measured exactly with the available inner width const bool hasExactWidth = - yoga::isDefined(width) && widthMode == MeasureMode::Exactly; + yoga::isDefined(width) && widthMode == SizingMode::StretchFit; const bool childWidthStretch = resolveChildAlignment(node, child) == Align::Stretch && - childWidthMeasureMode != MeasureMode::Exactly; + childWidthSizingMode != SizingMode::StretchFit; if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth && childWidthStretch) { childWidth = width; - childWidthMeasureMode = MeasureMode::Exactly; + childWidthSizingMode = SizingMode::StretchFit; if (childStyle.aspectRatio().isDefined()) { childHeight = (childWidth - marginRow) / childStyle.aspectRatio().unwrap(); - childHeightMeasureMode = MeasureMode::Exactly; + childHeightSizingMode = SizingMode::StretchFit; } } const bool hasExactHeight = - yoga::isDefined(height) && heightMode == MeasureMode::Exactly; + yoga::isDefined(height) && heightMode == SizingMode::StretchFit; const bool childHeightStretch = resolveChildAlignment(node, child) == Align::Stretch && - childHeightMeasureMode != MeasureMode::Exactly; + childHeightSizingMode != SizingMode::StretchFit; if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight && childHeightStretch) { childHeight = height; - childHeightMeasureMode = MeasureMode::Exactly; + childHeightSizingMode = SizingMode::StretchFit; if (childStyle.aspectRatio().isDefined()) { childWidth = (childHeight - marginColumn) * childStyle.aspectRatio().unwrap(); - childWidthMeasureMode = MeasureMode::Exactly; + childWidthSizingMode = SizingMode::StretchFit; } } @@ -279,14 +280,14 @@ static void computeFlexBasisForChild( FlexDirection::Row, ownerWidth, ownerWidth, - &childWidthMeasureMode, + &childWidthSizingMode, &childWidth); constrainMaxSizeForMode( child, FlexDirection::Column, ownerHeight, ownerWidth, - &childHeightMeasureMode, + &childHeightSizingMode, &childHeight); // Measure the child @@ -295,8 +296,8 @@ static void computeFlexBasisForChild( childWidth, childHeight, direction, - childWidthMeasureMode, - childHeightMeasureMode, + childWidthSizingMode, + childHeightSizingMode, ownerWidth, ownerHeight, false, @@ -316,7 +317,7 @@ static void layoutAbsoluteChild( const yoga::Node* const node, yoga::Node* const child, const float width, - const MeasureMode widthMode, + const SizingMode widthMode, const float height, const Direction direction, LayoutData& layoutMarkerData, @@ -329,8 +330,8 @@ static void layoutAbsoluteChild( float childWidth = YGUndefined; float childHeight = YGUndefined; - MeasureMode childWidthMeasureMode = MeasureMode::Undefined; - MeasureMode childHeightMeasureMode = MeasureMode::Undefined; + SizingMode childWidthSizingMode = SizingMode::MaxContent; + SizingMode childHeightSizingMode = SizingMode::MaxContent; auto marginRow = child->getMarginForAxis(FlexDirection::Row, width); auto marginColumn = child->getMarginForAxis(FlexDirection::Column, width); @@ -395,22 +396,22 @@ static void layoutAbsoluteChild( // If we're still missing one or the other dimension, measure the content. if (yoga::isUndefined(childWidth) || yoga::isUndefined(childHeight)) { - childWidthMeasureMode = yoga::isUndefined(childWidth) - ? MeasureMode::Undefined - : MeasureMode::Exactly; - childHeightMeasureMode = yoga::isUndefined(childHeight) - ? MeasureMode::Undefined - : MeasureMode::Exactly; + childWidthSizingMode = yoga::isUndefined(childWidth) + ? SizingMode::MaxContent + : SizingMode::StretchFit; + childHeightSizingMode = yoga::isUndefined(childHeight) + ? SizingMode::MaxContent + : SizingMode::StretchFit; // If the size of the owner is defined then try to constrain the absolute // child to that size as well. This allows text within the absolute child to // wrap to the size of its owner. This is the same behavior as many browsers // implement. if (!isMainAxisRow && yoga::isUndefined(childWidth) && - widthMode != MeasureMode::Undefined && yoga::isDefined(width) && + widthMode != SizingMode::MaxContent && yoga::isDefined(width) && width > 0) { childWidth = width; - childWidthMeasureMode = MeasureMode::AtMost; + childWidthSizingMode = SizingMode::FitContent; } calculateLayoutInternal( @@ -418,8 +419,8 @@ static void layoutAbsoluteChild( childWidth, childHeight, direction, - childWidthMeasureMode, - childHeightMeasureMode, + childWidthSizingMode, + childHeightSizingMode, childWidth, childHeight, false, @@ -438,8 +439,8 @@ static void layoutAbsoluteChild( childWidth, childHeight, direction, - MeasureMode::Exactly, - MeasureMode::Exactly, + SizingMode::StretchFit, + SizingMode::StretchFit, childWidth, childHeight, true, @@ -534,8 +535,8 @@ static void measureNodeWithMeasureFunc( yoga::Node* const node, float availableWidth, float availableHeight, - const MeasureMode widthMeasureMode, - const MeasureMode heightMeasureMode, + const SizingMode widthSizingMode, + const SizingMode heightSizingMode, const float ownerWidth, const float ownerHeight, LayoutData& layoutMarkerData, @@ -545,10 +546,10 @@ static void measureNodeWithMeasureFunc( node->hasMeasureFunc(), "Expected node to have custom measure function"); - if (widthMeasureMode == MeasureMode::Undefined) { + if (widthSizingMode == SizingMode::MaxContent) { availableWidth = YGUndefined; } - if (heightMeasureMode == MeasureMode::Undefined) { + if (heightSizingMode == SizingMode::MaxContent) { availableHeight = YGUndefined; } @@ -567,8 +568,8 @@ static void measureNodeWithMeasureFunc( ? availableHeight : yoga::maxOrDefined(0.0f, availableHeight - paddingAndBorderAxisColumn); - if (widthMeasureMode == MeasureMode::Exactly && - heightMeasureMode == MeasureMode::Exactly) { + if (widthSizingMode == SizingMode::StretchFit && + heightSizingMode == SizingMode::StretchFit) { // Don't bother sizing the text if both dimensions are already defined. node->setLayoutMeasuredDimension( boundAxis( @@ -587,7 +588,10 @@ static void measureNodeWithMeasureFunc( // Measure the text under the current constraints. const YGSize measuredSize = node->measure( - innerWidth, widthMeasureMode, innerHeight, heightMeasureMode); + innerWidth, + measureMode(widthSizingMode), + innerHeight, + measureMode(heightSizingMode)); layoutMarkerData.measureCallbacks += 1; layoutMarkerData.measureCallbackReasonsCount[static_cast(reason)] += @@ -596,9 +600,9 @@ static void measureNodeWithMeasureFunc( Event::publish( node, {innerWidth, - unscopedEnum(widthMeasureMode), + unscopedEnum(measureMode(widthSizingMode)), innerHeight, - unscopedEnum(heightMeasureMode), + unscopedEnum(measureMode(heightSizingMode)), measuredSize.width, measuredSize.height, reason}); @@ -607,8 +611,8 @@ static void measureNodeWithMeasureFunc( boundAxis( node, FlexDirection::Row, - (widthMeasureMode == MeasureMode::Undefined || - widthMeasureMode == MeasureMode::AtMost) + (widthSizingMode == SizingMode::MaxContent || + widthSizingMode == SizingMode::FitContent) ? measuredSize.width + paddingAndBorderAxisRow : availableWidth, ownerWidth, @@ -619,8 +623,8 @@ static void measureNodeWithMeasureFunc( boundAxis( node, FlexDirection::Column, - (heightMeasureMode == MeasureMode::Undefined || - heightMeasureMode == MeasureMode::AtMost) + (heightSizingMode == SizingMode::MaxContent || + heightSizingMode == SizingMode::FitContent) ? measuredSize.height + paddingAndBorderAxisColumn : availableHeight, ownerHeight, @@ -635,16 +639,16 @@ static void measureNodeWithoutChildren( yoga::Node* const node, const float availableWidth, const float availableHeight, - const MeasureMode widthMeasureMode, - const MeasureMode heightMeasureMode, + const SizingMode widthSizingMode, + const SizingMode heightSizingMode, const float ownerWidth, const float ownerHeight) { const auto& padding = node->getLayout().padding; const auto& border = node->getLayout().border; float width = availableWidth; - if (widthMeasureMode == MeasureMode::Undefined || - widthMeasureMode == MeasureMode::AtMost) { + if (widthSizingMode == SizingMode::MaxContent || + widthSizingMode == SizingMode::FitContent) { width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight]; } @@ -653,8 +657,8 @@ static void measureNodeWithoutChildren( Dimension::Width); float height = availableHeight; - if (heightMeasureMode == MeasureMode::Undefined || - heightMeasureMode == MeasureMode::AtMost) { + if (heightSizingMode == SizingMode::MaxContent || + heightSizingMode == SizingMode::FitContent) { height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom]; } @@ -667,22 +671,22 @@ static bool measureNodeWithFixedSize( yoga::Node* const node, const float availableWidth, const float availableHeight, - const MeasureMode widthMeasureMode, - const MeasureMode heightMeasureMode, + const SizingMode widthSizingMode, + const SizingMode heightSizingMode, const float ownerWidth, const float ownerHeight) { if ((yoga::isDefined(availableWidth) && - widthMeasureMode == MeasureMode::AtMost && availableWidth <= 0.0f) || + widthSizingMode == SizingMode::FitContent && availableWidth <= 0.0f) || (yoga::isDefined(availableHeight) && - heightMeasureMode == MeasureMode::AtMost && availableHeight <= 0.0f) || - (widthMeasureMode == MeasureMode::Exactly && - heightMeasureMode == MeasureMode::Exactly)) { + heightSizingMode == SizingMode::FitContent && availableHeight <= 0.0f) || + (widthSizingMode == SizingMode::StretchFit && + heightSizingMode == SizingMode::StretchFit)) { node->setLayoutMeasuredDimension( boundAxis( node, FlexDirection::Row, yoga::isUndefined(availableWidth) || - (widthMeasureMode == MeasureMode::AtMost && + (widthSizingMode == SizingMode::FitContent && availableWidth < 0.0f) ? 0.0f : availableWidth, @@ -695,7 +699,7 @@ static bool measureNodeWithFixedSize( node, FlexDirection::Column, yoga::isUndefined(availableHeight) || - (heightMeasureMode == MeasureMode::AtMost && + (heightSizingMode == SizingMode::FitContent && availableHeight < 0.0f) ? 0.0f : availableHeight, @@ -755,8 +759,8 @@ static float computeFlexBasisForChildren( yoga::Node* const node, const float availableInnerWidth, const float availableInnerHeight, - MeasureMode widthMeasureMode, - MeasureMode heightMeasureMode, + SizingMode widthSizingMode, + SizingMode heightSizingMode, Direction direction, FlexDirection mainAxis, bool performLayout, @@ -766,12 +770,12 @@ static float computeFlexBasisForChildren( float totalOuterFlexBasis = 0.0f; YGNodeRef singleFlexChild = nullptr; const auto& children = node->getChildren(); - MeasureMode measureModeMainDim = - isRow(mainAxis) ? widthMeasureMode : heightMeasureMode; + SizingMode sizingModeMainDim = + isRow(mainAxis) ? widthSizingMode : heightSizingMode; // If there is only one child with flexGrow + flexShrink it means we can set // the computedFlexBasis to 0 instead of measuring and shrinking / flexing the // child to exactly match the remaining space - if (measureModeMainDim == MeasureMode::Exactly) { + if (sizingModeMainDim == SizingMode::StretchFit) { for (auto child : children) { if (child->isNodeFlexible()) { if (singleFlexChild != nullptr || @@ -818,11 +822,11 @@ static float computeFlexBasisForChildren( node, child, availableInnerWidth, - widthMeasureMode, + widthSizingMode, availableInnerHeight, availableInnerWidth, availableInnerHeight, - heightMeasureMode, + heightSizingMode, direction, layoutMarkerData, depth, @@ -852,7 +856,7 @@ static float distributeFreeSpaceSecondPass( const float availableInnerWidth, const float availableInnerHeight, const bool mainAxisOverflows, - const MeasureMode measureModeCrossDim, + const SizingMode sizingModeCrossDim, const bool performLayout, LayoutData& layoutMarkerData, const uint32_t depth, @@ -925,35 +929,35 @@ static float distributeFreeSpaceSecondPass( float childCrossSize; float childMainSize = updatedMainSize + marginMain; - MeasureMode childCrossMeasureMode; - MeasureMode childMainMeasureMode = MeasureMode::Exactly; + SizingMode childCrossSizingMode; + SizingMode childMainSizingMode = SizingMode::StretchFit; const auto& childStyle = currentLineChild->getStyle(); if (childStyle.aspectRatio().isDefined()) { childCrossSize = isMainAxisRow ? (childMainSize - marginMain) / childStyle.aspectRatio().unwrap() : (childMainSize - marginMain) * childStyle.aspectRatio().unwrap(); - childCrossMeasureMode = MeasureMode::Exactly; + childCrossSizingMode = SizingMode::StretchFit; childCrossSize += marginCross; } else if ( !std::isnan(availableInnerCrossDim) && !styleDefinesDimension( currentLineChild, crossAxis, availableInnerCrossDim) && - measureModeCrossDim == MeasureMode::Exactly && + sizingModeCrossDim == SizingMode::StretchFit && !(isNodeFlexWrap && mainAxisOverflows) && resolveChildAlignment(node, currentLineChild) == Align::Stretch && currentLineChild->getFlexStartMarginValue(crossAxis).unit != YGUnitAuto && currentLineChild->marginTrailingValue(crossAxis).unit != YGUnitAuto) { childCrossSize = availableInnerCrossDim; - childCrossMeasureMode = MeasureMode::Exactly; + childCrossSizingMode = SizingMode::StretchFit; } else if (!styleDefinesDimension( currentLineChild, crossAxis, availableInnerCrossDim)) { childCrossSize = availableInnerCrossDim; - childCrossMeasureMode = yoga::isUndefined(childCrossSize) - ? MeasureMode::Undefined - : MeasureMode::AtMost; + childCrossSizingMode = yoga::isUndefined(childCrossSize) + ? SizingMode::MaxContent + : SizingMode::FitContent; } else { childCrossSize = yoga::resolveValue( @@ -964,11 +968,11 @@ static float distributeFreeSpaceSecondPass( const bool isLoosePercentageMeasurement = currentLineChild->getResolvedDimension(dimension(crossAxis)).unit == YGUnitPercent && - measureModeCrossDim != MeasureMode::Exactly; - childCrossMeasureMode = + sizingModeCrossDim != SizingMode::StretchFit; + childCrossSizingMode = yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement - ? MeasureMode::Undefined - : MeasureMode::Exactly; + ? SizingMode::MaxContent + : SizingMode::StretchFit; } constrainMaxSizeForMode( @@ -976,14 +980,14 @@ static float distributeFreeSpaceSecondPass( mainAxis, availableInnerMainDim, availableInnerWidth, - &childMainMeasureMode, + &childMainSizingMode, &childMainSize); constrainMaxSizeForMode( currentLineChild, crossAxis, availableInnerCrossDim, availableInnerWidth, - &childCrossMeasureMode, + &childCrossSizingMode, &childCrossSize); const bool requiresStretchLayout = @@ -997,10 +1001,10 @@ static float distributeFreeSpaceSecondPass( const float childWidth = isMainAxisRow ? childMainSize : childCrossSize; const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize; - const MeasureMode childWidthMeasureMode = - isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode; - const MeasureMode childHeightMeasureMode = - !isMainAxisRow ? childMainMeasureMode : childCrossMeasureMode; + const SizingMode childWidthSizingMode = + isMainAxisRow ? childMainSizingMode : childCrossSizingMode; + const SizingMode childHeightSizingMode = + !isMainAxisRow ? childMainSizingMode : childCrossSizingMode; const bool isLayoutPass = performLayout && !requiresStretchLayout; // Recursively call the layout algorithm for this child with the updated @@ -1010,8 +1014,8 @@ static float distributeFreeSpaceSecondPass( childWidth, childHeight, node->getLayout().direction(), - childWidthMeasureMode, - childHeightMeasureMode, + childWidthSizingMode, + childHeightSizingMode, availableInnerWidth, availableInnerHeight, isLayoutPass, @@ -1144,7 +1148,7 @@ static void resolveFlexibleLength( const float availableInnerWidth, const float availableInnerHeight, const bool mainAxisOverflows, - const MeasureMode measureModeCrossDim, + const SizingMode sizingModeCrossDim, const bool performLayout, LayoutData& layoutMarkerData, const uint32_t depth, @@ -1170,7 +1174,7 @@ static void resolveFlexibleLength( availableInnerWidth, availableInnerHeight, mainAxisOverflows, - measureModeCrossDim, + sizingModeCrossDim, performLayout, layoutMarkerData, depth, @@ -1186,8 +1190,8 @@ static void justifyMainAxis( const FlexDirection mainAxis, const FlexDirection crossAxis, const Direction direction, - const MeasureMode measureModeMainDim, - const MeasureMode measureModeCrossDim, + const SizingMode sizingModeMainDim, + const SizingMode sizingModeCrossDim, const float mainAxisownerSize, const float ownerWidth, const float availableInnerMainDim, @@ -1208,7 +1212,7 @@ static void justifyMainAxis( const float gap = node->getGapForAxis(mainAxis); // If we are using "at most" rules in the main axis, make sure that // remainingFreeSpace is 0 when min main dimension is not given - if (measureModeMainDim == MeasureMode::AtMost && + if (sizingModeMainDim == SizingMode::FitContent && flexLine.layout.remainingFreeSpace > 0) { if (style.minDimension(dimension(mainAxis)).isDefined() && yoga::resolveValue( @@ -1340,7 +1344,7 @@ static void justifyMainAxis( static_cast(numberOfAutoMarginsOnCurrentLine); } bool canSkipFlex = - !performLayout && measureModeCrossDim == MeasureMode::Exactly; + !performLayout && sizingModeCrossDim == SizingMode::StretchFit; if (canSkipFlex) { // If we skipped the flex step, then we can't rely on the measuredDims // because they weren't computed. This means we can't call @@ -1432,9 +1436,9 @@ static void justifyMainAxis( // depends on layout flags // - ownerDirection: the inline (text) direction within the owner // (left-to-right or right-to-left) -// - widthMeasureMode: indicates the sizing rules for the width (see below +// - widthSizingMode: indicates the sizing rules for the width (see below // for explanation) -// - heightMeasureMode: indicates the sizing rules for the height (see below +// - heightSizingMode: indicates the sizing rules for the height (see below // for explanation) // - performLayout: specifies whether the caller is interested in just the // dimensions of the node or it requires the entire node and its subtree to @@ -1449,26 +1453,17 @@ static void justifyMainAxis( // layout.measuredDimensions field includes any border or padding for the // node but does not include margins. // -// The spec describes four different layout modes: "fill available", "max -// content", "min content", and "fit content". Of these, we don't use "min -// content" because we don't support default minimum main sizes (see above -// for details). Each of our measure modes maps to a layout mode from the -// spec (https://www.w3.org/TR/CSS3-sizing/#terms): -// - MeasureMode::Undefined: max content -// - MeasureMode::Exactly: fill available -// - MeasureMode::AtMost: fit content -// // When calling calculateLayoutImpl and calculateLayoutInternal, if the // caller passes an available size of undefined then it must also pass a -// measure mode of MeasureMode::Undefined in that dimension. +// measure mode of SizingMode::MaxContent in that dimension. // static void calculateLayoutImpl( yoga::Node* const node, const float availableWidth, const float availableHeight, const Direction ownerDirection, - const MeasureMode widthMeasureMode, - const MeasureMode heightMeasureMode, + const SizingMode widthSizingMode, + const SizingMode heightSizingMode, const float ownerWidth, const float ownerHeight, const bool performLayout, @@ -1479,17 +1474,17 @@ static void calculateLayoutImpl( yoga::assertFatalWithNode( node, yoga::isUndefined(availableWidth) - ? widthMeasureMode == MeasureMode::Undefined + ? widthSizingMode == SizingMode::MaxContent : true, - "availableWidth is indefinite so widthMeasureMode must be " - "MeasureMode::Undefined"); + "availableWidth is indefinite so widthSizingMode must be " + "SizingMode::MaxContent"); yoga::assertFatalWithNode( node, yoga::isUndefined(availableHeight) - ? heightMeasureMode == MeasureMode::Undefined + ? heightSizingMode == SizingMode::MaxContent : true, - "availableHeight is indefinite so heightMeasureMode must be " - "MeasureMode::Undefined"); + "availableHeight is indefinite so heightSizingMode must be " + "SizingMode::MaxContent"); (performLayout ? layoutMarkerData.layouts : layoutMarkerData.measures) += 1; @@ -1549,8 +1544,8 @@ static void calculateLayoutImpl( node, availableWidth - marginAxisRow, availableHeight - marginAxisColumn, - widthMeasureMode, - heightMeasureMode, + widthSizingMode, + heightSizingMode, ownerWidth, ownerHeight, layoutMarkerData, @@ -1564,8 +1559,8 @@ static void calculateLayoutImpl( node, availableWidth - marginAxisRow, availableHeight - marginAxisColumn, - widthMeasureMode, - heightMeasureMode, + widthSizingMode, + heightSizingMode, ownerWidth, ownerHeight); return; @@ -1578,8 +1573,8 @@ static void calculateLayoutImpl( node, availableWidth - marginAxisRow, availableHeight - marginAxisColumn, - widthMeasureMode, - heightMeasureMode, + widthSizingMode, + heightSizingMode, ownerWidth, ownerHeight)) { return; @@ -1608,10 +1603,10 @@ static void calculateLayoutImpl( const float leadingPaddingAndBorderCross = node->getInlineStartPaddingAndBorder(crossAxis, direction, ownerWidth); - MeasureMode measureModeMainDim = - isMainAxisRow ? widthMeasureMode : heightMeasureMode; - MeasureMode measureModeCrossDim = - isMainAxisRow ? heightMeasureMode : widthMeasureMode; + SizingMode sizingModeMainDim = + isMainAxisRow ? widthSizingMode : heightSizingMode; + SizingMode sizingModeCrossDim = + isMainAxisRow ? heightSizingMode : widthSizingMode; const float paddingAndBorderAxisRow = isMainAxisRow ? paddingAndBorderAxisMain : paddingAndBorderAxisCross; @@ -1646,8 +1641,8 @@ static void calculateLayoutImpl( node, availableInnerWidth, availableInnerHeight, - widthMeasureMode, - heightMeasureMode, + widthSizingMode, + heightSizingMode, direction, mainAxis, performLayout, @@ -1661,12 +1656,12 @@ static void calculateLayoutImpl( } const bool mainAxisOverflows = - (measureModeMainDim != MeasureMode::Undefined) && + (sizingModeMainDim != SizingMode::MaxContent) && totalMainDim > availableInnerMainDim; if (isNodeFlexWrap && mainAxisOverflows && - measureModeMainDim == MeasureMode::AtMost) { - measureModeMainDim = MeasureMode::Exactly; + sizingModeMainDim == SizingMode::FitContent) { + sizingModeMainDim = SizingMode::StretchFit; } // STEP 4: COLLECT FLEX ITEMS INTO FLEX LINES @@ -1700,7 +1695,7 @@ static void calculateLayoutImpl( // If we don't need to measure the cross axis, we can skip the entire flex // step. const bool canSkipFlex = - !performLayout && measureModeCrossDim == MeasureMode::Exactly; + !performLayout && sizingModeCrossDim == SizingMode::StretchFit; // STEP 5: RESOLVING FLEXIBLE LENGTHS ON MAIN AXIS // Calculate the remaining available space that needs to be allocated. If @@ -1710,7 +1705,7 @@ static void calculateLayoutImpl( bool sizeBasedOnContent = false; // If we don't measure with exact main dimension we want to ensure we don't // violate min and max - if (measureModeMainDim != MeasureMode::Exactly) { + if (sizingModeMainDim != SizingMode::StretchFit) { const auto& style = node->getStyle(); const float minInnerWidth = yoga::resolveValue(style.minDimension(Dimension::Width), ownerWidth) @@ -1783,7 +1778,7 @@ static void calculateLayoutImpl( availableInnerWidth, availableInnerHeight, mainAxisOverflows, - measureModeCrossDim, + sizingModeCrossDim, performLayout, layoutMarkerData, depth, @@ -1808,8 +1803,8 @@ static void calculateLayoutImpl( mainAxis, crossAxis, direction, - measureModeMainDim, - measureModeCrossDim, + sizingModeMainDim, + sizingModeCrossDim, mainAxisownerSize, ownerWidth, availableInnerMainDim, @@ -1818,8 +1813,8 @@ static void calculateLayoutImpl( performLayout); float containerCrossAxis = availableInnerCrossDim; - if (measureModeCrossDim == MeasureMode::Undefined || - measureModeCrossDim == MeasureMode::AtMost) { + if (sizingModeCrossDim == SizingMode::MaxContent || + sizingModeCrossDim == SizingMode::FitContent) { // Compute the cross axis from the max cross dimension of the children. containerCrossAxis = boundAxis( @@ -1832,7 +1827,7 @@ static void calculateLayoutImpl( } // If there's no flex wrap, the cross dimension is defined by the container. - if (!isNodeFlexWrap && measureModeCrossDim == MeasureMode::Exactly) { + if (!isNodeFlexWrap && sizingModeCrossDim == SizingMode::StretchFit) { flexLine.layout.crossDim = availableInnerCrossDim; } @@ -1911,21 +1906,21 @@ static void calculateLayoutImpl( childMainSize += child->getMarginForAxis(mainAxis, availableInnerWidth); - MeasureMode childMainMeasureMode = MeasureMode::Exactly; - MeasureMode childCrossMeasureMode = MeasureMode::Exactly; + SizingMode childMainSizingMode = SizingMode::StretchFit; + SizingMode childCrossSizingMode = SizingMode::StretchFit; constrainMaxSizeForMode( child, mainAxis, availableInnerMainDim, availableInnerWidth, - &childMainMeasureMode, + &childMainSizingMode, &childMainSize); constrainMaxSizeForMode( child, crossAxis, availableInnerCrossDim, availableInnerWidth, - &childCrossMeasureMode, + &childCrossSizingMode, &childCrossSize); const float childWidth = @@ -1936,24 +1931,24 @@ static void calculateLayoutImpl( auto alignContent = node->getStyle().alignContent(); auto crossAxisDoesNotGrow = alignContent != Align::Stretch && isNodeFlexWrap; - const MeasureMode childWidthMeasureMode = + const SizingMode childWidthSizingMode = yoga::isUndefined(childWidth) || (!isMainAxisRow && crossAxisDoesNotGrow) - ? MeasureMode::Undefined - : MeasureMode::Exactly; - const MeasureMode childHeightMeasureMode = + ? SizingMode::MaxContent + : SizingMode::StretchFit; + const SizingMode childHeightSizingMode = yoga::isUndefined(childHeight) || (isMainAxisRow && crossAxisDoesNotGrow) - ? MeasureMode::Undefined - : MeasureMode::Exactly; + ? SizingMode::MaxContent + : SizingMode::StretchFit; calculateLayoutInternal( child, childWidth, childHeight, direction, - childWidthMeasureMode, - childHeightMeasureMode, + childWidthSizingMode, + childHeightSizingMode, availableInnerWidth, availableInnerHeight, true, @@ -2174,8 +2169,8 @@ static void calculateLayoutImpl( childWidth, childHeight, direction, - MeasureMode::Exactly, - MeasureMode::Exactly, + SizingMode::StretchFit, + SizingMode::StretchFit, availableInnerWidth, availableInnerHeight, true, @@ -2234,9 +2229,9 @@ static void calculateLayoutImpl( // If the user didn't specify a width or height for the node, set the // dimensions based on the children. - if (measureModeMainDim == MeasureMode::Undefined || + if (sizingModeMainDim == SizingMode::MaxContent || (node->getStyle().overflow() != Overflow::Scroll && - measureModeMainDim == MeasureMode::AtMost)) { + sizingModeMainDim == SizingMode::FitContent)) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. node->setLayoutMeasuredDimension( @@ -2245,7 +2240,7 @@ static void calculateLayoutImpl( dimension(mainAxis)); } else if ( - measureModeMainDim == MeasureMode::AtMost && + sizingModeMainDim == SizingMode::FitContent && node->getStyle().overflow() == Overflow::Scroll) { node->setLayoutMeasuredDimension( yoga::maxOrDefined( @@ -2261,9 +2256,9 @@ static void calculateLayoutImpl( dimension(mainAxis)); } - if (measureModeCrossDim == MeasureMode::Undefined || + if (sizingModeCrossDim == SizingMode::MaxContent || (node->getStyle().overflow() != Overflow::Scroll && - measureModeCrossDim == MeasureMode::AtMost)) { + sizingModeCrossDim == SizingMode::FitContent)) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. node->setLayoutMeasuredDimension( @@ -2276,7 +2271,7 @@ static void calculateLayoutImpl( dimension(crossAxis)); } else if ( - measureModeCrossDim == MeasureMode::AtMost && + sizingModeCrossDim == SizingMode::FitContent && node->getStyle().overflow() == Overflow::Scroll) { node->setLayoutMeasuredDimension( yoga::maxOrDefined( @@ -2325,7 +2320,7 @@ static void calculateLayoutImpl( absolutePercentageAgainstPaddingEdge ? node->getLayout().measuredDimension(Dimension::Width) : availableInnerWidth, - isMainAxisRow ? measureModeMainDim : measureModeCrossDim, + isMainAxisRow ? sizingModeMainDim : sizingModeCrossDim, absolutePercentageAgainstPaddingEdge ? node->getLayout().measuredDimension(Dimension::Height) : availableInnerHeight, @@ -2375,15 +2370,15 @@ static const char* spacerWithLength(const unsigned long level) { } } -static const char* measureModeName( - const MeasureMode mode, +static const char* sizingModeName( + const SizingMode mode, const bool performLayout) { switch (mode) { - case MeasureMode::Undefined: + case SizingMode::MaxContent: return performLayout ? "LAY_UNDEFINED" : "UNDEFINED"; - case MeasureMode::Exactly: + case SizingMode::StretchFit: return performLayout ? "LAY_EXACTLY" : "EXACTLY"; - case MeasureMode::AtMost: + case SizingMode::FitContent: return performLayout ? "LAY_AT_MOST" : "AT_MOST"; } return ""; @@ -2402,8 +2397,8 @@ bool calculateLayoutInternal( const float availableWidth, const float availableHeight, const Direction ownerDirection, - const MeasureMode widthMeasureMode, - const MeasureMode heightMeasureMode, + const SizingMode widthSizingMode, + const SizingMode heightSizingMode, const float ownerWidth, const float ownerHeight, const bool performLayout, @@ -2424,8 +2419,8 @@ bool calculateLayoutInternal( layout->nextCachedMeasurementsIndex = 0; layout->cachedLayout.availableWidth = -1; layout->cachedLayout.availableHeight = -1; - layout->cachedLayout.widthMeasureMode = MeasureMode::Undefined; - layout->cachedLayout.heightMeasureMode = MeasureMode::Undefined; + layout->cachedLayout.widthSizingMode = SizingMode::MaxContent; + layout->cachedLayout.heightSizingMode = SizingMode::MaxContent; layout->cachedLayout.computedWidth = -1; layout->cachedLayout.computedHeight = -1; } @@ -2448,13 +2443,13 @@ bool calculateLayoutInternal( // First, try to use the layout cache. if (canUseCachedMeasurement( - widthMeasureMode, + widthSizingMode, availableWidth, - heightMeasureMode, + heightSizingMode, availableHeight, - layout->cachedLayout.widthMeasureMode, + layout->cachedLayout.widthSizingMode, layout->cachedLayout.availableWidth, - layout->cachedLayout.heightMeasureMode, + layout->cachedLayout.heightSizingMode, layout->cachedLayout.availableHeight, layout->cachedLayout.computedWidth, layout->cachedLayout.computedHeight, @@ -2466,13 +2461,13 @@ bool calculateLayoutInternal( // Try to use the measurement cache. for (size_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) { if (canUseCachedMeasurement( - widthMeasureMode, + widthSizingMode, availableWidth, - heightMeasureMode, + heightSizingMode, availableHeight, - layout->cachedMeasurements[i].widthMeasureMode, + layout->cachedMeasurements[i].widthSizingMode, layout->cachedMeasurements[i].availableWidth, - layout->cachedMeasurements[i].heightMeasureMode, + layout->cachedMeasurements[i].heightSizingMode, layout->cachedMeasurements[i].availableHeight, layout->cachedMeasurements[i].computedWidth, layout->cachedMeasurements[i].computedHeight, @@ -2489,8 +2484,8 @@ bool calculateLayoutInternal( layout->cachedLayout.availableWidth, availableWidth) && yoga::inexactEquals( layout->cachedLayout.availableHeight, availableHeight) && - layout->cachedLayout.widthMeasureMode == widthMeasureMode && - layout->cachedLayout.heightMeasureMode == heightMeasureMode) { + layout->cachedLayout.widthSizingMode == widthSizingMode && + layout->cachedLayout.heightSizingMode == heightSizingMode) { cachedResults = &layout->cachedLayout; } } else { @@ -2499,9 +2494,8 @@ bool calculateLayoutInternal( layout->cachedMeasurements[i].availableWidth, availableWidth) && yoga::inexactEquals( layout->cachedMeasurements[i].availableHeight, availableHeight) && - layout->cachedMeasurements[i].widthMeasureMode == widthMeasureMode && - layout->cachedMeasurements[i].heightMeasureMode == - heightMeasureMode) { + layout->cachedMeasurements[i].widthSizingMode == widthSizingMode && + layout->cachedMeasurements[i].heightSizingMode == heightSizingMode) { cachedResults = &layout->cachedMeasurements[i]; break; } @@ -2529,8 +2523,8 @@ bool calculateLayoutInternal( node, LogLevel::Verbose, "wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n", - measureModeName(widthMeasureMode, performLayout), - measureModeName(heightMeasureMode, performLayout), + sizingModeName(widthSizingMode, performLayout), + sizingModeName(heightSizingMode, performLayout), availableWidth, availableHeight, cachedResults->computedWidth, @@ -2551,8 +2545,8 @@ bool calculateLayoutInternal( node, LogLevel::Verbose, "wm: %s, hm: %s, aw: %f ah: %f %s\n", - measureModeName(widthMeasureMode, performLayout), - measureModeName(heightMeasureMode, performLayout), + sizingModeName(widthSizingMode, performLayout), + sizingModeName(heightSizingMode, performLayout), availableWidth, availableHeight, LayoutPassReasonToString(reason)); @@ -2563,8 +2557,8 @@ bool calculateLayoutInternal( availableWidth, availableHeight, ownerDirection, - widthMeasureMode, - heightMeasureMode, + widthSizingMode, + heightSizingMode, ownerWidth, ownerHeight, performLayout, @@ -2586,8 +2580,8 @@ bool calculateLayoutInternal( node, LogLevel::Verbose, "wm: %s, hm: %s, d: (%f, %f) %s\n", - measureModeName(widthMeasureMode, performLayout), - measureModeName(heightMeasureMode, performLayout), + sizingModeName(widthSizingMode, performLayout), + sizingModeName(heightSizingMode, performLayout), layout->measuredDimension(Dimension::Width), layout->measuredDimension(Dimension::Height), LayoutPassReasonToString(reason)); @@ -2621,8 +2615,8 @@ bool calculateLayoutInternal( newCacheEntry->availableWidth = availableWidth; newCacheEntry->availableHeight = availableHeight; - newCacheEntry->widthMeasureMode = widthMeasureMode; - newCacheEntry->heightMeasureMode = heightMeasureMode; + newCacheEntry->widthSizingMode = widthSizingMode; + newCacheEntry->heightSizingMode = heightSizingMode; newCacheEntry->computedWidth = layout->measuredDimension(Dimension::Width); newCacheEntry->computedHeight = @@ -2672,7 +2666,7 @@ void calculateLayout( gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed); node->resolveDimension(); float width = YGUndefined; - MeasureMode widthMeasureMode = MeasureMode::Undefined; + SizingMode widthSizingMode = SizingMode::MaxContent; const auto& style = node->getStyle(); if (styleDefinesDimension(node, FlexDirection::Row, ownerWidth)) { width = @@ -2681,21 +2675,21 @@ void calculateLayout( ownerWidth) .unwrap() + node->getMarginForAxis(FlexDirection::Row, ownerWidth)); - widthMeasureMode = MeasureMode::Exactly; + widthSizingMode = SizingMode::StretchFit; } else if (yoga::resolveValue( style.maxDimension(Dimension::Width), ownerWidth) .isDefined()) { width = yoga::resolveValue(style.maxDimension(Dimension::Width), ownerWidth) .unwrap(); - widthMeasureMode = MeasureMode::AtMost; + widthSizingMode = SizingMode::FitContent; } else { width = ownerWidth; - widthMeasureMode = yoga::isUndefined(width) ? MeasureMode::Undefined - : MeasureMode::Exactly; + widthSizingMode = yoga::isUndefined(width) ? SizingMode::MaxContent + : SizingMode::StretchFit; } float height = YGUndefined; - MeasureMode heightMeasureMode = MeasureMode::Undefined; + SizingMode heightSizingMode = SizingMode::MaxContent; if (styleDefinesDimension(node, FlexDirection::Column, ownerHeight)) { height = (yoga::resolveValue( @@ -2703,26 +2697,26 @@ void calculateLayout( ownerHeight) .unwrap() + node->getMarginForAxis(FlexDirection::Column, ownerWidth)); - heightMeasureMode = MeasureMode::Exactly; + heightSizingMode = SizingMode::StretchFit; } else if (yoga::resolveValue( style.maxDimension(Dimension::Height), ownerHeight) .isDefined()) { height = yoga::resolveValue(style.maxDimension(Dimension::Height), ownerHeight) .unwrap(); - heightMeasureMode = MeasureMode::AtMost; + heightSizingMode = SizingMode::FitContent; } else { height = ownerHeight; - heightMeasureMode = yoga::isUndefined(height) ? MeasureMode::Undefined - : MeasureMode::Exactly; + heightSizingMode = yoga::isUndefined(height) ? SizingMode::MaxContent + : SizingMode::StretchFit; } if (calculateLayoutInternal( node, width, height, ownerDirection, - widthMeasureMode, - heightMeasureMode, + widthSizingMode, + heightSizingMode, ownerWidth, ownerHeight, true, diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/SizingMode.h b/packages/react-native/ReactCommon/yoga/yoga/algorithm/SizingMode.h new file mode 100644 index 00000000000000..bd725df13ac68b --- /dev/null +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/SizingMode.h @@ -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. + */ + +#pragma once + +#include +#include + +namespace facebook::yoga { + +/** + * Corresponds to a CSS auto box sizes. Missing "min-content", as Yoga does not + * current support automatic minimum sizes. + * https://www.w3.org/TR/css-sizing-3/#auto-box-sizes + * https://www.w3.org/TR/css-flexbox-1/#min-size-auto + */ +enum class SizingMode { + /** + * The size a box would take if its outer size filled the available space in + * the given axis; in other words, the stretch fit into the available space, + * if that is definite. Undefined if the available space is indefinite. + */ + StretchFit, + + /** + * A box’s “ideal” size in a given axis when given infinite available space. + * Usually this is the smallest size the box could take in that axis while + * still fitting around its contents, i.e. minimizing unfilled space while + * avoiding overflow. + */ + MaxContent, + + /** + * If the available space in a given axis is definite, equal to + * clamp(min-content size, stretch-fit size, max-content size) (i.e. + * max(min-content size, min(max-content size, stretch-fit size))). When + * sizing under a min-content constraint, equal to the min-content size. + * Otherwise, equal to the max-content size in that axis. + */ + FitContent, +}; + +inline MeasureMode measureMode(SizingMode mode) { + switch (mode) { + case SizingMode::StretchFit: + return MeasureMode::Exactly; + case SizingMode::MaxContent: + return MeasureMode::Undefined; + case SizingMode::FitContent: + return MeasureMode::AtMost; + } + + fatalWithMessage("Invalid SizingMode"); +} + +inline SizingMode sizingMode(MeasureMode mode) { + switch (mode) { + case MeasureMode::Exactly: + return SizingMode::StretchFit; + case MeasureMode::Undefined: + return SizingMode::MaxContent; + case MeasureMode::AtMost: + return SizingMode::FitContent; + } + + fatalWithMessage("Invalid MeasureMode"); +} + +} // namespace facebook::yoga diff --git a/packages/react-native/ReactCommon/yoga/yoga/debug/AssertFatal.cpp b/packages/react-native/ReactCommon/yoga/yoga/debug/AssertFatal.cpp index 2388a744539dbe..e43ce2a254ee23 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/debug/AssertFatal.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/debug/AssertFatal.cpp @@ -7,8 +7,10 @@ #include +#include #include #include +#include namespace facebook::yoga { diff --git a/packages/react-native/ReactCommon/yoga/yoga/debug/AssertFatal.h b/packages/react-native/ReactCommon/yoga/yoga/debug/AssertFatal.h index 929ff1792d0d8f..bbd8ad19eabbf0 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/debug/AssertFatal.h +++ b/packages/react-native/ReactCommon/yoga/yoga/debug/AssertFatal.h @@ -8,11 +8,12 @@ #pragma once #include -#include -#include namespace facebook::yoga { +class Node; +class Config; + [[noreturn]] void fatalWithMessage(const char* message); void assertFatal(bool condition, const char* message); diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/CachedMeasurement.h b/packages/react-native/ReactCommon/yoga/yoga/node/CachedMeasurement.h index 4d2c22260075dc..9c76280acf74e1 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/CachedMeasurement.h +++ b/packages/react-native/ReactCommon/yoga/yoga/node/CachedMeasurement.h @@ -11,7 +11,7 @@ #include -#include +#include #include namespace facebook::yoga { @@ -19,15 +19,15 @@ namespace facebook::yoga { struct CachedMeasurement { float availableWidth{-1}; float availableHeight{-1}; - MeasureMode widthMeasureMode{MeasureMode::Undefined}; - MeasureMode heightMeasureMode{MeasureMode::Undefined}; + SizingMode widthSizingMode{SizingMode::MaxContent}; + SizingMode heightSizingMode{SizingMode::MaxContent}; float computedWidth{-1}; float computedHeight{-1}; bool operator==(CachedMeasurement measurement) const { - bool isEqual = widthMeasureMode == measurement.widthMeasureMode && - heightMeasureMode == measurement.heightMeasureMode; + bool isEqual = widthSizingMode == measurement.widthSizingMode && + heightSizingMode == measurement.heightSizingMode; if (!yoga::isUndefined(availableWidth) || !yoga::isUndefined(measurement.availableWidth)) { From 5e22e887cdaef564113c23398c89089b9811c70a Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Sat, 25 Nov 2023 15:05:45 -0800 Subject: [PATCH 3/3] YGEdge -> yoga::Edge (#41391) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41391 X-link: https://github.com/facebook/yoga/pull/1461 Converts usages of `YGEdge` within internal APIs to `yoga::Edge` scoped enum. With the exception of YGUnit which is in its own state of transition, this is the last public yoga enum to need to be moved to scoped enum form for usages internal to the Yoga public API. Changelog: [internal] Reviewed By: rshest Differential Revision: D51152779 fbshipit-source-id: e9293b6215a8f4a3c65852d583a29693ae34f8aa --- .../Text/RCTParagraphComponentViewTests.mm | 16 +- .../AndroidTextInputComponentDescriptor.h | 12 +- .../components/view/BaseViewProps.cpp | 22 +- .../components/view/ViewShadowNode.cpp | 2 +- .../view/YogaLayoutableShadowNode.cpp | 113 ++++----- .../components/view/YogaStylableProps.cpp | 220 +++++++++--------- .../view/YogaStylablePropsMapBuffer.cpp | 25 +- .../components/view/propsConversions.h | 216 ++++++++--------- .../components/view/tests/LayoutTest.cpp | 16 +- .../mounting/tests/StackingContextTest.cpp | 6 +- .../ReactCommon/yoga/yoga/YGNodeLayout.cpp | 38 +-- .../ReactCommon/yoga/yoga/YGNodeStyle.cpp | 24 +- .../yoga/yoga/algorithm/Baseline.cpp | 2 +- .../yoga/yoga/algorithm/CalculateLayout.cpp | 55 +++-- .../yoga/yoga/algorithm/FlexDirection.h | 53 ++--- .../yoga/yoga/algorithm/PixelGrid.cpp | 8 +- .../yoga/yoga/debug/NodeToString.cpp | 8 +- .../yoga/yoga/node/LayoutResults.cpp | 8 +- .../yoga/yoga/node/LayoutResults.h | 71 ++++-- .../ReactCommon/yoga/yoga/node/Node.cpp | 138 +++++------ .../ReactCommon/yoga/yoga/node/Node.h | 17 +- .../ReactCommon/yoga/yoga/style/Style.h | 32 +-- 22 files changed, 575 insertions(+), 527 deletions(-) diff --git a/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm b/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm index f6c1ba3c6ed15f..2d8e5de1fb5c00 100644 --- a/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm +++ b/packages/react-native/React/Tests/Text/RCTParagraphComponentViewTests.mm @@ -134,8 +134,8 @@ - (void)setUp props.accessible = true; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0)); - yogaStyle.setPosition(YGEdgeTop, yoga::value::points(0)); + 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)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(200)); return sharedProps; @@ -214,8 +214,8 @@ - (void)setUp props.accessible = true; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0)); - yogaStyle.setPosition(YGEdgeTop, yoga::value::points(30)); + 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)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50)); return sharedProps; @@ -258,8 +258,8 @@ - (void)setUp props.accessible = true; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0)); - yogaStyle.setPosition(YGEdgeTop, yoga::value::points(90)); + 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)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50)); return sharedProps; @@ -432,8 +432,8 @@ - (void)testEntireParagraphLink props.accessibilityTraits = AccessibilityTraits::Link; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(0)); - yogaStyle.setPosition(YGEdgeTop, yoga::value::points(90)); + 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)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(20)); return sharedProps; diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h index 0ff0f91ea30953..6ee6c1e73c192c 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h @@ -105,23 +105,23 @@ class AndroidTextInputComponentDescriptor final !textInputProps.hasPaddingLeft && !textInputProps.hasPaddingHorizontal) { changedPadding = true; - style.setPadding(YGEdgeStart, yoga::value::points(theme.start)); + style.setPadding(yoga::Edge::Start, yoga::value::points(theme.start)); } if (!textInputProps.hasPadding && !textInputProps.hasPaddingEnd && !textInputProps.hasPaddingRight && !textInputProps.hasPaddingHorizontal) { changedPadding = true; - style.setPadding(YGEdgeEnd, yoga::value::points(theme.end)); + style.setPadding(yoga::Edge::End, yoga::value::points(theme.end)); } if (!textInputProps.hasPadding && !textInputProps.hasPaddingTop && !textInputProps.hasPaddingVertical) { changedPadding = true; - style.setPadding(YGEdgeTop, yoga::value::points(theme.top)); + style.setPadding(yoga::Edge::Top, yoga::value::points(theme.top)); } if (!textInputProps.hasPadding && !textInputProps.hasPaddingBottom && !textInputProps.hasPaddingVertical) { changedPadding = true; - style.setPadding(YGEdgeBottom, yoga::value::points(theme.bottom)); + style.setPadding(yoga::Edge::Bottom, yoga::value::points(theme.bottom)); } // If the TextInput initially does not have paddingLeft or paddingStart, a @@ -132,12 +132,12 @@ class AndroidTextInputComponentDescriptor final if ((textInputProps.hasPadding || textInputProps.hasPaddingLeft || textInputProps.hasPaddingHorizontal) && !textInputProps.hasPaddingStart) { - style.setPadding(YGEdgeStart, yoga::value::undefined()); + style.setPadding(yoga::Edge::Start, yoga::value::undefined()); } if ((textInputProps.hasPadding || textInputProps.hasPaddingRight || textInputProps.hasPaddingHorizontal) && !textInputProps.hasPaddingEnd) { - style.setPadding(YGEdgeEnd, yoga::value::undefined()); + style.setPadding(yoga::Edge::End, yoga::value::undefined()); } // Note that this is expensive: on every adopt, we need to set the Yoga 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 790f14638e8622..3d55f25c38cb9c 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/BaseViewProps.cpp @@ -358,20 +358,24 @@ BorderMetrics BaseViewProps::resolveBorderMetrics( bool{layoutMetrics.layoutDirection == LayoutDirection::RightToLeft}; auto borderWidths = CascadedBorderWidths{ - /* .left = */ optionalFloatFromYogaValue(yogaStyle.border(YGEdgeLeft)), - /* .top = */ optionalFloatFromYogaValue(yogaStyle.border(YGEdgeTop)), + /* .left = */ optionalFloatFromYogaValue( + yogaStyle.border(yoga::Edge::Left)), + /* .top = */ + optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Top)), /* .right = */ - optionalFloatFromYogaValue(yogaStyle.border(YGEdgeRight)), + optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Right)), /* .bottom = */ - optionalFloatFromYogaValue(yogaStyle.border(YGEdgeBottom)), + optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Bottom)), /* .start = */ - optionalFloatFromYogaValue(yogaStyle.border(YGEdgeStart)), - /* .end = */ optionalFloatFromYogaValue(yogaStyle.border(YGEdgeEnd)), + optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Start)), + /* .end = */ + optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::End)), /* .horizontal = */ - optionalFloatFromYogaValue(yogaStyle.border(YGEdgeHorizontal)), + optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Horizontal)), /* .vertical = */ - optionalFloatFromYogaValue(yogaStyle.border(YGEdgeVertical)), - /* .all = */ optionalFloatFromYogaValue(yogaStyle.border(YGEdgeAll)), + optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::Vertical)), + /* .all = */ + optionalFloatFromYogaValue(yogaStyle.border(yoga::Edge::All)), }; return { diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp index 627128b1711a87..fe11e92e1a5771 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp @@ -41,7 +41,7 @@ void ViewShadowNode::initialize() noexcept { auto hasBorder = [&]() { for (auto edge : yoga::ordinals()) { - if (viewProps.yogaStyle.border(yoga::unscopedEnum(edge)).isDefined()) { + if (viewProps.yogaStyle.border(edge).isDefined()) { return true; } } 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 ed278ac98828ba..7c531e3517db21 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -392,54 +392,54 @@ void YogaLayoutableShadowNode::updateYogaProps() { // Aliases with precedence if (props.insetInlineEnd.isDefined()) { - result.setPosition(YGEdgeEnd, props.insetInlineEnd); + result.setPosition(yoga::Edge::End, props.insetInlineEnd); } if (props.insetInlineStart.isDefined()) { - result.setPosition(YGEdgeStart, props.insetInlineStart); + result.setPosition(yoga::Edge::Start, props.insetInlineStart); } if (props.marginInline.isDefined()) { - result.setMargin(YGEdgeHorizontal, props.marginInline); + result.setMargin(yoga::Edge::Horizontal, props.marginInline); } if (props.marginInlineStart.isDefined()) { - result.setMargin(YGEdgeStart, props.marginInlineStart); + result.setMargin(yoga::Edge::Start, props.marginInlineStart); } if (props.marginInlineEnd.isDefined()) { - result.setMargin(YGEdgeEnd, props.marginInlineEnd); + result.setMargin(yoga::Edge::End, props.marginInlineEnd); } if (props.marginBlock.isDefined()) { - result.setMargin(YGEdgeVertical, props.marginBlock); + result.setMargin(yoga::Edge::Vertical, props.marginBlock); } if (props.paddingInline.isDefined()) { - result.setPadding(YGEdgeHorizontal, props.paddingInline); + result.setPadding(yoga::Edge::Horizontal, props.paddingInline); } if (props.paddingInlineStart.isDefined()) { - result.setPadding(YGEdgeStart, props.paddingInlineStart); + result.setPadding(yoga::Edge::Start, props.paddingInlineStart); } if (props.paddingInlineEnd.isDefined()) { - result.setPadding(YGEdgeEnd, props.paddingInlineEnd); + result.setPadding(yoga::Edge::End, props.paddingInlineEnd); } if (props.paddingBlock.isDefined()) { - result.setPadding(YGEdgeVertical, props.paddingBlock); + result.setPadding(yoga::Edge::Vertical, props.paddingBlock); } // Aliases without precedence - if (result.position(YGEdgeBottom).isUndefined()) { - result.setPosition(YGEdgeBottom, props.insetBlockEnd); + if (result.position(yoga::Edge::Bottom).isUndefined()) { + result.setPosition(yoga::Edge::Bottom, props.insetBlockEnd); } - if (result.position(YGEdgeTop).isUndefined()) { - result.setPosition(YGEdgeTop, props.insetBlockStart); + if (result.position(yoga::Edge::Top).isUndefined()) { + result.setPosition(yoga::Edge::Top, props.insetBlockStart); } - if (result.margin(YGEdgeTop).isUndefined()) { - result.setMargin(YGEdgeTop, props.marginBlockStart); + if (result.margin(yoga::Edge::Top).isUndefined()) { + result.setMargin(yoga::Edge::Top, props.marginBlockStart); } - if (result.margin(YGEdgeBottom).isUndefined()) { - result.setMargin(YGEdgeBottom, props.marginBlockEnd); + if (result.margin(yoga::Edge::Bottom).isUndefined()) { + result.setMargin(yoga::Edge::Bottom, props.marginBlockEnd); } - if (result.padding(YGEdgeTop).isUndefined()) { - result.setPadding(YGEdgeTop, props.paddingBlockStart); + if (result.padding(yoga::Edge::Top).isUndefined()) { + result.setPadding(yoga::Edge::Top, props.paddingBlockStart); } - if (result.padding(YGEdgeBottom).isUndefined()) { - result.setPadding(YGEdgeBottom, props.paddingBlockEnd); + if (result.padding(yoga::Edge::Bottom).isUndefined()) { + result.setPadding(yoga::Edge::Bottom, props.paddingBlockEnd); } return result; @@ -545,14 +545,14 @@ void YogaLayoutableShadowNode::setPadding(RectangleEdges padding) const { auto rightPadding = yoga::value::points(padding.right); auto bottomPadding = yoga::value::points(padding.bottom); - if (leftPadding != style.padding(YGEdgeLeft) || - topPadding != style.padding(YGEdgeTop) || - rightPadding != style.padding(YGEdgeRight) || - bottomPadding != style.padding(YGEdgeBottom)) { - style.setPadding(YGEdgeTop, yoga::value::points(padding.top)); - style.setPadding(YGEdgeLeft, yoga::value::points(padding.left)); - style.setPadding(YGEdgeRight, yoga::value::points(padding.right)); - style.setPadding(YGEdgeBottom, yoga::value::points(padding.bottom)); + if (leftPadding != style.padding(yoga::Edge::Left) || + topPadding != style.padding(yoga::Edge::Top) || + rightPadding != style.padding(yoga::Edge::Right) || + bottomPadding != style.padding(yoga::Edge::Bottom)) { + style.setPadding(yoga::Edge::Top, yoga::value::points(padding.top)); + style.setPadding(yoga::Edge::Left, yoga::value::points(padding.left)); + style.setPadding(yoga::Edge::Right, yoga::value::points(padding.right)); + style.setPadding(yoga::Edge::Bottom, yoga::value::points(padding.bottom)); yogaNode_.setStyle(style); yogaNode_.setDirty(true); } @@ -873,34 +873,37 @@ void YogaLayoutableShadowNode::swapLeftAndRightInYogaStyleProps( // Swap Yoga node values, position, padding and margin. - if (yogaStyle.position(YGEdgeLeft).isDefined()) { - yogaStyle.setPosition(YGEdgeStart, yogaStyle.position(YGEdgeLeft)); - yogaStyle.setPosition(YGEdgeLeft, yoga::value::undefined()); + if (yogaStyle.position(yoga::Edge::Left).isDefined()) { + yogaStyle.setPosition( + yoga::Edge::Start, yogaStyle.position(yoga::Edge::Left)); + yogaStyle.setPosition(yoga::Edge::Left, yoga::value::undefined()); } - if (yogaStyle.position(YGEdgeRight).isDefined()) { - yogaStyle.setPosition(YGEdgeEnd, yogaStyle.position(YGEdgeRight)); - yogaStyle.setPosition(YGEdgeRight, yoga::value::undefined()); + if (yogaStyle.position(yoga::Edge::Right).isDefined()) { + yogaStyle.setPosition( + yoga::Edge::End, yogaStyle.position(yoga::Edge::Right)); + yogaStyle.setPosition(yoga::Edge::Right, yoga::value::undefined()); } - if (yogaStyle.padding(YGEdgeLeft).isDefined()) { - yogaStyle.setPadding(YGEdgeStart, yogaStyle.padding(YGEdgeLeft)); - yogaStyle.setPadding(YGEdgeLeft, yoga::value::undefined()); + if (yogaStyle.padding(yoga::Edge::Left).isDefined()) { + yogaStyle.setPadding( + yoga::Edge::Start, yogaStyle.padding(yoga::Edge::Left)); + yogaStyle.setPadding(yoga::Edge::Left, yoga::value::undefined()); } - if (yogaStyle.padding(YGEdgeRight).isDefined()) { - yogaStyle.setPadding(YGEdgeEnd, yogaStyle.padding(YGEdgeRight)); - yogaStyle.setPadding(YGEdgeRight, yoga::value::undefined()); + if (yogaStyle.padding(yoga::Edge::Right).isDefined()) { + yogaStyle.setPadding(yoga::Edge::End, yogaStyle.padding(yoga::Edge::Right)); + yogaStyle.setPadding(yoga::Edge::Right, yoga::value::undefined()); } - if (yogaStyle.margin(YGEdgeLeft).isDefined()) { - yogaStyle.setMargin(YGEdgeStart, yogaStyle.margin(YGEdgeLeft)); - yogaStyle.setMargin(YGEdgeLeft, yoga::value::undefined()); + if (yogaStyle.margin(yoga::Edge::Left).isDefined()) { + yogaStyle.setMargin(yoga::Edge::Start, yogaStyle.margin(yoga::Edge::Left)); + yogaStyle.setMargin(yoga::Edge::Left, yoga::value::undefined()); } - if (yogaStyle.margin(YGEdgeRight).isDefined()) { - yogaStyle.setMargin(YGEdgeEnd, yogaStyle.margin(YGEdgeRight)); - yogaStyle.setMargin(YGEdgeRight, yoga::value::undefined()); + if (yogaStyle.margin(yoga::Edge::Right).isDefined()) { + yogaStyle.setMargin(yoga::Edge::End, yogaStyle.margin(yoga::Edge::Right)); + yogaStyle.setMargin(yoga::Edge::Right, yoga::value::undefined()); } shadowNode.yogaNode_.setStyle(yogaStyle); @@ -953,14 +956,16 @@ void YogaLayoutableShadowNode::swapLeftAndRightInViewProps( props.borderStyles.right.reset(); } - if (props.yogaStyle.border(YGEdgeLeft).isDefined()) { - props.yogaStyle.setBorder(YGEdgeStart, props.yogaStyle.border(YGEdgeLeft)); - props.yogaStyle.setBorder(YGEdgeLeft, yoga::value::undefined()); + if (props.yogaStyle.border(yoga::Edge::Left).isDefined()) { + props.yogaStyle.setBorder( + yoga::Edge::Start, props.yogaStyle.border(yoga::Edge::Left)); + props.yogaStyle.setBorder(yoga::Edge::Left, yoga::value::undefined()); } - if (props.yogaStyle.border(YGEdgeRight).isDefined()) { - props.yogaStyle.setBorder(YGEdgeEnd, props.yogaStyle.border(YGEdgeRight)); - props.yogaStyle.setBorder(YGEdgeRight, yoga::value::undefined()); + if (props.yogaStyle.border(yoga::Edge::Right).isDefined()) { + props.yogaStyle.setBorder( + yoga::Edge::End, props.yogaStyle.border(yoga::Edge::Right)); + props.yogaStyle.setBorder(yoga::Edge::Right, yoga::value::undefined()); } } 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 ce472496bedebe..f3bce4b95c392d 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp @@ -81,45 +81,45 @@ static inline T const getFieldValue( REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ field, setter, yoga::Gutter::All, gapStr); -#define REBUILD_FIELD_YG_EDGES(field, setter, prefix, suffix) \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeLeft, prefix "Left" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeTop, prefix "Top" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeRight, prefix "Right" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeBottom, prefix "Bottom" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeStart, prefix "Start" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeEnd, prefix "End" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeHorizontal, prefix "Horizontal" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeVertical, prefix "Vertical" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, YGEdgeAll, prefix "" suffix); +#define REBUILD_FIELD_YG_EDGES(field, setter, prefix, suffix) \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::Left, prefix "Left" suffix); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::Top, prefix "Top" suffix); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::Right, prefix "Right" suffix); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::Bottom, prefix "Bottom" suffix); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::Start, prefix "Start" suffix); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::End, prefix "End" suffix); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::Horizontal, prefix "Horizontal" suffix); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::Vertical, prefix "Vertical" suffix); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + field, setter, yoga::Edge::All, prefix "" suffix); -#define REBUILD_FIELD_YG_EDGES_POSITION() \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeLeft, "left"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeTop, "top"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeRight, "right"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeBottom, "bottom"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeStart, "start"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeEnd, "end"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeHorizontal, "insetInline"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeVertical, "insetBlock"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, YGEdgeAll, "inset"); +#define REBUILD_FIELD_YG_EDGES_POSITION() \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::Left, "left"); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::Top, "top"); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::Right, "right"); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::Bottom, "bottom"); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::Start, "start"); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::End, "end"); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::Horizontal, "insetInline"); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::Vertical, "insetBlock"); \ + REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ + position, setPosition, yoga::Edge::All, "inset"); void YogaStylableProps::setProp( const PropsParserContext& context, @@ -234,148 +234,148 @@ SharedDebugStringConvertibleList YogaStylableProps::getDebugProps() const { "flexBasis", yogaStyle.flexBasis(), defaultYogaStyle.flexBasis()), debugStringConvertibleItem( "marginLeft", - yogaStyle.margin(YGEdgeLeft), - defaultYogaStyle.margin(YGEdgeLeft)), + yogaStyle.margin(yoga::Edge::Left), + defaultYogaStyle.margin(yoga::Edge::Left)), debugStringConvertibleItem( "marginTop", - yogaStyle.margin(YGEdgeTop), - defaultYogaStyle.margin(YGEdgeTop)), + yogaStyle.margin(yoga::Edge::Top), + defaultYogaStyle.margin(yoga::Edge::Top)), debugStringConvertibleItem( "marginRight", - yogaStyle.margin(YGEdgeRight), - defaultYogaStyle.margin(YGEdgeRight)), + yogaStyle.margin(yoga::Edge::Right), + defaultYogaStyle.margin(yoga::Edge::Right)), debugStringConvertibleItem( "marginBottom", - yogaStyle.margin(YGEdgeBottom), - defaultYogaStyle.margin(YGEdgeBottom)), + yogaStyle.margin(yoga::Edge::Bottom), + defaultYogaStyle.margin(yoga::Edge::Bottom)), debugStringConvertibleItem( "marginStart", - yogaStyle.margin(YGEdgeStart), - defaultYogaStyle.margin(YGEdgeStart)), + yogaStyle.margin(yoga::Edge::Start), + defaultYogaStyle.margin(yoga::Edge::Start)), debugStringConvertibleItem( "marginEnd", - yogaStyle.margin(YGEdgeEnd), - defaultYogaStyle.margin(YGEdgeEnd)), + yogaStyle.margin(yoga::Edge::End), + defaultYogaStyle.margin(yoga::Edge::End)), debugStringConvertibleItem( "marginHorizontal", - yogaStyle.margin(YGEdgeHorizontal), - defaultYogaStyle.margin(YGEdgeHorizontal)), + yogaStyle.margin(yoga::Edge::Horizontal), + defaultYogaStyle.margin(yoga::Edge::Horizontal)), debugStringConvertibleItem( "marginVertical", - yogaStyle.margin(YGEdgeVertical), - defaultYogaStyle.margin(YGEdgeVertical)), + yogaStyle.margin(yoga::Edge::Vertical), + defaultYogaStyle.margin(yoga::Edge::Vertical)), debugStringConvertibleItem( "margin", - yogaStyle.margin(YGEdgeAll), - defaultYogaStyle.margin(YGEdgeAll)), + yogaStyle.margin(yoga::Edge::All), + defaultYogaStyle.margin(yoga::Edge::All)), debugStringConvertibleItem( "left", - yogaStyle.position(YGEdgeLeft), - defaultYogaStyle.position(YGEdgeLeft)), + yogaStyle.position(yoga::Edge::Left), + defaultYogaStyle.position(yoga::Edge::Left)), debugStringConvertibleItem( "top", - yogaStyle.position(YGEdgeTop), - defaultYogaStyle.position(YGEdgeTop)), + yogaStyle.position(yoga::Edge::Top), + defaultYogaStyle.position(yoga::Edge::Top)), debugStringConvertibleItem( "right", - yogaStyle.position(YGEdgeRight), - defaultYogaStyle.position(YGEdgeRight)), + yogaStyle.position(yoga::Edge::Right), + defaultYogaStyle.position(yoga::Edge::Right)), debugStringConvertibleItem( "bottom", - yogaStyle.position(YGEdgeBottom), - defaultYogaStyle.position(YGEdgeBottom)), + yogaStyle.position(yoga::Edge::Bottom), + defaultYogaStyle.position(yoga::Edge::Bottom)), debugStringConvertibleItem( "start", - yogaStyle.position(YGEdgeStart), - defaultYogaStyle.position(YGEdgeStart)), + yogaStyle.position(yoga::Edge::Start), + defaultYogaStyle.position(yoga::Edge::Start)), debugStringConvertibleItem( "end", - yogaStyle.position(YGEdgeEnd), - defaultYogaStyle.position(YGEdgeEnd)), + yogaStyle.position(yoga::Edge::End), + defaultYogaStyle.position(yoga::Edge::End)), debugStringConvertibleItem( "inseInline", - yogaStyle.position(YGEdgeHorizontal), - defaultYogaStyle.position(YGEdgeHorizontal)), + yogaStyle.position(yoga::Edge::Horizontal), + defaultYogaStyle.position(yoga::Edge::Horizontal)), debugStringConvertibleItem( "insetBlock", - yogaStyle.position(YGEdgeVertical), - defaultYogaStyle.position(YGEdgeVertical)), + yogaStyle.position(yoga::Edge::Vertical), + defaultYogaStyle.position(yoga::Edge::Vertical)), debugStringConvertibleItem( "inset", - yogaStyle.position(YGEdgeAll), - defaultYogaStyle.position(YGEdgeAll)), + yogaStyle.position(yoga::Edge::All), + defaultYogaStyle.position(yoga::Edge::All)), debugStringConvertibleItem( "paddingLeft", - yogaStyle.padding(YGEdgeLeft), - defaultYogaStyle.padding(YGEdgeLeft)), + yogaStyle.padding(yoga::Edge::Left), + defaultYogaStyle.padding(yoga::Edge::Left)), debugStringConvertibleItem( "paddingTop", - yogaStyle.padding(YGEdgeTop), - defaultYogaStyle.padding(YGEdgeTop)), + yogaStyle.padding(yoga::Edge::Top), + defaultYogaStyle.padding(yoga::Edge::Top)), debugStringConvertibleItem( "paddingRight", - yogaStyle.padding(YGEdgeRight), - defaultYogaStyle.padding(YGEdgeRight)), + yogaStyle.padding(yoga::Edge::Right), + defaultYogaStyle.padding(yoga::Edge::Right)), debugStringConvertibleItem( "paddingBottom", - yogaStyle.padding(YGEdgeBottom), - defaultYogaStyle.padding(YGEdgeBottom)), + yogaStyle.padding(yoga::Edge::Bottom), + defaultYogaStyle.padding(yoga::Edge::Bottom)), debugStringConvertibleItem( "paddingStart", - yogaStyle.padding(YGEdgeStart), - defaultYogaStyle.padding(YGEdgeStart)), + yogaStyle.padding(yoga::Edge::Start), + defaultYogaStyle.padding(yoga::Edge::Start)), debugStringConvertibleItem( "paddingEnd", - yogaStyle.padding(YGEdgeEnd), - defaultYogaStyle.padding(YGEdgeEnd)), + yogaStyle.padding(yoga::Edge::End), + defaultYogaStyle.padding(yoga::Edge::End)), debugStringConvertibleItem( "paddingHorizontal", - yogaStyle.padding(YGEdgeHorizontal), - defaultYogaStyle.padding(YGEdgeHorizontal)), + yogaStyle.padding(yoga::Edge::Horizontal), + defaultYogaStyle.padding(yoga::Edge::Horizontal)), debugStringConvertibleItem( "paddingVertical", - yogaStyle.padding(YGEdgeVertical), - defaultYogaStyle.padding(YGEdgeVertical)), + yogaStyle.padding(yoga::Edge::Vertical), + defaultYogaStyle.padding(yoga::Edge::Vertical)), debugStringConvertibleItem( "padding", - yogaStyle.padding(YGEdgeAll), - defaultYogaStyle.padding(YGEdgeAll)), + yogaStyle.padding(yoga::Edge::All), + defaultYogaStyle.padding(yoga::Edge::All)), debugStringConvertibleItem( "borderLeftWidth", - yogaStyle.border(YGEdgeLeft), - defaultYogaStyle.border(YGEdgeLeft)), + yogaStyle.border(yoga::Edge::Left), + defaultYogaStyle.border(yoga::Edge::Left)), debugStringConvertibleItem( "borderTopWidth", - yogaStyle.border(YGEdgeTop), - defaultYogaStyle.border(YGEdgeTop)), + yogaStyle.border(yoga::Edge::Top), + defaultYogaStyle.border(yoga::Edge::Top)), debugStringConvertibleItem( "borderRightWidth", - yogaStyle.border(YGEdgeRight), - defaultYogaStyle.border(YGEdgeRight)), + yogaStyle.border(yoga::Edge::Right), + defaultYogaStyle.border(yoga::Edge::Right)), debugStringConvertibleItem( "borderBottomWidth", - yogaStyle.border(YGEdgeBottom), - defaultYogaStyle.border(YGEdgeBottom)), + yogaStyle.border(yoga::Edge::Bottom), + defaultYogaStyle.border(yoga::Edge::Bottom)), debugStringConvertibleItem( "borderStartWidth", - yogaStyle.border(YGEdgeStart), - defaultYogaStyle.border(YGEdgeStart)), + yogaStyle.border(yoga::Edge::Start), + defaultYogaStyle.border(yoga::Edge::Start)), debugStringConvertibleItem( "borderEndWidth", - yogaStyle.border(YGEdgeEnd), - defaultYogaStyle.border(YGEdgeEnd)), + yogaStyle.border(yoga::Edge::End), + defaultYogaStyle.border(yoga::Edge::End)), debugStringConvertibleItem( "borderHorizontalWidth", - yogaStyle.border(YGEdgeHorizontal), - defaultYogaStyle.border(YGEdgeHorizontal)), + yogaStyle.border(yoga::Edge::Horizontal), + defaultYogaStyle.border(yoga::Edge::Horizontal)), debugStringConvertibleItem( "borderVerticalWidth", - yogaStyle.border(YGEdgeVertical), - defaultYogaStyle.border(YGEdgeVertical)), + yogaStyle.border(yoga::Edge::Vertical), + defaultYogaStyle.border(yoga::Edge::Vertical)), debugStringConvertibleItem( "bordeWidth", - yogaStyle.border(YGEdgeAll), - defaultYogaStyle.border(YGEdgeAll)), + yogaStyle.border(yoga::Edge::All), + defaultYogaStyle.border(yoga::Edge::All)), debugStringConvertibleItem( "width", yogaStyle.dimension(yoga::Dimension::Width), diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.cpp index f23fccf8913738..20474d7ec37a4f 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.cpp @@ -16,25 +16,33 @@ namespace facebook::react { MapBuffer convertBorderWidths(const yoga::Style& style) { MapBufferBuilder builder(7); putOptionalFloat( - builder, EDGE_TOP, optionalFloatFromYogaValue(style.border(YGEdgeTop))); + builder, + EDGE_TOP, + optionalFloatFromYogaValue(style.border(yoga::Edge::Top))); putOptionalFloat( builder, EDGE_RIGHT, - optionalFloatFromYogaValue(style.border(YGEdgeRight))); + optionalFloatFromYogaValue(style.border(yoga::Edge::Right))); putOptionalFloat( builder, EDGE_BOTTOM, - optionalFloatFromYogaValue(style.border(YGEdgeBottom))); + optionalFloatFromYogaValue(style.border(yoga::Edge::Bottom))); putOptionalFloat( - builder, EDGE_LEFT, optionalFloatFromYogaValue(style.border(YGEdgeLeft))); + builder, + EDGE_LEFT, + optionalFloatFromYogaValue(style.border(yoga::Edge::Left))); putOptionalFloat( builder, EDGE_START, - optionalFloatFromYogaValue(style.border(YGEdgeStart))); + optionalFloatFromYogaValue(style.border(yoga::Edge::Start))); putOptionalFloat( - builder, EDGE_END, optionalFloatFromYogaValue(style.border(YGEdgeEnd))); + builder, + EDGE_END, + optionalFloatFromYogaValue(style.border(yoga::Edge::End))); putOptionalFloat( - builder, EDGE_ALL, optionalFloatFromYogaValue(style.border(YGEdgeAll))); + builder, + EDGE_ALL, + optionalFloatFromYogaValue(style.border(yoga::Edge::All))); return builder.build(); } @@ -62,8 +70,7 @@ void YogaStylableProps::propsDiffMapBuffer( bool areBordersEqual = true; for (auto edge : yoga::ordinals()) { - if (oldStyle.border(yoga::unscopedEnum(edge)) != - newStyle.border(yoga::unscopedEnum(edge))) { + if (oldStyle.border(edge) != newStyle.border(edge)) { areBordersEqual = false; break; } 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 13af58193c4289..529f3236454a2f 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h @@ -101,247 +101,247 @@ static inline yoga::Style convertRawProp( yogaStyle.flexBasis()); yogaStyle.setMargin( - YGEdgeLeft, + yoga::Edge::Left, convertRawProp( context, rawProps, "marginLeft", - sourceValue.margin(YGEdgeLeft), - yogaStyle.margin(YGEdgeLeft))); + sourceValue.margin(yoga::Edge::Left), + yogaStyle.margin(yoga::Edge::Left))); yogaStyle.setMargin( - YGEdgeTop, + yoga::Edge::Top, convertRawProp( context, rawProps, "marginTop", - sourceValue.margin(YGEdgeTop), - yogaStyle.margin(YGEdgeTop))); + sourceValue.margin(yoga::Edge::Top), + yogaStyle.margin(yoga::Edge::Top))); yogaStyle.setMargin( - YGEdgeRight, + yoga::Edge::Right, convertRawProp( context, rawProps, "marginRight", - sourceValue.margin(YGEdgeRight), - yogaStyle.margin(YGEdgeRight))); + sourceValue.margin(yoga::Edge::Right), + yogaStyle.margin(yoga::Edge::Right))); yogaStyle.setMargin( - YGEdgeBottom, + yoga::Edge::Bottom, convertRawProp( context, rawProps, "marginBottom", - sourceValue.margin(YGEdgeBottom), - yogaStyle.margin(YGEdgeBottom))); + sourceValue.margin(yoga::Edge::Bottom), + yogaStyle.margin(yoga::Edge::Bottom))); yogaStyle.setMargin( - YGEdgeStart, + yoga::Edge::Start, convertRawProp( context, rawProps, "marginStart", - sourceValue.margin(YGEdgeStart), - yogaStyle.margin(YGEdgeStart))); + sourceValue.margin(yoga::Edge::Start), + yogaStyle.margin(yoga::Edge::Start))); yogaStyle.setMargin( - YGEdgeEnd, + yoga::Edge::End, convertRawProp( context, rawProps, "marginEnd", - sourceValue.margin(YGEdgeEnd), - yogaStyle.margin(YGEdgeEnd))); + sourceValue.margin(yoga::Edge::End), + yogaStyle.margin(yoga::Edge::End))); yogaStyle.setMargin( - YGEdgeHorizontal, + yoga::Edge::Horizontal, convertRawProp( context, rawProps, "marginHorizontal", - sourceValue.margin(YGEdgeHorizontal), - yogaStyle.margin(YGEdgeHorizontal))); + sourceValue.margin(yoga::Edge::Horizontal), + yogaStyle.margin(yoga::Edge::Horizontal))); yogaStyle.setMargin( - YGEdgeVertical, + yoga::Edge::Vertical, convertRawProp( context, rawProps, "marginVertical", - sourceValue.margin(YGEdgeVertical), - yogaStyle.margin(YGEdgeVertical))); + sourceValue.margin(yoga::Edge::Vertical), + yogaStyle.margin(yoga::Edge::Vertical))); yogaStyle.setMargin( - YGEdgeAll, + yoga::Edge::All, convertRawProp( context, rawProps, "margin", - sourceValue.margin(YGEdgeAll), - yogaStyle.margin(YGEdgeAll))); + sourceValue.margin(yoga::Edge::All), + yogaStyle.margin(yoga::Edge::All))); yogaStyle.setPosition( - YGEdgeLeft, + yoga::Edge::Left, convertRawProp( context, rawProps, "left", - sourceValue.position(YGEdgeLeft), - yogaStyle.position(YGEdgeLeft))); + sourceValue.position(yoga::Edge::Left), + yogaStyle.position(yoga::Edge::Left))); yogaStyle.setPosition( - YGEdgeTop, + yoga::Edge::Top, convertRawProp( context, rawProps, "top", - sourceValue.position(YGEdgeTop), - yogaStyle.position(YGEdgeTop))); + sourceValue.position(yoga::Edge::Top), + yogaStyle.position(yoga::Edge::Top))); yogaStyle.setPosition( - YGEdgeRight, + yoga::Edge::Right, convertRawProp( context, rawProps, "right", - sourceValue.position(YGEdgeRight), - yogaStyle.position(YGEdgeRight))); + sourceValue.position(yoga::Edge::Right), + yogaStyle.position(yoga::Edge::Right))); yogaStyle.setPosition( - YGEdgeBottom, + yoga::Edge::Bottom, convertRawProp( context, rawProps, "bottom", - sourceValue.position(YGEdgeBottom), - yogaStyle.position(YGEdgeBottom))); + sourceValue.position(yoga::Edge::Bottom), + yogaStyle.position(yoga::Edge::Bottom))); yogaStyle.setPosition( - YGEdgeStart, + yoga::Edge::Start, convertRawProp( context, rawProps, "start", - sourceValue.position(YGEdgeStart), - yogaStyle.position(YGEdgeStart))); + sourceValue.position(yoga::Edge::Start), + yogaStyle.position(yoga::Edge::Start))); yogaStyle.setPosition( - YGEdgeEnd, + yoga::Edge::End, convertRawProp( context, rawProps, "end", - sourceValue.position(YGEdgeEnd), - yogaStyle.position(YGEdgeEnd))); + sourceValue.position(yoga::Edge::End), + yogaStyle.position(yoga::Edge::End))); yogaStyle.setPosition( - YGEdgeHorizontal, + yoga::Edge::Horizontal, convertRawProp( context, rawProps, "insetInline", - sourceValue.position(YGEdgeHorizontal), - yogaStyle.position(YGEdgeHorizontal))); + sourceValue.position(yoga::Edge::Horizontal), + yogaStyle.position(yoga::Edge::Horizontal))); yogaStyle.setPosition( - YGEdgeVertical, + yoga::Edge::Vertical, convertRawProp( context, rawProps, "insetBlock", - sourceValue.position(YGEdgeVertical), - yogaStyle.position(YGEdgeVertical))); + sourceValue.position(yoga::Edge::Vertical), + yogaStyle.position(yoga::Edge::Vertical))); yogaStyle.setPosition( - YGEdgeAll, + yoga::Edge::All, convertRawProp( context, rawProps, "inset", - sourceValue.position(YGEdgeAll), - yogaStyle.position(YGEdgeAll))); + sourceValue.position(yoga::Edge::All), + yogaStyle.position(yoga::Edge::All))); yogaStyle.setPadding( - YGEdgeLeft, + yoga::Edge::Left, convertRawProp( context, rawProps, "paddingLeft", - sourceValue.padding(YGEdgeLeft), - yogaStyle.padding(YGEdgeLeft))); + sourceValue.padding(yoga::Edge::Left), + yogaStyle.padding(yoga::Edge::Left))); yogaStyle.setPadding( - YGEdgeTop, + yoga::Edge::Top, convertRawProp( context, rawProps, "paddingTop", - sourceValue.padding(YGEdgeTop), - yogaStyle.padding(YGEdgeTop))); + sourceValue.padding(yoga::Edge::Top), + yogaStyle.padding(yoga::Edge::Top))); yogaStyle.setPadding( - YGEdgeRight, + yoga::Edge::Right, convertRawProp( context, rawProps, "paddingRight", - sourceValue.padding(YGEdgeRight), - yogaStyle.padding(YGEdgeRight))); + sourceValue.padding(yoga::Edge::Right), + yogaStyle.padding(yoga::Edge::Right))); yogaStyle.setPadding( - YGEdgeBottom, + yoga::Edge::Bottom, convertRawProp( context, rawProps, "paddingBottom", - sourceValue.padding(YGEdgeBottom), - yogaStyle.padding(YGEdgeBottom))); + sourceValue.padding(yoga::Edge::Bottom), + yogaStyle.padding(yoga::Edge::Bottom))); yogaStyle.setPadding( - YGEdgeStart, + yoga::Edge::Start, convertRawProp( context, rawProps, "paddingStart", - sourceValue.padding(YGEdgeStart), - yogaStyle.padding(YGEdgeStart))); + sourceValue.padding(yoga::Edge::Start), + yogaStyle.padding(yoga::Edge::Start))); yogaStyle.setPadding( - YGEdgeEnd, + yoga::Edge::End, convertRawProp( context, rawProps, "paddingEnd", - sourceValue.padding(YGEdgeEnd), - yogaStyle.padding(YGEdgeEnd))); + sourceValue.padding(yoga::Edge::End), + yogaStyle.padding(yoga::Edge::End))); yogaStyle.setPadding( - YGEdgeHorizontal, + yoga::Edge::Horizontal, convertRawProp( context, rawProps, "paddingHorizontal", - sourceValue.padding(YGEdgeHorizontal), - yogaStyle.padding(YGEdgeHorizontal))); + sourceValue.padding(yoga::Edge::Horizontal), + yogaStyle.padding(yoga::Edge::Horizontal))); yogaStyle.setPadding( - YGEdgeVertical, + yoga::Edge::Vertical, convertRawProp( context, rawProps, "paddingVertical", - sourceValue.padding(YGEdgeVertical), - yogaStyle.padding(YGEdgeVertical))); + sourceValue.padding(yoga::Edge::Vertical), + yogaStyle.padding(yoga::Edge::Vertical))); yogaStyle.setPadding( - YGEdgeAll, + yoga::Edge::All, convertRawProp( context, rawProps, "padding", - sourceValue.padding(YGEdgeAll), - yogaStyle.padding(YGEdgeAll))); + sourceValue.padding(yoga::Edge::All), + yogaStyle.padding(yoga::Edge::All))); yogaStyle.setGap( yoga::Gutter::Row, @@ -371,85 +371,85 @@ static inline yoga::Style convertRawProp( yogaStyle.gap(yoga::Gutter::All))); yogaStyle.setBorder( - YGEdgeLeft, + yoga::Edge::Left, convertRawProp( context, rawProps, "borderLeftWidth", - sourceValue.border(YGEdgeLeft), - yogaStyle.border(YGEdgeLeft))); + sourceValue.border(yoga::Edge::Left), + yogaStyle.border(yoga::Edge::Left))); yogaStyle.setBorder( - YGEdgeTop, + yoga::Edge::Top, convertRawProp( context, rawProps, "borderTopWidth", - sourceValue.border(YGEdgeTop), - yogaStyle.border(YGEdgeTop))); + sourceValue.border(yoga::Edge::Top), + yogaStyle.border(yoga::Edge::Top))); yogaStyle.setBorder( - YGEdgeRight, + yoga::Edge::Right, convertRawProp( context, rawProps, "borderRightWidth", - sourceValue.border(YGEdgeRight), - yogaStyle.border(YGEdgeRight))); + sourceValue.border(yoga::Edge::Right), + yogaStyle.border(yoga::Edge::Right))); yogaStyle.setBorder( - YGEdgeBottom, + yoga::Edge::Bottom, convertRawProp( context, rawProps, "borderBottomWidth", - sourceValue.border(YGEdgeBottom), - yogaStyle.border(YGEdgeBottom))); + sourceValue.border(yoga::Edge::Bottom), + yogaStyle.border(yoga::Edge::Bottom))); yogaStyle.setBorder( - YGEdgeStart, + yoga::Edge::Start, convertRawProp( context, rawProps, "borderStartWidth", - sourceValue.border(YGEdgeStart), - yogaStyle.border(YGEdgeStart))); + sourceValue.border(yoga::Edge::Start), + yogaStyle.border(yoga::Edge::Start))); yogaStyle.setBorder( - YGEdgeEnd, + yoga::Edge::End, convertRawProp( context, rawProps, "borderEndWidth", - sourceValue.border(YGEdgeEnd), - yogaStyle.border(YGEdgeEnd))); + sourceValue.border(yoga::Edge::End), + yogaStyle.border(yoga::Edge::End))); yogaStyle.setBorder( - YGEdgeHorizontal, + yoga::Edge::Horizontal, convertRawProp( context, rawProps, "borderHorizontalWidth", - sourceValue.border(YGEdgeHorizontal), - yogaStyle.border(YGEdgeHorizontal))); + sourceValue.border(yoga::Edge::Horizontal), + yogaStyle.border(yoga::Edge::Horizontal))); yogaStyle.setBorder( - YGEdgeVertical, + yoga::Edge::Vertical, convertRawProp( context, rawProps, "borderVerticalWidth", - sourceValue.border(YGEdgeVertical), - yogaStyle.border(YGEdgeVertical))); + sourceValue.border(yoga::Edge::Vertical), + yogaStyle.border(yoga::Edge::Vertical))); yogaStyle.setBorder( - YGEdgeAll, + yoga::Edge::All, convertRawProp( context, rawProps, "borderWidth", - sourceValue.border(YGEdgeAll), - yogaStyle.border(YGEdgeAll))); + sourceValue.border(yoga::Edge::All), + yogaStyle.border(yoga::Edge::All))); yogaStyle.setDimension( yoga::Dimension::Width, 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 5e44e2d5044293..bdb879a974598e 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 @@ -103,8 +103,8 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(10)); - yogaStyle.setPosition(YGEdgeTop, yoga::value::points(10)); + 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)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(90)); @@ -136,8 +136,8 @@ class LayoutTest : public ::testing::Test { } yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(10)); - yogaStyle.setPosition(YGEdgeTop, yoga::value::points(10)); + 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)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(20)); return sharedProps; @@ -151,8 +151,8 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(70)); - yogaStyle.setPosition(YGEdgeTop, yoga::value::points(-50)); + 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)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(60)); return sharedProps; @@ -166,8 +166,8 @@ class LayoutTest : public ::testing::Test { auto &props = *sharedProps; auto &yogaStyle = props.yogaStyle; yogaStyle.positionType() = yoga::PositionType::Absolute; - yogaStyle.setPosition(YGEdgeLeft, yoga::value::points(-60)); - yogaStyle.setPosition(YGEdgeTop, yoga::value::points(50)); + 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)); yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(20)); return sharedProps; 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 ae64dd3393dc34..f09dabda6d332e 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp @@ -251,8 +251,8 @@ TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) { mutateViewShadowNodeProps_(nodeAA_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.setPadding(YGEdgeAll, yoga::value::points(42)); - yogaStyle.setMargin(YGEdgeAll, yoga::value::points(42)); + yogaStyle.setPadding(yoga::Edge::All, yoga::value::points(42)); + yogaStyle.setMargin(yoga::Edge::All, yoga::value::points(42)); yogaStyle.positionType() = yoga::PositionType::Absolute; props.shadowRadius = 42; props.shadowOffset = Size{42, 42}; @@ -262,7 +262,7 @@ TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) { mutateViewShadowNodeProps_(nodeBA_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; props.zIndex = 42; - yogaStyle.setMargin(YGEdgeAll, yoga::value::points(42)); + yogaStyle.setMargin(yoga::Edge::All, yoga::value::points(42)); props.shadowColor = clearColor(); props.shadowOpacity = 0.42; }); diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNodeLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGNodeLayout.cpp index 39f67f9dc9792b..d2477f72cf21f2 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNodeLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNodeLayout.cpp @@ -7,6 +7,7 @@ #include #include +#include #include using namespace facebook; @@ -15,50 +16,48 @@ using namespace facebook::yoga; namespace { template -float getResolvedLayoutProperty( - const YGNodeConstRef nodeRef, - const YGEdge edge) { +float getResolvedLayoutProperty(const YGNodeConstRef nodeRef, const Edge edge) { const auto node = resolveRef(nodeRef); yoga::assertFatalWithNode( node, - edge <= YGEdgeEnd, + edge <= Edge::End, "Cannot get layout properties of multi-edge shorthands"); - if (edge == YGEdgeStart) { + if (edge == Edge::Start) { if (node->getLayout().direction() == Direction::RTL) { - return (node->getLayout().*LayoutMember)[YGEdgeRight]; + return (node->getLayout().*LayoutMember)(Edge::Right); } else { - return (node->getLayout().*LayoutMember)[YGEdgeLeft]; + return (node->getLayout().*LayoutMember)(Edge::Left); } } - if (edge == YGEdgeEnd) { + if (edge == Edge::End) { if (node->getLayout().direction() == Direction::RTL) { - return (node->getLayout().*LayoutMember)[YGEdgeLeft]; + return (node->getLayout().*LayoutMember)(Edge::Left); } else { - return (node->getLayout().*LayoutMember)[YGEdgeRight]; + return (node->getLayout().*LayoutMember)(Edge::Right); } } - return (node->getLayout().*LayoutMember)[edge]; + return (node->getLayout().*LayoutMember)(edge); } } // namespace float YGNodeLayoutGetLeft(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().position[YGEdgeLeft]; + return resolveRef(node)->getLayout().position(Edge::Left); } float YGNodeLayoutGetTop(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().position[YGEdgeTop]; + return resolveRef(node)->getLayout().position(Edge::Top); } float YGNodeLayoutGetRight(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().position[YGEdgeRight]; + return resolveRef(node)->getLayout().position(Edge::Right); } float YGNodeLayoutGetBottom(const YGNodeConstRef node) { - return resolveRef(node)->getLayout().position[YGEdgeBottom]; + return resolveRef(node)->getLayout().position(Edge::Bottom); } float YGNodeLayoutGetWidth(const YGNodeConstRef node) { @@ -78,13 +77,16 @@ bool YGNodeLayoutGetHadOverflow(const YGNodeConstRef node) { } float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge) { - return getResolvedLayoutProperty<&LayoutResults::margin>(node, edge); + return getResolvedLayoutProperty<&LayoutResults::margin>( + node, scopedEnum(edge)); } float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge) { - return getResolvedLayoutProperty<&LayoutResults::border>(node, edge); + return getResolvedLayoutProperty<&LayoutResults::border>( + node, scopedEnum(edge)); } float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge) { - return getResolvedLayoutProperty<&LayoutResults::padding>(node, edge); + return getResolvedLayoutProperty<&LayoutResults::padding>( + node, scopedEnum(edge)); } diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp index 6767e5e8e31969..c39372a33ac10c 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNodeStyle.cpp @@ -223,49 +223,49 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) { updateIndexedStyleProp<&Style::position, &Style::setPosition>( - node, edge, value::points(points)); + node, scopedEnum(edge), value::points(points)); } void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) { updateIndexedStyleProp<&Style::position, &Style::setPosition>( - node, edge, value::percent(percent)); + node, scopedEnum(edge), value::percent(percent)); } YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { - return resolveRef(node)->getStyle().position(edge); + return resolveRef(node)->getStyle().position(scopedEnum(edge)); } void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) { updateIndexedStyleProp<&Style::margin, &Style::setMargin>( - node, edge, value::points(points)); + node, scopedEnum(edge), value::points(points)); } void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) { updateIndexedStyleProp<&Style::margin, &Style::setMargin>( - node, edge, value::percent(percent)); + node, scopedEnum(edge), value::percent(percent)); } void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { updateIndexedStyleProp<&Style::margin, &Style::setMargin>( - node, edge, value::ofAuto()); + node, scopedEnum(edge), value::ofAuto()); } YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { - return resolveRef(node)->getStyle().margin(edge); + return resolveRef(node)->getStyle().margin(scopedEnum(edge)); } void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) { updateIndexedStyleProp<&Style::padding, &Style::setPadding>( - node, edge, value::points(points)); + node, scopedEnum(edge), value::points(points)); } void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) { updateIndexedStyleProp<&Style::padding, &Style::setPadding>( - node, edge, value::percent(percent)); + node, scopedEnum(edge), value::percent(percent)); } YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { - return resolveRef(node)->getStyle().padding(edge); + return resolveRef(node)->getStyle().padding(scopedEnum(edge)); } void YGNodeStyleSetBorder( @@ -273,11 +273,11 @@ void YGNodeStyleSetBorder( const YGEdge edge, const float border) { updateIndexedStyleProp<&Style::border, &Style::setBorder>( - node, edge, value::points(border)); + node, scopedEnum(edge), value::points(border)); } float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) { - auto border = resolveRef(node)->getStyle().border(edge); + auto border = resolveRef(node)->getStyle().border(scopedEnum(edge)); if (border.isUndefined() || border.isAuto()) { return YGUndefined; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp index aea316c03526f7..a86b9b28a48db1 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp @@ -57,7 +57,7 @@ float calculateBaseline(const yoga::Node* node) { } const float baseline = calculateBaseline(baselineChild); - return baseline + baselineChild->getLayout().position[YGEdgeTop]; + return baseline + baselineChild->getLayout().position(Edge::Top); } bool isBaselineLayout(const yoga::Node* node) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index f066dbdfc45213..fe97b4e1166482 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -89,7 +89,7 @@ static void setChildTrailingPosition( const float size = child->getLayout().measuredDimension(dimension(axis)); child->setLayoutPosition( node->getLayout().measuredDimension(dimension(axis)) - size - - child->getLayout().position[flexStartEdge(axis)], + child->getLayout().position(flexStartEdge(axis)), flexEndEdge(axis)); } @@ -553,12 +553,13 @@ static void measureNodeWithMeasureFunc( availableHeight = YGUndefined; } - const auto& padding = node->getLayout().padding; - const auto& border = node->getLayout().border; - const float paddingAndBorderAxisRow = padding[YGEdgeLeft] + - padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight]; - const float paddingAndBorderAxisColumn = padding[YGEdgeTop] + - padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom]; + const auto& layout = node->getLayout(); + const float paddingAndBorderAxisRow = layout.padding(Edge::Left) + + layout.padding(Edge::Right) + layout.border(Edge::Left) + + layout.border(Edge::Right); + const float paddingAndBorderAxisColumn = layout.padding(Edge::Top) + + layout.padding(Edge::Bottom) + layout.border(Edge::Top) + + layout.border(Edge::Bottom); // We want to make sure we don't call measure with negative size const float innerWidth = yoga::isUndefined(availableWidth) @@ -643,14 +644,13 @@ static void measureNodeWithoutChildren( const SizingMode heightSizingMode, const float ownerWidth, const float ownerHeight) { - const auto& padding = node->getLayout().padding; - const auto& border = node->getLayout().border; + const auto& layout = node->getLayout(); float width = availableWidth; if (widthSizingMode == SizingMode::MaxContent || widthSizingMode == SizingMode::FitContent) { - width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + - border[YGEdgeRight]; + width = layout.padding(Edge::Left) + layout.padding(Edge::Right) + + layout.border(Edge::Left) + layout.border(Edge::Right); } node->setLayoutMeasuredDimension( boundAxis(node, FlexDirection::Row, width, ownerWidth, ownerWidth), @@ -659,8 +659,8 @@ static void measureNodeWithoutChildren( float height = availableHeight; if (heightSizingMode == SizingMode::MaxContent || heightSizingMode == SizingMode::FitContent) { - height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + - border[YGEdgeBottom]; + height = layout.padding(Edge::Top) + layout.padding(Edge::Bottom) + + layout.border(Edge::Top) + layout.border(Edge::Bottom); } node->setLayoutMeasuredDimension( boundAxis(node, FlexDirection::Column, height, ownerHeight, ownerWidth), @@ -1330,7 +1330,7 @@ static void justifyMainAxis( if (performLayout) { child->setLayoutPosition( - childLayout.position[flexStartEdge(mainAxis)] + + childLayout.position(flexStartEdge(mainAxis)) + flexLine.layout.mainDim, flexStartEdge(mainAxis)); } @@ -1386,7 +1386,7 @@ static void justifyMainAxis( } } else if (performLayout) { child->setLayoutPosition( - childLayout.position[flexStartEdge(mainAxis)] + + childLayout.position(flexStartEdge(mainAxis)) + node->getInlineStartBorder(mainAxis, direction) + leadingMainDim, flexStartEdge(mainAxis)); @@ -1497,9 +1497,8 @@ static void calculateLayoutImpl( const FlexDirection flexColumnDirection = resolveDirection(FlexDirection::Column, direction); - const YGEdge startEdge = - direction == Direction::LTR ? YGEdgeLeft : YGEdgeRight; - const YGEdge endEdge = direction == Direction::LTR ? YGEdgeRight : YGEdgeLeft; + const Edge startEdge = direction == Direction::LTR ? Edge::Left : Edge::Right; + const Edge endEdge = direction == Direction::LTR ? Edge::Right : Edge::Left; const float marginRowLeading = node->getInlineStartMargin(flexRowDirection, direction, ownerWidth); @@ -1509,10 +1508,10 @@ static void calculateLayoutImpl( node->setLayoutMargin(marginRowTrailing, endEdge); const float marginColumnLeading = node->getInlineStartMargin(flexColumnDirection, direction, ownerWidth); - node->setLayoutMargin(marginColumnLeading, YGEdgeTop); + node->setLayoutMargin(marginColumnLeading, Edge::Top); const float marginColumnTrailing = node->getInlineEndMargin(flexColumnDirection, direction, ownerWidth); - node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom); + node->setLayoutMargin(marginColumnTrailing, Edge::Bottom); const float marginAxisRow = marginRowLeading + marginRowTrailing; const float marginAxisColumn = marginColumnLeading + marginColumnTrailing; @@ -1522,9 +1521,9 @@ static void calculateLayoutImpl( node->setLayoutBorder( node->getInlineEndBorder(flexRowDirection, direction), endEdge); node->setLayoutBorder( - node->getInlineStartBorder(flexColumnDirection, direction), YGEdgeTop); + node->getInlineStartBorder(flexColumnDirection, direction), Edge::Top); node->setLayoutBorder( - node->getInlineEndBorder(flexColumnDirection, direction), YGEdgeBottom); + node->getInlineEndBorder(flexColumnDirection, direction), Edge::Bottom); node->setLayoutPadding( node->getInlineStartPadding(flexRowDirection, direction, ownerWidth), @@ -1534,10 +1533,10 @@ static void calculateLayoutImpl( endEdge); node->setLayoutPadding( node->getInlineStartPadding(flexColumnDirection, direction, ownerWidth), - YGEdgeTop); + Edge::Top); node->setLayoutPadding( node->getInlineEndPadding(flexColumnDirection, direction, ownerWidth), - YGEdgeBottom); + Edge::Bottom); if (node->hasMeasureFunc()) { measureNodeWithMeasureFunc( @@ -1868,7 +1867,7 @@ static void calculateLayoutImpl( // default to border + margin if (!isChildLeadingPosDefined || yoga::isUndefined( - child->getLayout().position[flexStartEdge(crossAxis)])) { + child->getLayout().position(flexStartEdge(crossAxis)))) { child->setLayoutPosition( node->getInlineStartBorder(crossAxis, direction) + child->getInlineStartMargin( @@ -1981,7 +1980,7 @@ static void calculateLayoutImpl( } // And we apply the position child->setLayoutPosition( - child->getLayout().position[flexStartEdge(crossAxis)] + + child->getLayout().position(flexStartEdge(crossAxis)) + totalLineCrossDim + leadingCrossDim, flexStartEdge(crossAxis)); } @@ -2190,7 +2189,7 @@ static void calculateLayoutImpl( FlexDirection::Column, direction, availableInnerCrossDim), - YGEdgeTop); + Edge::Top); break; } @@ -2296,7 +2295,7 @@ static void calculateLayoutImpl( if (child->getStyle().positionType() != PositionType::Absolute) { child->setLayoutPosition( node->getLayout().measuredDimension(dimension(crossAxis)) - - child->getLayout().position[flexStartEdge(crossAxis)] - + child->getLayout().position(flexStartEdge(crossAxis)) - child->getLayout().measuredDimension(dimension(crossAxis)), flexStartEdge(crossAxis)); } diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexDirection.h b/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexDirection.h index a8ee7586aeb849..5bc5880a4dd886 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexDirection.h +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexDirection.h @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace facebook::yoga { @@ -48,80 +49,80 @@ inline FlexDirection resolveCrossDirection( : FlexDirection::Column; } -inline YGEdge flexStartEdge(const FlexDirection flexDirection) { +inline Edge flexStartEdge(const FlexDirection flexDirection) { switch (flexDirection) { case FlexDirection::Column: - return YGEdgeTop; + return Edge::Top; case FlexDirection::ColumnReverse: - return YGEdgeBottom; + return Edge::Bottom; case FlexDirection::Row: - return YGEdgeLeft; + return Edge::Left; case FlexDirection::RowReverse: - return YGEdgeRight; + return Edge::Right; } fatalWithMessage("Invalid FlexDirection"); } -inline YGEdge flexEndEdge(const FlexDirection flexDirection) { +inline Edge flexEndEdge(const FlexDirection flexDirection) { switch (flexDirection) { case FlexDirection::Column: - return YGEdgeBottom; + return Edge::Bottom; case FlexDirection::ColumnReverse: - return YGEdgeTop; + return Edge::Top; case FlexDirection::Row: - return YGEdgeRight; + return Edge::Right; case FlexDirection::RowReverse: - return YGEdgeLeft; + return Edge::Left; } fatalWithMessage("Invalid FlexDirection"); } -inline YGEdge inlineStartEdge( +inline Edge inlineStartEdge( const FlexDirection flexDirection, const Direction direction) { if (isRow(flexDirection)) { - return direction == Direction::RTL ? YGEdgeRight : YGEdgeLeft; + return direction == Direction::RTL ? Edge::Right : Edge::Left; } - return YGEdgeTop; + return Edge::Top; } -inline YGEdge inlineEndEdge( +inline Edge inlineEndEdge( const FlexDirection flexDirection, const Direction direction) { if (isRow(flexDirection)) { - return direction == Direction::RTL ? YGEdgeLeft : YGEdgeRight; + return direction == Direction::RTL ? Edge::Left : Edge::Right; } - return YGEdgeBottom; + return Edge::Bottom; } /** - * The physical edges that YGEdgeStart and YGEdgeEnd correspond to (e.g. + * The physical edges that Edge::Start and Edge::End correspond to (e.g. * left/right) are soley dependent on the direction. However, there are cases * where we want the flex start/end edge (i.e. which edge is the start/end * for laying out flex items), which can be distinct from the corresponding * inline edge. In these cases we need to know which "relative edge" - * (YGEdgeStart/YGEdgeEnd) corresponds to the said flex start/end edge as these + * (Edge::Start/Edge::End) corresponds to the said flex start/end edge as these * relative edges can be used instead of physical ones when defining certain * attributes like border or padding. */ -inline YGEdge flexStartRelativeEdge( +inline Edge flexStartRelativeEdge( FlexDirection flexDirection, Direction direction) { - const YGEdge leadLayoutEdge = inlineStartEdge(flexDirection, direction); - const YGEdge leadFlexItemEdge = flexStartEdge(flexDirection); - return leadLayoutEdge == leadFlexItemEdge ? YGEdgeStart : YGEdgeEnd; + const Edge leadLayoutEdge = inlineStartEdge(flexDirection, direction); + const Edge leadFlexItemEdge = flexStartEdge(flexDirection); + return leadLayoutEdge == leadFlexItemEdge ? Edge::Start : Edge::End; } -inline YGEdge flexEndRelativeEdge( +inline Edge flexEndRelativeEdge( FlexDirection flexDirection, Direction direction) { - const YGEdge trailLayoutEdge = inlineEndEdge(flexDirection, direction); - const YGEdge trailFlexItemEdge = flexEndEdge(flexDirection); - return trailLayoutEdge == trailFlexItemEdge ? YGEdgeEnd : YGEdgeStart; + const Edge trailLayoutEdge = inlineEndEdge(flexDirection, direction); + const Edge trailFlexItemEdge = flexEndEdge(flexDirection); + return trailLayoutEdge == trailFlexItemEdge ? Edge::End : Edge::Start; } inline Dimension dimension(const FlexDirection flexDirection) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/PixelGrid.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/PixelGrid.cpp index 5e44c2cc8d40c6..b84cd7db090671 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/PixelGrid.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/PixelGrid.cpp @@ -68,8 +68,8 @@ void roundLayoutResultsToPixelGrid( const double absoluteTop) { const auto pointScaleFactor = node->getConfig()->getPointScaleFactor(); - const double nodeLeft = node->getLayout().position[YGEdgeLeft]; - const double nodeTop = node->getLayout().position[YGEdgeTop]; + const double nodeLeft = node->getLayout().position(Edge::Left); + const double nodeTop = node->getLayout().position(Edge::Top); const double nodeWidth = node->getLayout().dimension(Dimension::Width); const double nodeHeight = node->getLayout().dimension(Dimension::Height); @@ -87,11 +87,11 @@ void roundLayoutResultsToPixelGrid( node->setLayoutPosition( roundValueToPixelGrid(nodeLeft, pointScaleFactor, false, textRounding), - YGEdgeLeft); + Edge::Left); node->setLayoutPosition( roundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding), - YGEdgeTop); + Edge::Top); // We multiply dimension by scale factor and if the result is close to the // whole number, we don't have any fraction To verify if the result is close diff --git a/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp b/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp index ef55ea1d215e9d..18e8aeec659b50 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp @@ -9,8 +9,6 @@ #include -#include - #include #include #include @@ -85,7 +83,7 @@ static void appendEdges(std::string& base, const std::string& key, const Style& style) { for (auto edge : ordinals()) { std::string str = key + "-" + toString(edge); - appendNumberIfNotZero(base, str, (style.*Field)(unscopedEnum(edge))); + appendNumberIfNotZero(base, str, (style.*Field)(edge)); } } @@ -104,9 +102,9 @@ void nodeToString( appendFormattedString( str, "height: %g; ", node->getLayout().dimension(Dimension::Height)); appendFormattedString( - str, "top: %g; ", node->getLayout().position[YGEdgeTop]); + str, "top: %g; ", node->getLayout().position(Edge::Top)); appendFormattedString( - str, "left: %g;", node->getLayout().position[YGEdgeLeft]); + str, "left: %g;", node->getLayout().position(Edge::Left)); appendFormattedString(str, "\" "); } diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.cpp b/packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.cpp index d050bfdc73fec6..fd70870e65b3a7 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.cpp @@ -13,11 +13,11 @@ namespace facebook::yoga { bool LayoutResults::operator==(LayoutResults layout) const { - bool isEqual = yoga::inexactEquals(position, layout.position) && + bool isEqual = yoga::inexactEquals(position_, layout.position_) && yoga::inexactEquals(dimensions_, layout.dimensions_) && - yoga::inexactEquals(margin, layout.margin) && - yoga::inexactEquals(border, layout.border) && - yoga::inexactEquals(padding, layout.padding) && + yoga::inexactEquals(margin_, layout.margin_) && + yoga::inexactEquals(border_, layout.border_) && + yoga::inexactEquals(padding_, layout.padding_) && direction() == layout.direction() && hadOverflow() == layout.hadOverflow() && lastOwnerDirection == layout.lastOwnerDirection && diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.h b/packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.h index 8b324e6454bf38..f7cf8b8cf47858 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.h +++ b/packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.h @@ -10,8 +10,10 @@ #include #include +#include #include #include +#include #include #include @@ -22,19 +24,6 @@ struct LayoutResults { // 98% of analyzed layouts require less than 8 entries. static constexpr int32_t MaxCachedMeasurements = 8; - std::array position = {}; - std::array margin = {}; - std::array border = {}; - std::array padding = {}; - - private: - Direction direction_ : bitCount() = Direction::Inherit; - bool hadOverflow_ : 1 = false; - - std::array dimensions_ = {{YGUndefined, YGUndefined}}; - std::array measuredDimensions_ = {{YGUndefined, YGUndefined}}; - - public: uint32_t computedFlexBasisGeneration = 0; FloatOptional computedFlexBasis = {}; @@ -80,10 +69,66 @@ struct LayoutResults { measuredDimensions_[yoga::to_underlying(axis)] = dimension; } + float position(Edge cardinalEdge) const { + assertCardinalEdge(cardinalEdge); + return position_[yoga::to_underlying(cardinalEdge)]; + } + + void setPosition(Edge cardinalEdge, float dimension) { + assertCardinalEdge(cardinalEdge); + position_[yoga::to_underlying(cardinalEdge)] = dimension; + } + + float margin(Edge cardinalEdge) const { + assertCardinalEdge(cardinalEdge); + return margin_[yoga::to_underlying(cardinalEdge)]; + } + + void setMargin(Edge cardinalEdge, float dimension) { + assertCardinalEdge(cardinalEdge); + margin_[yoga::to_underlying(cardinalEdge)] = dimension; + } + + float border(Edge cardinalEdge) const { + assertCardinalEdge(cardinalEdge); + return border_[yoga::to_underlying(cardinalEdge)]; + } + + void setBorder(Edge cardinalEdge, float dimension) { + assertCardinalEdge(cardinalEdge); + border_[yoga::to_underlying(cardinalEdge)] = dimension; + } + + float padding(Edge cardinalEdge) const { + assertCardinalEdge(cardinalEdge); + return padding_[yoga::to_underlying(cardinalEdge)]; + } + + void setPadding(Edge cardinalEdge, float dimension) { + assertCardinalEdge(cardinalEdge); + padding_[yoga::to_underlying(cardinalEdge)] = dimension; + } + bool operator==(LayoutResults layout) const; bool operator!=(LayoutResults layout) const { return !(*this == layout); } + + private: + static inline void assertCardinalEdge(Edge edge) { + assertFatal( + static_cast(edge) <= 3, "Edge must be top/left/bottom/right"); + } + + Direction direction_ : bitCount() = Direction::Inherit; + bool hadOverflow_ : 1 = false; + + std::array dimensions_ = {{YGUndefined, YGUndefined}}; + std::array measuredDimensions_ = {{YGUndefined, YGUndefined}}; + std::array position_ = {}; + std::array margin_ = {}; + std::array border_ = {}; + std::array padding_ = {}; }; } // namespace facebook::yoga diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp index 0781b8e63ab44b..faf812e8cf1949 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp @@ -58,31 +58,31 @@ void Node::print() { // TODO: Edge value resolution should be moved to `yoga::Style` template -Style::Length Node::computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const { +Style::Length Node::computeEdgeValueForRow(Edge rowEdge, Edge edge) const { if ((style_.*Field)(rowEdge).isDefined()) { return (style_.*Field)(rowEdge); } else if ((style_.*Field)(edge).isDefined()) { return (style_.*Field)(edge); - } else if ((style_.*Field)(YGEdgeHorizontal).isDefined()) { - return (style_.*Field)(YGEdgeHorizontal); + } else if ((style_.*Field)(Edge::Horizontal).isDefined()) { + return (style_.*Field)(Edge::Horizontal); } else { - return (style_.*Field)(YGEdgeAll); + return (style_.*Field)(Edge::All); } } // TODO: Edge value resolution should be moved to `yoga::Style` template -Style::Length Node::computeEdgeValueForColumn(YGEdge edge) const { +Style::Length Node::computeEdgeValueForColumn(Edge edge) const { if ((style_.*Field)(edge).isDefined()) { return (style_.*Field)(edge); - } else if ((style_.*Field)(YGEdgeVertical).isDefined()) { - return (style_.*Field)(YGEdgeVertical); + } else if ((style_.*Field)(Edge::Vertical).isDefined()) { + return (style_.*Field)(Edge::Vertical); } else { - return (style_.*Field)(YGEdgeAll); + return (style_.*Field)(Edge::All); } } -YGEdge Node::getInlineStartEdgeUsingErrata( +Edge Node::getInlineStartEdgeUsingErrata( FlexDirection flexDirection, Direction direction) const { return hasErrata(Errata::StartingEndingEdgeFromFlexDirection) @@ -90,7 +90,7 @@ YGEdge Node::getInlineStartEdgeUsingErrata( : inlineStartEdge(flexDirection, direction); } -YGEdge Node::getInlineEndEdgeUsingErrata( +Edge Node::getInlineEndEdgeUsingErrata( FlexDirection flexDirection, Direction direction) const { return hasErrata(Errata::StartingEndingEdgeFromFlexDirection) @@ -99,9 +99,9 @@ YGEdge Node::getInlineEndEdgeUsingErrata( } bool Node::isFlexStartPositionDefined(FlexDirection axis) const { - const YGEdge startEdge = flexStartEdge(axis); + const Edge startEdge = flexStartEdge(axis); auto leadingPosition = isRow(axis) - ? computeEdgeValueForRow<&Style::position>(YGEdgeStart, startEdge) + ? computeEdgeValueForRow<&Style::position>(Edge::Start, startEdge) : computeEdgeValueForColumn<&Style::position>(startEdge); return leadingPosition.isDefined(); @@ -109,18 +109,18 @@ bool Node::isFlexStartPositionDefined(FlexDirection axis) const { bool Node::isInlineStartPositionDefined(FlexDirection axis, Direction direction) const { - const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction); + const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction); auto leadingPosition = isRow(axis) - ? computeEdgeValueForRow<&Style::position>(YGEdgeStart, startEdge) + ? computeEdgeValueForRow<&Style::position>(Edge::Start, startEdge) : computeEdgeValueForColumn<&Style::position>(startEdge); return leadingPosition.isDefined(); } bool Node::isFlexEndPositionDefined(FlexDirection axis) const { - const YGEdge endEdge = flexEndEdge(axis); + const Edge endEdge = flexEndEdge(axis); auto trailingPosition = isRow(axis) - ? computeEdgeValueForRow<&Style::position>(YGEdgeEnd, endEdge) + ? computeEdgeValueForRow<&Style::position>(Edge::End, endEdge) : computeEdgeValueForColumn<&Style::position>(endEdge); return !trailingPosition.isUndefined(); @@ -128,18 +128,18 @@ bool Node::isFlexEndPositionDefined(FlexDirection axis) const { bool Node::isInlineEndPositionDefined(FlexDirection axis, Direction direction) const { - const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction); + const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction); auto trailingPosition = isRow(axis) - ? computeEdgeValueForRow<&Style::position>(YGEdgeEnd, endEdge) + ? computeEdgeValueForRow<&Style::position>(Edge::End, endEdge) : computeEdgeValueForColumn<&Style::position>(endEdge); return trailingPosition.isDefined(); } float Node::getFlexStartPosition(FlexDirection axis, float axisSize) const { - const YGEdge startEdge = flexStartEdge(axis); + const Edge startEdge = flexStartEdge(axis); auto leadingPosition = isRow(axis) - ? computeEdgeValueForRow<&Style::position>(YGEdgeStart, startEdge) + ? computeEdgeValueForRow<&Style::position>(Edge::Start, startEdge) : computeEdgeValueForColumn<&Style::position>(startEdge); return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f); @@ -149,18 +149,18 @@ float Node::getInlineStartPosition( FlexDirection axis, Direction direction, float axisSize) const { - const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction); + const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction); auto leadingPosition = isRow(axis) - ? computeEdgeValueForRow<&Style::position>(YGEdgeStart, startEdge) + ? computeEdgeValueForRow<&Style::position>(Edge::Start, startEdge) : computeEdgeValueForColumn<&Style::position>(startEdge); return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f); } float Node::getFlexEndPosition(FlexDirection axis, float axisSize) const { - const YGEdge endEdge = flexEndEdge(axis); + const Edge endEdge = flexEndEdge(axis); auto trailingPosition = isRow(axis) - ? computeEdgeValueForRow<&Style::position>(YGEdgeEnd, endEdge) + ? computeEdgeValueForRow<&Style::position>(Edge::End, endEdge) : computeEdgeValueForColumn<&Style::position>(endEdge); return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f); @@ -170,18 +170,18 @@ float Node::getInlineEndPosition( FlexDirection axis, Direction direction, float axisSize) const { - const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction); + const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction); auto trailingPosition = isRow(axis) - ? computeEdgeValueForRow<&Style::position>(YGEdgeEnd, endEdge) + ? computeEdgeValueForRow<&Style::position>(Edge::End, endEdge) : computeEdgeValueForColumn<&Style::position>(endEdge); return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f); } float Node::getFlexStartMargin(FlexDirection axis, float widthSize) const { - const YGEdge startEdge = flexStartEdge(axis); + const Edge startEdge = flexStartEdge(axis); auto leadingMargin = isRow(axis) - ? computeEdgeValueForRow<&Style::margin>(YGEdgeStart, startEdge) + ? computeEdgeValueForRow<&Style::margin>(Edge::Start, startEdge) : computeEdgeValueForColumn<&Style::margin>(startEdge); return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f); @@ -191,18 +191,18 @@ float Node::getInlineStartMargin( FlexDirection axis, Direction direction, float widthSize) const { - const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction); + const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction); auto leadingMargin = isRow(axis) - ? computeEdgeValueForRow<&Style::margin>(YGEdgeStart, startEdge) + ? computeEdgeValueForRow<&Style::margin>(Edge::Start, startEdge) : computeEdgeValueForColumn<&Style::margin>(startEdge); return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f); } float Node::getFlexEndMargin(FlexDirection axis, float widthSize) const { - const YGEdge endEdge = flexEndEdge(axis); + const Edge endEdge = flexEndEdge(axis); auto trailingMargin = isRow(axis) - ? computeEdgeValueForRow<&Style::margin>(YGEdgeEnd, endEdge) + ? computeEdgeValueForRow<&Style::margin>(Edge::End, endEdge) : computeEdgeValueForColumn<&Style::margin>(endEdge); return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f); @@ -212,9 +212,9 @@ float Node::getInlineEndMargin( FlexDirection axis, Direction direction, float widthSize) const { - const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction); + const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction); auto trailingMargin = isRow(axis) - ? computeEdgeValueForRow<&Style::margin>(YGEdgeEnd, endEdge) + ? computeEdgeValueForRow<&Style::margin>(Edge::End, endEdge) : computeEdgeValueForColumn<&Style::margin>(endEdge); return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f); @@ -222,17 +222,16 @@ float Node::getInlineEndMargin( float Node::getInlineStartBorder(FlexDirection axis, Direction direction) const { - const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction); + const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction); YGValue leadingBorder = isRow(axis) - ? computeEdgeValueForRow<&Style::border>(YGEdgeStart, startEdge) + ? computeEdgeValueForRow<&Style::border>(Edge::Start, startEdge) : computeEdgeValueForColumn<&Style::border>(startEdge); return maxOrDefined(leadingBorder.value, 0.0f); } float Node::getFlexStartBorder(FlexDirection axis, Direction direction) const { - const YGEdge leadRelativeFlexItemEdge = - flexStartRelativeEdge(axis, direction); + const Edge leadRelativeFlexItemEdge = flexStartRelativeEdge(axis, direction); YGValue leadingBorder = isRow(axis) ? computeEdgeValueForRow<&Style::border>( leadRelativeFlexItemEdge, flexStartEdge(axis)) @@ -242,16 +241,16 @@ float Node::getFlexStartBorder(FlexDirection axis, Direction direction) const { } float Node::getInlineEndBorder(FlexDirection axis, Direction direction) const { - const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction); + const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction); YGValue trailingBorder = isRow(axis) - ? computeEdgeValueForRow<&Style::border>(YGEdgeEnd, endEdge) + ? computeEdgeValueForRow<&Style::border>(Edge::End, endEdge) : computeEdgeValueForColumn<&Style::border>(endEdge); return maxOrDefined(trailingBorder.value, 0.0f); } float Node::getFlexEndBorder(FlexDirection axis, Direction direction) const { - const YGEdge trailRelativeFlexItemEdge = flexEndRelativeEdge(axis, direction); + const Edge trailRelativeFlexItemEdge = flexEndRelativeEdge(axis, direction); YGValue trailingBorder = isRow(axis) ? computeEdgeValueForRow<&Style::border>( trailRelativeFlexItemEdge, flexEndEdge(axis)) @@ -264,9 +263,9 @@ float Node::getInlineStartPadding( FlexDirection axis, Direction direction, float widthSize) const { - const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction); + const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction); auto leadingPadding = isRow(axis) - ? computeEdgeValueForRow<&Style::padding>(YGEdgeStart, startEdge) + ? computeEdgeValueForRow<&Style::padding>(Edge::Start, startEdge) : computeEdgeValueForColumn<&Style::padding>(startEdge); return maxOrDefined(resolveValue(leadingPadding, widthSize).unwrap(), 0.0f); @@ -276,8 +275,7 @@ float Node::getFlexStartPadding( FlexDirection axis, Direction direction, float widthSize) const { - const YGEdge leadRelativeFlexItemEdge = - flexStartRelativeEdge(axis, direction); + const Edge leadRelativeFlexItemEdge = flexStartRelativeEdge(axis, direction); auto leadingPadding = isRow(axis) ? computeEdgeValueForRow<&Style::padding>( leadRelativeFlexItemEdge, flexStartEdge(axis)) @@ -290,9 +288,9 @@ float Node::getInlineEndPadding( FlexDirection axis, Direction direction, float widthSize) const { - const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction); + const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction); auto trailingPadding = isRow(axis) - ? computeEdgeValueForRow<&Style::padding>(YGEdgeEnd, endEdge) + ? computeEdgeValueForRow<&Style::padding>(Edge::End, endEdge) : computeEdgeValueForColumn<&Style::padding>(endEdge); return maxOrDefined(resolveValue(trailingPadding, widthSize).unwrap(), 0.0f); @@ -302,7 +300,7 @@ float Node::getFlexEndPadding( FlexDirection axis, Direction direction, float widthSize) const { - const YGEdge trailRelativeFlexItemEdge = flexEndRelativeEdge(axis, direction); + const Edge trailRelativeFlexItemEdge = flexEndRelativeEdge(axis, direction); auto trailingPadding = isRow(axis) ? computeEdgeValueForRow<&Style::padding>( trailRelativeFlexItemEdge, flexEndEdge(axis)) @@ -446,25 +444,16 @@ void Node::setLayoutDirection(Direction direction) { layout_.setDirection(direction); } -void Node::setLayoutMargin(float margin, YGEdge edge) { - assertFatal( - edge < static_cast(layout_.margin.size()), - "Edge must be top/left/bottom/right"); - layout_.margin[edge] = margin; +void Node::setLayoutMargin(float margin, Edge edge) { + layout_.setMargin(edge, margin); } -void Node::setLayoutBorder(float border, YGEdge edge) { - assertFatal( - edge < static_cast(layout_.border.size()), - "Edge must be top/left/bottom/right"); - layout_.border[edge] = border; +void Node::setLayoutBorder(float border, Edge edge) { + layout_.setBorder(edge, border); } -void Node::setLayoutPadding(float padding, YGEdge edge) { - assertFatal( - edge < static_cast(layout_.padding.size()), - "Edge must be top/left/bottom/right"); - layout_.padding[edge] = padding; +void Node::setLayoutPadding(float padding, Edge edge) { + layout_.setPadding(edge, padding); } void Node::setLayoutLastOwnerDirection(Direction direction) { @@ -475,11 +464,8 @@ void Node::setLayoutComputedFlexBasis(const FloatOptional computedFlexBasis) { layout_.computedFlexBasis = computedFlexBasis; } -void Node::setLayoutPosition(float position, YGEdge edge) { - assertFatal( - edge < static_cast(layout_.position.size()), - "Edge must be top/left/bottom/right"); - layout_.position[edge] = position; +void Node::setLayoutPosition(float position, Edge edge) { + layout_.setPosition(edge, position); } void Node::setLayoutComputedFlexBasisGeneration( @@ -536,13 +522,13 @@ void Node::setPosition( const float relativePositionCross = relativePosition(crossAxis, directionRespectingRoot, crossSize); - const YGEdge mainAxisLeadingEdge = + const Edge mainAxisLeadingEdge = getInlineStartEdgeUsingErrata(mainAxis, direction); - const YGEdge mainAxisTrailingEdge = + const Edge mainAxisTrailingEdge = getInlineEndEdgeUsingErrata(mainAxis, direction); - const YGEdge crossAxisLeadingEdge = + const Edge crossAxisLeadingEdge = getInlineStartEdgeUsingErrata(crossAxis, direction); - const YGEdge crossAxisTrailingEdge = + const Edge crossAxisTrailingEdge = getInlineEndEdgeUsingErrata(crossAxis, direction); setLayoutPosition( @@ -564,16 +550,16 @@ void Node::setPosition( } YGValue Node::getFlexStartMarginValue(FlexDirection axis) const { - if (isRow(axis) && style_.margin(YGEdgeStart).isDefined()) { - return style_.margin(YGEdgeStart); + if (isRow(axis) && style_.margin(Edge::Start).isDefined()) { + return style_.margin(Edge::Start); } else { return style_.margin(flexStartEdge(axis)); } } YGValue Node::marginTrailingValue(FlexDirection axis) const { - if (isRow(axis) && style_.margin(YGEdgeEnd).isDefined()) { - return style_.margin(YGEdgeEnd); + if (isRow(axis) && style_.margin(Edge::End).isDefined()) { + return style_.margin(Edge::End); } else { return style_.margin(flexEndEdge(axis)); } diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h index 1c9acbbe86d23d..d01a1ed4ca6da2 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -52,10 +53,10 @@ class YG_EXPORT Node : public ::YGNode { Direction direction, const float axisSize) const; - YGEdge getInlineStartEdgeUsingErrata( + Edge getInlineStartEdgeUsingErrata( FlexDirection flexDirection, Direction direction) const; - YGEdge getInlineEndEdgeUsingErrata( + Edge getInlineEndEdgeUsingErrata( FlexDirection flexDirection, Direction direction) const; @@ -65,10 +66,10 @@ class YG_EXPORT Node : public ::YGNode { } template - Style::Length computeEdgeValueForColumn(YGEdge edge) const; + Style::Length computeEdgeValueForColumn(Edge edge) const; template - Style::Length computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const; + Style::Length computeEdgeValueForRow(Edge rowEdge, Edge edge) const; // DANGER DANGER DANGER! // If the node assigned to has children, we'd either have to deallocate @@ -328,10 +329,10 @@ class YG_EXPORT Node : public ::YGNode { void setLayoutHadOverflow(bool hadOverflow); void setLayoutDimension(float LengthValue, Dimension dimension); void setLayoutDirection(Direction direction); - void setLayoutMargin(float margin, YGEdge edge); - void setLayoutBorder(float border, YGEdge edge); - void setLayoutPadding(float padding, YGEdge edge); - void setLayoutPosition(float position, YGEdge edge); + void setLayoutMargin(float margin, Edge edge); + void setLayoutBorder(float border, Edge edge); + void setLayoutPadding(float padding, Edge edge); + void setLayoutPosition(float position, Edge edge); void setPosition( const Direction direction, const float mainSize, diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h index 835632edd598dc..e40f1c4fb644f7 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h @@ -227,32 +227,32 @@ class YG_EXPORT Style { return {*this}; } - Style::Length margin(YGEdge edge) const { - return margin_[edge]; + Style::Length margin(Edge edge) const { + return margin_[yoga::to_underlying(edge)]; } - void setMargin(YGEdge edge, Style::Length value) { - margin_[edge] = value; + void setMargin(Edge edge, Style::Length value) { + margin_[yoga::to_underlying(edge)] = value; } - Style::Length position(YGEdge edge) const { - return position_[edge]; + Style::Length position(Edge edge) const { + return position_[yoga::to_underlying(edge)]; } - void setPosition(YGEdge edge, Style::Length value) { - position_[edge] = value; + void setPosition(Edge edge, Style::Length value) { + position_[yoga::to_underlying(edge)] = value; } - Style::Length padding(YGEdge edge) const { - return padding_[edge]; + Style::Length padding(Edge edge) const { + return padding_[yoga::to_underlying(edge)]; } - void setPadding(YGEdge edge, Style::Length value) { - padding_[edge] = value; + void setPadding(Edge edge, Style::Length value) { + padding_[yoga::to_underlying(edge)] = value; } - Style::Length border(YGEdge edge) const { - return border_[edge]; + Style::Length border(Edge edge) const { + return border_[yoga::to_underlying(edge)]; } - void setBorder(YGEdge edge, Style::Length value) { - border_[edge] = value; + void setBorder(Edge edge, Style::Length value) { + border_[yoga::to_underlying(edge)] = value; } Style::Length gap(Gutter gutter) const {