diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 03032cf0535..8d06148f34b 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -1026,13 +1026,11 @@ static MinContentSize measureOrWalkMinContentMainSize( } const Direction direction = node->resolveDirection(ownerDirection); - const FlexDirection nodeMainAxis = - resolveDirection(node->style().flexDirection(), direction); - const FlexDirection nodeCrossAxis = - resolveCrossDirection(nodeMainAxis, direction); + // Children add up along the container's main axis; across it the largest + // counts. + const bool alongMainAxis = isRow(node->style().flexDirection()) == wantRow; - float mainTotal = 0.0f; - float crossMax = 0.0f; + float minContent = 0.0f; bool resolvesAgainstOwnerWidth = node->style().hasPercentPadding(); for (size_t i = 0; i < node->getChildCount(); i++) { @@ -1042,47 +1040,27 @@ static MinContentSize measureOrWalkMinContentMainSize( continue; } - const MinContentSize childMain = computeChildMinContentContribution( + const MinContentSize child = computeChildMinContentContribution( node, i, - nodeMainAxis, + requestedAxis, direction, ownerWidth, ownerHeight, generationCount); - const MinContentSize childCross = computeChildMinContentContribution( - node, - i, - nodeCrossAxis, - direction, - ownerWidth, - ownerHeight, - generationCount); - - mainTotal += childMain.size + - childStyle.computeMarginForAxis(nodeMainAxis, ownerWidth); - crossMax = std::max( - crossMax, - childCross.size + - childStyle.computeMarginForAxis(nodeCrossAxis, ownerWidth)); + const float childSize = + child.size + childStyle.computeMarginForAxis(requestedAxis, ownerWidth); + minContent = alongMainAxis ? minContent + childSize + : std::max(minContent, childSize); resolvesAgainstOwnerWidth = resolvesAgainstOwnerWidth || - childMain.resolvesAgainstOwnerWidth || - childCross.resolvesAgainstOwnerWidth || childStyle.hasPercentMargin(); + child.resolvesAgainstOwnerWidth || childStyle.hasPercentMargin(); } - mainTotal += node->style().computeFlexStartPaddingAndBorder( - nodeMainAxis, direction, ownerWidth) + - node->style().computeFlexEndPaddingAndBorder( - nodeMainAxis, direction, ownerWidth); - crossMax += node->style().computeFlexStartPaddingAndBorder( - nodeCrossAxis, direction, ownerWidth) + + minContent += node->style().computeFlexStartPaddingAndBorder( + requestedAxis, direction, ownerWidth) + node->style().computeFlexEndPaddingAndBorder( - nodeCrossAxis, direction, ownerWidth); + requestedAxis, direction, ownerWidth); - const bool nodeMainIsRow = isRow(nodeMainAxis); - const float widthMin = nodeMainIsRow ? mainTotal : crossMax; - const float heightMin = nodeMainIsRow ? crossMax : mainTotal; - const float minContent = wantRow ? widthMin : heightMin; layout.minContent[axisIndex] = minContent; layout.minContentOwnerWidth[axisIndex] = ownerWidth; layout.setMinContentResolvesAgainstOwnerWidth( @@ -1201,10 +1179,10 @@ static MinContentSize computeChildMinContentContribution( // respond with 0 along their scroll axis. // * Empty leaf: return 0. // * Container: iterate in-flow children. For each, take its -// min-content contribution along the container's own main axis (sum -// into `mainTotal`) and along its cross axis (max into `crossMax`), -// plus the child's margins. Add the container's own padding and -// border on both ends of each axis. Project onto `requestedAxis`. +// 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. // // Container-level recursion does no layout writes (no positions, no // alignment, no flex distribution); only the descendant leaf measure