diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 8d06148f34b..1eccc7c1fba 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -1031,6 +1031,7 @@ static MinContentSize measureOrWalkMinContentMainSize( const bool alongMainAxis = isRow(node->style().flexDirection()) == wantRow; float minContent = 0.0f; + size_t itemCount = 0; bool resolvesAgainstOwnerWidth = node->style().hasPercentPadding(); for (size_t i = 0; i < node->getChildCount(); i++) { @@ -1039,6 +1040,7 @@ static MinContentSize measureOrWalkMinContentMainSize( childStyle.positionType() == PositionType::Absolute) { continue; } + itemCount++; const MinContentSize child = computeChildMinContentContribution( node, @@ -1056,6 +1058,13 @@ static MinContentSize measureOrWalkMinContentMainSize( child.resolvesAgainstOwnerWidth || childStyle.hasPercentMargin(); } + // A percentage gap resolves against the size being found, so it counts as + // zero (css-sizing-3 ยง5.2.1). + if (alongMainAxis && itemCount > 1) { + minContent += node->style().computeGapForAxis(requestedAxis, 0.0f) * + static_cast(itemCount - 1); + } + minContent += node->style().computeFlexStartPaddingAndBorder( requestedAxis, direction, ownerWidth) + node->style().computeFlexEndPaddingAndBorder( @@ -1181,8 +1190,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 container's own -// padding and border on both ends of the axis. +// 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. // // Container-level recursion does no layout writes (no positions, no // alignment, no flex distribution); only the descendant leaf measure