diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 1eccc7c1fba..b490dcca869 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -1027,8 +1027,12 @@ static MinContentSize measureOrWalkMinContentMainSize( const Direction direction = node->resolveDirection(ownerDirection); // Children add up along the container's main axis; across it the largest - // counts. - const bool alongMainAxis = isRow(node->style().flexDirection()) == wantRow; + // counts. A wrapping row can put each child on a line of its own, so its + // largest child counts along it too (css-flexbox-1 §9.9.1). A wrapping + // column still adds up: Chrome finds a min-content height by layout at an + // indefinite height, where nothing wraps. + const bool childrenAddUp = isRow(node->style().flexDirection()) == wantRow && + (node->style().flexWrap() == Wrap::NoWrap || !wantRow); float minContent = 0.0f; size_t itemCount = 0; @@ -1052,7 +1056,7 @@ static MinContentSize measureOrWalkMinContentMainSize( generationCount); const float childSize = child.size + childStyle.computeMarginForAxis(requestedAxis, ownerWidth); - minContent = alongMainAxis ? minContent + childSize + minContent = childrenAddUp ? minContent + childSize : std::max(minContent, childSize); resolvesAgainstOwnerWidth = resolvesAgainstOwnerWidth || child.resolvesAgainstOwnerWidth || childStyle.hasPercentMargin(); @@ -1060,7 +1064,7 @@ static MinContentSize measureOrWalkMinContentMainSize( // A percentage gap resolves against the size being found, so it counts as // zero (css-sizing-3 §5.2.1). - if (alongMainAxis && itemCount > 1) { + if (childrenAddUp && itemCount > 1) { minContent += node->style().computeGapForAxis(requestedAxis, 0.0f) * static_cast(itemCount - 1); } @@ -1190,9 +1194,9 @@ static MinContentSize computeChildMinContentContribution( // * Container: iterate in-flow children. For each, take its // min-content contribution along `requestedAxis` plus its margins: // the sum of them where that is the container's main axis, the -// largest where it is its cross axis. Add the gaps between them -// along the main axis, and the container's own padding and border -// on both ends of the axis. +// largest where it is its cross axis or the container is a +// wrapping row. Add the gaps between the children that add up, and +// the container's own padding and border on both ends of the axis. // // Container-level recursion does no layout writes (no positions, no // alignment, no flex distribution); only the descendant leaf measure