From 516021a9e6e45d89e289880543a87482bd60e979 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 14 Nov 2023 08:03:44 -0800 Subject: [PATCH] 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: 17378a8710afa2b22c63ae5098be51a3391a6019 --- .../Text/RCTParagraphComponentViewTests.mm | 16 +- .../AndroidTextInputComponentDescriptor.h | 16 +- .../components/view/BaseViewProps.cpp | 22 +- .../components/view/ViewShadowNode.cpp | 5 +- .../view/YogaLayoutableShadowNode.cpp | 113 ++++----- .../components/view/YogaStylableProps.cpp | 222 +++++++++--------- .../view/YogaStylablePropsMapBuffer.cpp | 28 ++- .../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 | 10 +- .../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, 583 insertions(+), 533 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 086d7872d19645..793596c4f3049a 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 @@ -109,10 +109,10 @@ class AndroidTextInputComponentDescriptor final // paddingStart, and vice-versa with paddingRight/paddingEnd. // For now this assumes no RTL. ThemePadding result{ - .start = textInputProps.yogaStyle.padding(YGEdgeStart), - .end = textInputProps.yogaStyle.padding(YGEdgeEnd), - .top = textInputProps.yogaStyle.padding(YGEdgeTop), - .bottom = textInputProps.yogaStyle.padding(YGEdgeBottom)}; + .start = textInputProps.yogaStyle.padding(yoga::Edge::Start), + .end = textInputProps.yogaStyle.padding(yoga::Edge::End), + .top = textInputProps.yogaStyle.padding(yoga::Edge::Top), + .bottom = textInputProps.yogaStyle.padding(yoga::Edge::Bottom)}; bool changedPadding = false; if (!textInputProps.hasPadding && !textInputProps.hasPaddingStart && @@ -161,10 +161,10 @@ class AndroidTextInputComponentDescriptor final // Set new props on node yoga::Style& style = const_cast(textInputProps).yogaStyle; - style.setPadding(YGEdgeStart, result.start); - style.setPadding(YGEdgeEnd, result.end); - style.setPadding(YGEdgeTop, result.top); - style.setPadding(YGEdgeBottom, result.bottom); + style.setPadding(yoga::Edge::Start, result.start); + style.setPadding(yoga::Edge::End, result.end); + style.setPadding(yoga::Edge::Top, result.top); + style.setPadding(yoga::Edge::Bottom, result.bottom); // Communicate new props to Yoga part of the node textInputShadowNode.updateYogaProps(); 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 8c66b0f6f890c2..91ee72f143a6aa 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp @@ -55,8 +55,9 @@ void ViewShadowNode::initialize() noexcept { HostPlatformViewTraitsInitializer::formsStackingContext(viewProps); bool hasBorder = [&]() { - for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) { - if (viewProps.yogaStyle.border(static_cast(edge)).isDefined()) { + for (int edge = 0; edge < yoga::ordinalCount(); ++edge) { + if (viewProps.yogaStyle.border(static_cast(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 c2d6cde510797c..90aa3fdd58074b 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp @@ -196,45 +196,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_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(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, 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, @@ -350,151 +350,151 @@ SharedDebugStringConvertibleList YogaStylableProps::getDebugProps() const { 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( "borderLeft", - yogaStyle.border(YGEdgeLeft), - defaultYogaStyle.border(YGEdgeLeft)), + yogaStyle.border(yoga::Edge::Left), + defaultYogaStyle.border(yoga::Edge::Left)), debugStringConvertibleItem( "borderTop", - yogaStyle.border(YGEdgeTop), - defaultYogaStyle.border(YGEdgeTop)), + yogaStyle.border(yoga::Edge::Top), + defaultYogaStyle.border(yoga::Edge::Top)), debugStringConvertibleItem( "borderRight", - yogaStyle.border(YGEdgeRight), - defaultYogaStyle.border(YGEdgeRight)), + yogaStyle.border(yoga::Edge::Right), + defaultYogaStyle.border(yoga::Edge::Right)), debugStringConvertibleItem( "borderBottom", - yogaStyle.border(YGEdgeBottom), - defaultYogaStyle.border(YGEdgeBottom)), + yogaStyle.border(yoga::Edge::Bottom), + defaultYogaStyle.border(yoga::Edge::Bottom)), debugStringConvertibleItem( "borderStart", - yogaStyle.border(YGEdgeStart), - defaultYogaStyle.border(YGEdgeStart)), + yogaStyle.border(yoga::Edge::Start), + defaultYogaStyle.border(yoga::Edge::Start)), debugStringConvertibleItem( "borderEnd", - yogaStyle.border(YGEdgeEnd), - defaultYogaStyle.border(YGEdgeEnd)), + yogaStyle.border(yoga::Edge::End), + defaultYogaStyle.border(yoga::Edge::End)), debugStringConvertibleItem( "borderHorizontal", - yogaStyle.border(YGEdgeHorizontal), - defaultYogaStyle.border(YGEdgeHorizontal)), + yogaStyle.border(yoga::Edge::Horizontal), + defaultYogaStyle.border(yoga::Edge::Horizontal)), debugStringConvertibleItem( "borderVertical", - yogaStyle.border(YGEdgeVertical), - defaultYogaStyle.border(YGEdgeVertical)), + yogaStyle.border(yoga::Edge::Vertical), + defaultYogaStyle.border(yoga::Edge::Vertical)), debugStringConvertibleItem( "border", - yogaStyle.border(YGEdgeAll), - defaultYogaStyle.border(YGEdgeAll)), + yogaStyle.border(yoga::Edge::All), + defaultYogaStyle.border(yoga::Edge::All)), debugStringConvertibleItem( "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 663205dca10192..074a8021d65c94 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(); } @@ -61,9 +69,9 @@ void YogaStylableProps::propsDiffMapBuffer( const auto& newStyle = newProps.yogaStyle; bool areBordersEqual = [&]() { - for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) { - if (oldStyle.border(static_cast(edge)) != - newStyle.border(static_cast(edge))) { + for (int edge = 0; edge < yoga::ordinalCount(); ++edge) { + if (oldStyle.border(static_cast(edge)) != + newStyle.border(static_cast(edge))) { return false; } } 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 107c50e4bb9bdd..0ad06900875803 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 @@ -84,8 +82,8 @@ template static void appendEdges(std::string& base, const std::string& key, const Style& style) { for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) { - std::string str = key + "-" + YGEdgeToString(static_cast(edge)); - appendNumberIfNotZero(base, str, (style.*Field)(static_cast(edge))); + std::string str = key + "-" + toString(static_cast(edge)); + appendNumberIfNotZero(base, str, (style.*Field)(static_cast(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 {