From ebcd1ab1ab743f2b0d4b3df16a822f7bc170d58c Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 19 Sep 2023 16:30:02 -0700 Subject: [PATCH] C++ style enums 15/N: Display (#39541) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39541 X-link: https://github.com/facebook/yoga/pull/1397 Moves internal usages of YGDisplay to Display bypass-github-export-checks Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D49361952 fbshipit-source-id: a961efaa35a3fed01659d23783bf90e0b47656f0 --- .../components/view/ConcreteViewShadowNode.h | 2 +- .../components/view/ViewShadowNode.cpp | 2 +- .../renderer/components/view/conversions.h | 22 +++++++++---------- .../components/view/tests/ViewTest.cpp | 2 +- .../mounting/tests/StackingContextTest.cpp | 2 +- .../ReactCommon/yoga/yoga/Yoga.cpp | 4 ++-- .../yoga/yoga/algorithm/CalculateLayout.cpp | 14 ++++++------ .../yoga/yoga/algorithm/FlexLine.cpp | 2 +- .../yoga/yoga/debug/NodeToString.cpp | 3 +-- .../ReactCommon/yoga/yoga/style/Style.h | 7 +++--- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/ConcreteViewShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/view/ConcreteViewShadowNode.h index 54683517191..299b8db6ff3 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/ConcreteViewShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/ConcreteViewShadowNode.h @@ -88,7 +88,7 @@ class ConcreteViewShadowNode : public ConcreteShadowNode< void initialize() noexcept { auto& props = BaseShadowNode::getConcreteProps(); - if (props.yogaStyle.display() == YGDisplayNone) { + if (props.yogaStyle.display() == yoga::Display::None) { BaseShadowNode::traits_.set(ShadowNodeTraits::Trait::Hidden); } else { BaseShadowNode::traits_.unset(ShadowNodeTraits::Trait::Hidden); 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 4bbf90d73d4..42575ec6085 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/ViewShadowNode.cpp @@ -45,7 +45,7 @@ void ViewShadowNode::initialize() noexcept { viewProps.opacity != 1.0 || viewProps.transform != Transform{} || (viewProps.zIndex.has_value() && viewProps.yogaStyle.positionType() != yoga::PositionType::Static) || - viewProps.yogaStyle.display() == YGDisplayNone || + viewProps.yogaStyle.display() == yoga::Display::None || viewProps.getClipsContentToBounds() || viewProps.events.bits.any() || isColorMeaningful(viewProps.shadowColor) || viewProps.accessibilityElementsHidden || 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 cda87ef4e66..08f83b69183 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h @@ -141,9 +141,9 @@ inline LayoutMetrics layoutMetricsFromYogaNode(yoga::Node& yogaNode) { layoutMetrics.borderWidth.bottom + floatFromYogaFloat(YGNodeLayoutGetPadding(&yogaNode, YGEdgeBottom))}; - layoutMetrics.displayType = yogaNode.getStyle().display() == YGDisplayNone - ? DisplayType::None - : DisplayType::Flex; + layoutMetrics.displayType = + yogaNode.getStyle().display() == yoga::Display::None ? DisplayType::None + : DisplayType::Flex; layoutMetrics.layoutDirection = YGNodeLayoutGetDirection(&yogaNode) == YGDirectionRTL @@ -385,22 +385,22 @@ inline void fromRawValue( inline void fromRawValue( const PropsParserContext& context, const RawValue& value, - YGDisplay& result) { - result = YGDisplayFlex; + yoga::Display& result) { + result = yoga::Display::Flex; react_native_expect(value.hasType()); if (!value.hasType()) { return; } auto stringValue = (std::string)value; if (stringValue == "flex") { - result = YGDisplayFlex; + result = yoga::Display::Flex; return; } if (stringValue == "none") { - result = YGDisplayNone; + result = yoga::Display::None; return; } - LOG(ERROR) << "Could not parse YGDisplay:" << stringValue; + LOG(ERROR) << "Could not parse yoga::Display:" << stringValue; react_native_expect(false); } @@ -833,11 +833,11 @@ inline std::string toString(const yoga::Overflow& value) { } } -inline std::string toString(const YGDisplay& value) { +inline std::string toString(const yoga::Display& value) { switch (value) { - case YGDisplayFlex: + case yoga::Display::Flex: return "flex"; - case YGDisplayNone: + case yoga::Display::None: return "none"; } } 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 e2964738145..f948248c680 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 @@ -137,7 +137,7 @@ TEST_F(YogaDirtyFlagTest, changingLayoutSubPropsMustDirtyYogaNode) { auto& props = *viewProps; props.yogaStyle.alignContent() = yoga::Align::Baseline; - props.yogaStyle.display() = YGDisplayNone; + props.yogaStyle.display() = yoga::Display::None; return oldShadowNode.clone(ShadowNodeFragment{viewProps}); }); diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp index 556df62b157..262e7e10c2f 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StackingContextTest.cpp @@ -764,7 +764,7 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) { mutateViewShadowNodeProps_(nodeBB_, [](ViewProps& props) { auto& yogaStyle = props.yogaStyle; - yogaStyle.display() = YGDisplayNone; + yogaStyle.display() = yoga::Display::None; }); testViewTree_([](const StubViewTree& viewTree) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp b/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp index 039dc3fb507..42fd5821c7a 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp @@ -508,10 +508,10 @@ YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { } void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { - updateStyle(node, &Style::display, display); + updateStyle(node, &Style::display, scopedEnum(display)); } YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { - return resolveRef(node)->getStyle().display(); + return unscopedEnum(resolveRef(node)->getStyle().display()); } // TODO(T26792433): Change the API to accept FloatOptional. diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 6b303b610fa..d0f2eb81109 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -804,7 +804,7 @@ static float computeFlexBasisForChildren( for (auto child : children) { child->resolveDimension(); - if (child->getStyle().display() == YGDisplayNone) { + if (child->getStyle().display() == Display::None) { zeroOutLayoutRecursively(child); child->setHasNewLayout(true); child->setDirty(false); @@ -1307,7 +1307,7 @@ static void justifyMainAxis( const auto child = node->getChild(i); const Style& childStyle = child->getStyle(); const LayoutResults& childLayout = child->getLayout(); - if (childStyle.display() == YGDisplayNone) { + if (childStyle.display() == Display::None) { continue; } if (childStyle.positionType() == PositionType::Absolute && @@ -1863,7 +1863,7 @@ static void calculateLayoutImpl( if (performLayout) { for (size_t i = startOfLineIndex; i < endOfLineIndex; i++) { const auto child = node->getChild(i); - if (child->getStyle().display() == YGDisplayNone) { + if (child->getStyle().display() == Display::None) { continue; } if (child->getStyle().positionType() == PositionType::Absolute) { @@ -2069,7 +2069,7 @@ static void calculateLayoutImpl( float maxDescentForCurrentLine = 0; for (ii = startIndex; ii < childCount; ii++) { const auto child = node->getChild(ii); - if (child->getStyle().display() == YGDisplayNone) { + if (child->getStyle().display() == Display::None) { continue; } if (child->getStyle().positionType() != PositionType::Absolute) { @@ -2112,7 +2112,7 @@ static void calculateLayoutImpl( if (performLayout) { for (ii = startIndex; ii < endIndex; ii++) { const auto child = node->getChild(ii); - if (child->getStyle().display() == YGDisplayNone) { + if (child->getStyle().display() == Display::None) { continue; } if (child->getStyle().positionType() != PositionType::Absolute) { @@ -2318,7 +2318,7 @@ static void calculateLayoutImpl( if (performLayout) { // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN for (auto child : node->getChildren()) { - if (child->getStyle().display() == YGDisplayNone || + if (child->getStyle().display() == Display::None || child->getStyle().positionType() != PositionType::Absolute) { continue; } @@ -2352,7 +2352,7 @@ static void calculateLayoutImpl( if (needsMainTrailingPos || needsCrossTrailingPos) { for (size_t i = 0; i < childCount; i++) { const auto child = node->getChild(i); - if (child->getStyle().display() == YGDisplayNone) { + if (child->getStyle().display() == Display::None) { continue; } if (needsMainTrailingPos) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp index 0721941994f..f254a7a5739 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp @@ -38,7 +38,7 @@ FlexLine calculateFlexLine( // Add items to the current line until it's full or we run out of items. for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) { auto child = node->getChild(endOfLineIndex); - if (child->getStyle().display() == YGDisplayNone || + if (child->getStyle().display() == Display::None || child->getStyle().positionType() == PositionType::Absolute) { continue; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp b/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp index 225be915400..17a28b40063 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/debug/NodeToString.cpp @@ -174,8 +174,7 @@ void nodeToString( } if (style.display() != yoga::Node{}.getStyle().display()) { - appendFormattedString( - str, "display: %s; ", YGDisplayToString(style.display())); + appendFormattedString(str, "display: %s; ", toString(style.display())); } appendEdges(str, "margin", style.margin()); appendEdges(str, "padding", style.padding()); diff --git a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h index 6a382823fd3..01a572d0514 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/style/Style.h +++ b/packages/react-native/ReactCommon/yoga/yoga/style/Style.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -209,10 +210,10 @@ class YG_EXPORT Style { return {*this, overflowOffset}; } - YGDisplay display() const { - return getEnumData(flags, displayOffset); + Display display() const { + return getEnumData(flags, displayOffset); } - BitfieldRef display() { + BitfieldRef display() { return {*this, displayOffset}; }