Skip to content

Commit c65964d

Browse files
authored
Skip display: none children when finding a flex container's baseline (#2107)
Summary: A `display: none` child is not a flex item, so it cannot supply its container's baseline (css-flexbox-1 §8.5) or make its row a baseline layout. `calculateBaseline` chose a hidden first child, whose zeroed-out layout has a NaN measured height, and `isBaselineLayout` counted a hidden `align-self: baseline` child. `calculateBaseline` also read the line index of children that are not flex items before skipping them. Only flex items are assigned to lines, so a stale index from an earlier layout could end the search early. Reviewed By: javache Differential Revision: D135033729 Pull Request resolved: #60407
1 parent 239667f commit c65964d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • packages/react-native/ReactCommon/yoga/yoga/algorithm

‎packages/react-native/ReactCommon/yoga/yoga/algorithm/Baseline.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ float calculateBaseline(const yoga::Node* node) {
3333

3434
yoga::Node* baselineChild = nullptr;
3535
for (auto child : node->getLayoutChildren()) {
36+
// Children that are not flex items take no part in baseline alignment, and
37+
// their line index is stale: only flex items are assigned to lines.
38+
if (child->style().positionType() == PositionType::Absolute ||
39+
child->style().display() == Display::None) {
40+
continue;
41+
}
3642
if (child->getLineIndex() > 0) {
3743
break;
3844
}
39-
if (child->style().positionType() == PositionType::Absolute) {
40-
continue;
41-
}
4245
if (resolveChildAlignment(node, child) == Align::Baseline ||
4346
child->isReferenceBaseline()) {
4447
baselineChild = child;
@@ -67,6 +70,7 @@ bool isBaselineLayout(const yoga::Node* node) {
6770
}
6871
for (auto child : node->getLayoutChildren()) {
6972
if (child->style().positionType() != PositionType::Absolute &&
73+
child->style().display() != Display::None &&
7074
child->style().alignSelf() == Align::Baseline) {
7175
return true;
7276
}

0 commit comments

Comments
 (0)