From 2d3d3080bba7d36baf85c965ae2b8c9c6d5ac7ea Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 12 Sep 2023 19:08:55 -0700 Subject: [PATCH] Extract isBaselineLayout() (#39400) Summary: X-link: https://github.com/facebook/yoga/pull/1375 Pull Request resolved: https://github.com/facebook/react-native/pull/39400 Moves `isBaselineLayout` out of `CalculateLayout` into `Baseline.h`. This function is called by flex line justification code, which I have been looking at extracting. Reviewed By: yungsters Differential Revision: D49177937 fbshipit-source-id: 02c13aa0b02b26cb60ef197473b90e06d53d5f8d --- .../yoga/yoga/algorithm/Baseline.cpp | 19 +++++++++++++++++++ .../yoga/yoga/algorithm/Baseline.h | 3 +++ .../yoga/yoga/algorithm/CalculateLayout.cpp | 19 ------------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp index 5042074a1e8227..1cbfbd188342c1 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp @@ -62,4 +62,23 @@ float calculateBaseline(const yoga::Node* node, void* layoutContext) { return baseline + baselineChild->getLayout().position[YGEdgeTop]; } +bool isBaselineLayout(const yoga::Node* node) { + if (isColumn(node->getStyle().flexDirection())) { + return false; + } + if (node->getStyle().alignItems() == YGAlignBaseline) { + 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) { + return true; + } + } + + return false; +} + } // namespace facebook::yoga diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.h b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.h index 2e6b0158453334..71fb3d520d39cf 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.h +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.h @@ -15,4 +15,7 @@ namespace facebook::yoga { // Calculate baseline represented as an offset from the top edge of the node. float calculateBaseline(const yoga::Node* node, void* layoutContext); +// Whether any of the children of this node participate in baseline alignment +bool isBaselineLayout(const yoga::Node* node); + } // namespace facebook::yoga diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index cbd75ee0470aa1..78766ede9380ba 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -50,25 +50,6 @@ bool calculateLayoutInternal( const uint32_t depth, const uint32_t generationCount); -static bool isBaselineLayout(const yoga::Node* node) { - if (isColumn(node->getStyle().flexDirection())) { - return false; - } - if (node->getStyle().alignItems() == YGAlignBaseline) { - 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) { - return true; - } - } - - return false; -} - static inline float dimensionWithMargin( const yoga::Node* const node, const YGFlexDirection axis,