Skip to content

Commit

Permalink
Extract isBaselineLayout()
Browse files Browse the repository at this point in the history
Summary: Moves `isBaselineLayout` out of `CalculateLayout` into `Baseline.h`. This function is called by flex line justification code, which I have been looking at extracting.

Differential Revision: D49177937

fbshipit-source-id: 61325e5ca9c1d79e27306ba96147fe5eeda0e2d2
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 12, 2023
1 parent 247717b commit dae902a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
19 changes: 19 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dae902a

Please sign in to comment.