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 af2a3a34742..2684ea4f5ba 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h @@ -261,46 +261,46 @@ inline void fromRawValue( inline void fromRawValue( const PropsParserContext& context, const RawValue& value, - YGAlign& result) { - result = YGAlignStretch; + yoga::Align& result) { + result = yoga::Align::Stretch; react_native_expect(value.hasType()); if (!value.hasType()) { return; } auto stringValue = (std::string)value; if (stringValue == "auto") { - result = YGAlignAuto; + result = yoga::Align::Auto; return; } if (stringValue == "flex-start") { - result = YGAlignFlexStart; + result = yoga::Align::FlexStart; return; } if (stringValue == "center") { - result = YGAlignCenter; + result = yoga::Align::Center; return; } if (stringValue == "flex-end") { - result = YGAlignFlexEnd; + result = yoga::Align::FlexEnd; return; } if (stringValue == "stretch") { - result = YGAlignStretch; + result = yoga::Align::Stretch; return; } if (stringValue == "baseline") { - result = YGAlignBaseline; + result = yoga::Align::Baseline; return; } if (stringValue == "space-between") { - result = YGAlignSpaceBetween; + result = yoga::Align::SpaceBetween; return; } if (stringValue == "space-around") { - result = YGAlignSpaceAround; + result = yoga::Align::SpaceAround; return; } - LOG(ERROR) << "Could not parse YGAlign:" << stringValue; + LOG(ERROR) << "Could not parse yoga::Align:" << stringValue; react_native_expect(false); } @@ -779,23 +779,23 @@ inline std::string toString(const yoga::Justify& value) { } } -inline std::string toString(const YGAlign& value) { +inline std::string toString(const yoga::Align& value) { switch (value) { - case YGAlignAuto: + case yoga::Align::Auto: return "auto"; - case YGAlignFlexStart: + case yoga::Align::FlexStart: return "flex-start"; - case YGAlignCenter: + case yoga::Align::Center: return "center"; - case YGAlignFlexEnd: + case yoga::Align::FlexEnd: return "flex-end"; - case YGAlignStretch: + case yoga::Align::Stretch: return "stretch"; - case YGAlignBaseline: + case yoga::Align::Baseline: return "baseline"; - case YGAlignSpaceBetween: + case yoga::Align::SpaceBetween: return "space-between"; - case YGAlignSpaceAround: + case yoga::Align::SpaceAround: return "space-around"; } } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp index d2588b50dd4..e2964738145 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/tests/ViewTest.cpp @@ -52,7 +52,7 @@ class YogaDirtyFlagTest : public ::testing::Test { auto &props = *mutableViewProps; props.nativeId = "native Id"; props.opacity = 0.5; - props.yogaStyle.alignContent() = YGAlignBaseline; + props.yogaStyle.alignContent() = yoga::Align::Baseline; props.yogaStyle.flexDirection() = yoga::FlexDirection::RowReverse; return mutableViewProps; }), @@ -136,7 +136,7 @@ TEST_F(YogaDirtyFlagTest, changingLayoutSubPropsMustDirtyYogaNode) { auto viewProps = std::make_shared(); auto& props = *viewProps; - props.yogaStyle.alignContent() = YGAlignBaseline; + props.yogaStyle.alignContent() = yoga::Align::Baseline; props.yogaStyle.display() = YGDisplayNone; return oldShadowNode.clone(ShadowNodeFragment{viewProps}); diff --git a/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp b/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp index e1b980c28e0..c78e39ead59 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp @@ -459,24 +459,26 @@ void YGNodeStyleSetAlignContent( const YGNodeRef node, const YGAlign alignContent) { updateStyle( - node, &Style::alignContent, alignContent); + node, &Style::alignContent, scopedEnum(alignContent)); } YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { - return resolveRef(node)->getStyle().alignContent(); + return unscopedEnum(resolveRef(node)->getStyle().alignContent()); } void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) { - updateStyle(node, &Style::alignItems, alignItems); + updateStyle( + node, &Style::alignItems, scopedEnum(alignItems)); } YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { - return resolveRef(node)->getStyle().alignItems(); + return unscopedEnum(resolveRef(node)->getStyle().alignItems()); } void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) { - updateStyle(node, &Style::alignSelf, alignSelf); + updateStyle( + node, &Style::alignSelf, scopedEnum(alignSelf)); } YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { - return resolveRef(node)->getStyle().alignSelf(); + return unscopedEnum(resolveRef(node)->getStyle().alignSelf()); } void YGNodeStyleSetPositionType( diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Align.h b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Align.h index 9f7f4c24a25..196bf873f33 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Align.h +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Align.h @@ -14,14 +14,14 @@ namespace facebook::yoga { -inline YGAlign resolveChildAlignment( +inline Align resolveChildAlignment( const yoga::Node* node, const yoga::Node* child) { - const YGAlign align = child->getStyle().alignSelf() == YGAlignAuto + const Align align = child->getStyle().alignSelf() == Align::Auto ? node->getStyle().alignItems() : child->getStyle().alignSelf(); - if (align == YGAlignBaseline && isColumn(node->getStyle().flexDirection())) { - return YGAlignFlexStart; + if (align == Align::Baseline && isColumn(node->getStyle().flexDirection())) { + return Align::FlexStart; } return align; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp index 4ea00843b97..3b43204e08e 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp @@ -41,7 +41,7 @@ float calculateBaseline(const yoga::Node* node) { if (child->getStyle().positionType() == YGPositionTypeAbsolute) { continue; } - if (resolveChildAlignment(node, child) == YGAlignBaseline || + if (resolveChildAlignment(node, child) == Align::Baseline || child->isReferenceBaseline()) { baselineChild = child; break; @@ -64,14 +64,14 @@ bool isBaselineLayout(const yoga::Node* node) { if (isColumn(node->getStyle().flexDirection())) { return false; } - if (node->getStyle().alignItems() == YGAlignBaseline) { + if (node->getStyle().alignItems() == Align::Baseline) { return true; } const auto childCount = node->getChildCount(); for (size_t i = 0; i < childCount; i++) { auto child = node->getChild(i); if (child->getStyle().positionType() != YGPositionTypeAbsolute && - child->getStyle().alignSelf() == YGAlignBaseline) { + child->getStyle().alignSelf() == Align::Baseline) { return true; } } diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 8b8311a74a1..565ad3b3949 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -247,7 +247,7 @@ static void computeFlexBasisForChild( const bool hasExactWidth = !yoga::isUndefined(width) && widthMode == MeasureMode::Exactly; const bool childWidthStretch = - resolveChildAlignment(node, child) == YGAlignStretch && + resolveChildAlignment(node, child) == Align::Stretch && childWidthMeasureMode != MeasureMode::Exactly; if (!isMainAxisRow && !isRowStyleDimDefined && hasExactWidth && childWidthStretch) { @@ -263,7 +263,7 @@ static void computeFlexBasisForChild( const bool hasExactHeight = !yoga::isUndefined(height) && heightMode == MeasureMode::Exactly; const bool childHeightStretch = - resolveChildAlignment(node, child) == YGAlignStretch && + resolveChildAlignment(node, child) == Align::Stretch && childHeightMeasureMode != MeasureMode::Exactly; if (isMainAxisRow && !isColumnStyleDimDefined && hasExactHeight && childHeightStretch) { @@ -511,7 +511,7 @@ static void layoutAbsoluteChild( } else if ( !child->isLeadingPositionDefined(crossAxis) && - resolveChildAlignment(node, child) == YGAlignCenter) { + resolveChildAlignment(node, child) == Align::Center) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dimension(crossAxis)] - child->getLayout().measuredDimensions[dimension(crossAxis)]) / @@ -519,7 +519,7 @@ static void layoutAbsoluteChild( leadingEdge(crossAxis)); } else if ( !child->isLeadingPositionDefined(crossAxis) && - ((resolveChildAlignment(node, child) == YGAlignFlexEnd) ^ + ((resolveChildAlignment(node, child) == Align::FlexEnd) ^ (node->getStyle().flexWrap() == YGWrapWrapReverse))) { child->setLayoutPosition( (node->getLayout().measuredDimensions[dimension(crossAxis)] - @@ -959,7 +959,7 @@ static float distributeFreeSpaceSecondPass( currentLineChild, crossAxis, availableInnerCrossDim) && measureModeCrossDim == MeasureMode::Exactly && !(isNodeFlexWrap && mainAxisOverflows) && - resolveChildAlignment(node, currentLineChild) == YGAlignStretch && + resolveChildAlignment(node, currentLineChild) == Align::Stretch && currentLineChild->marginLeadingValue(crossAxis).unit != YGUnitAuto && currentLineChild->marginTrailingValue(crossAxis).unit != YGUnitAuto) { childCrossSize = availableInnerCrossDim; @@ -1005,7 +1005,7 @@ static float distributeFreeSpaceSecondPass( const bool requiresStretchLayout = !styleDefinesDimension( currentLineChild, crossAxis, availableInnerCrossDim) && - resolveChildAlignment(node, currentLineChild) == YGAlignStretch && + resolveChildAlignment(node, currentLineChild) == Align::Stretch && currentLineChild->marginLeadingValue(crossAxis).unit != YGUnitAuto && currentLineChild->marginTrailingValue(crossAxis).unit != YGUnitAuto; @@ -1898,12 +1898,12 @@ static void calculateLayoutImpl( // For a relative children, we're either using alignItems (owner) or // alignSelf (child) in order to determine the position in the cross // axis - const YGAlign alignItem = resolveChildAlignment(node, child); + const Align alignItem = resolveChildAlignment(node, child); // If the child uses align stretch, we need to lay it out one more // time, this time forcing the cross-axis size to be the computed // cross size for the current line. - if (alignItem == YGAlignStretch && + if (alignItem == Align::Stretch && child->marginLeadingValue(crossAxis).unit != YGUnitAuto && child->marginTrailingValue(crossAxis).unit != YGUnitAuto) { // If the child defines a definite size for its cross axis, there's @@ -1949,7 +1949,7 @@ static void calculateLayoutImpl( auto alignContent = node->getStyle().alignContent(); auto crossAxisDoesNotGrow = - alignContent != YGAlignStretch && isNodeFlexWrap; + alignContent != Align::Stretch && isNodeFlexWrap; const MeasureMode childWidthMeasureMode = yoga::isUndefined(childWidth) || (!isMainAxisRow && crossAxisDoesNotGrow) @@ -1990,9 +1990,9 @@ static void calculateLayoutImpl( } else if ( child->marginLeadingValue(crossAxis).unit == YGUnitAuto) { leadingCrossDim += yoga::maxOrDefined(0.0f, remainingCrossDim); - } else if (alignItem == YGAlignFlexStart) { + } else if (alignItem == Align::FlexStart) { // No-Op - } else if (alignItem == YGAlignCenter) { + } else if (alignItem == Align::Center) { leadingCrossDim += remainingCrossDim / 2; } else { leadingCrossDim += remainingCrossDim; @@ -2022,19 +2022,19 @@ static void calculateLayoutImpl( const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim; switch (node->getStyle().alignContent()) { - case YGAlignFlexEnd: + case Align::FlexEnd: currentLead += remainingAlignContentDim; break; - case YGAlignCenter: + case Align::Center: currentLead += remainingAlignContentDim / 2; break; - case YGAlignStretch: + case Align::Stretch: if (availableInnerCrossDim > totalLineCrossDim) { crossDimLead = remainingAlignContentDim / static_cast(lineCount); } break; - case YGAlignSpaceAround: + case Align::SpaceAround: if (availableInnerCrossDim > totalLineCrossDim) { currentLead += remainingAlignContentDim / (2 * static_cast(lineCount)); @@ -2046,15 +2046,15 @@ static void calculateLayoutImpl( currentLead += remainingAlignContentDim / 2; } break; - case YGAlignSpaceBetween: + case Align::SpaceBetween: if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) { crossDimLead = remainingAlignContentDim / static_cast(lineCount - 1); } break; - case YGAlignAuto: - case YGAlignFlexStart: - case YGAlignBaseline: + case Align::Auto: + case Align::FlexStart: + case Align::Baseline: break; } } @@ -2083,7 +2083,7 @@ static void calculateLayoutImpl( child->getMarginForAxis(crossAxis, availableInnerWidth) .unwrap()); } - if (resolveChildAlignment(node, child) == YGAlignBaseline) { + if (resolveChildAlignment(node, child) == Align::Baseline) { const float ascent = calculateBaseline(child) + child ->getLeadingMargin( @@ -2117,7 +2117,7 @@ static void calculateLayoutImpl( } if (child->getStyle().positionType() != YGPositionTypeAbsolute) { switch (resolveChildAlignment(node, child)) { - case YGAlignFlexStart: { + case Align::FlexStart: { child->setLayoutPosition( currentLead + child->getLeadingMargin(crossAxis, availableInnerWidth) @@ -2125,7 +2125,7 @@ static void calculateLayoutImpl( leadingEdge(crossAxis)); break; } - case YGAlignFlexEnd: { + case Align::FlexEnd: { child->setLayoutPosition( currentLead + lineHeight - child->getTrailingMargin(crossAxis, availableInnerWidth) @@ -2135,7 +2135,7 @@ static void calculateLayoutImpl( leadingEdge(crossAxis)); break; } - case YGAlignCenter: { + case Align::Center: { float childHeight = child->getLayout().measuredDimensions[dimension(crossAxis)]; @@ -2144,7 +2144,7 @@ static void calculateLayoutImpl( leadingEdge(crossAxis)); break; } - case YGAlignStretch: { + case Align::Stretch: { child->setLayoutPosition( currentLead + child->getLeadingMargin(crossAxis, availableInnerWidth) @@ -2195,7 +2195,7 @@ static void calculateLayoutImpl( } break; } - case YGAlignBaseline: { + case Align::Baseline: { child->setLayoutPosition( currentLead + maxAscentForCurrentLine - calculateBaseline(child) + @@ -2207,9 +2207,9 @@ static void calculateLayoutImpl( break; } - case YGAlignAuto: - case YGAlignSpaceBetween: - case YGAlignSpaceAround: + case Align::Auto: + case Align::SpaceBetween: + case Align::SpaceAround: break; } } diff --git a/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp b/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp index 92f2c0d4921..302685b3cc3 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp @@ -150,15 +150,15 @@ void nodeToString( } if (style.alignItems() != yoga::Node{}.getStyle().alignItems()) { appendFormattedString( - str, "align-items: %s; ", YGAlignToString(style.alignItems())); + str, "align-items: %s; ", toString(style.alignItems())); } if (style.alignContent() != yoga::Node{}.getStyle().alignContent()) { appendFormattedString( - str, "align-content: %s; ", YGAlignToString(style.alignContent())); + str, "align-content: %s; ", toString(style.alignContent())); } if (style.alignSelf() != yoga::Node{}.getStyle().alignSelf()) { appendFormattedString( - str, "align-self: %s; ", YGAlignToString(style.alignSelf())); + str, "align-self: %s; ", toString(style.alignSelf())); } appendFloatOptionalIfDefined(str, "flex-grow", style.flexGrow()); appendFloatOptionalIfDefined(str, "flex-shrink", style.flexShrink()); diff --git a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h index 562c4ee3a96..359df8514ec 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/node/Node.h +++ b/packages/react-native/ReactCommon/yoga/yoga/node/Node.h @@ -52,7 +52,7 @@ class YG_EXPORT Node : public ::YGNode { void useWebDefaults() { style_.flexDirection() = FlexDirection::Row; - style_.alignContent() = YGAlignStretch; + style_.alignContent() = Align::Stretch; } // DANGER DANGER DANGER! diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h index c6f99c40e79..55742363f81 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -95,8 +96,8 @@ class YG_EXPORT Style { }; Style() { - alignContent() = YGAlignFlexStart; - alignItems() = YGAlignStretch; + alignContent() = Align::FlexStart; + alignItems() = Align::Stretch; } ~Style() = default; @@ -109,11 +110,11 @@ class YG_EXPORT Style { static constexpr uint8_t alignContentOffset = justifyContentOffset + minimumBitCount(); static constexpr uint8_t alignItemsOffset = - alignContentOffset + minimumBitCount(); + alignContentOffset + minimumBitCount(); static constexpr uint8_t alignSelfOffset = - alignItemsOffset + minimumBitCount(); + alignItemsOffset + minimumBitCount(); static constexpr uint8_t positionTypeOffset = - alignSelfOffset + minimumBitCount(); + alignSelfOffset + minimumBitCount(); static constexpr uint8_t flexWrapOffset = positionTypeOffset + minimumBitCount(); static constexpr uint8_t overflowOffset = @@ -163,24 +164,24 @@ class YG_EXPORT Style { return {*this, justifyContentOffset}; } - YGAlign alignContent() const { - return getEnumData(flags, alignContentOffset); + Align alignContent() const { + return getEnumData(flags, alignContentOffset); } - BitfieldRef alignContent() { + BitfieldRef alignContent() { return {*this, alignContentOffset}; } - YGAlign alignItems() const { - return getEnumData(flags, alignItemsOffset); + Align alignItems() const { + return getEnumData(flags, alignItemsOffset); } - BitfieldRef alignItems() { + BitfieldRef alignItems() { return {*this, alignItemsOffset}; } - YGAlign alignSelf() const { - return getEnumData(flags, alignSelfOffset); + Align alignSelf() const { + return getEnumData(flags, alignSelfOffset); } - BitfieldRef alignSelf() { + BitfieldRef alignSelf() { return {*this, alignSelfOffset}; }