diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 3d7e570e5201..9411d296d495 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -456,6 +456,27 @@ static void computeFlexBasisForChild( child->getLayout().measuredDimension(dimension(mainAxis)), paddingAndBorderForAxis(child, mainAxis, direction, ownerWidth)))); } + + // A container sized by its content counts each item's max-content + // contribution: its content size, capped by a flex basis that is a length if + // the item cannot grow and floored by it if the item cannot shrink + // (css-flexbox-1 ยง9.9.3). Yoga does not flex the items of such a container, + // so the contribution is also the item's flex base size. + if (yoga::isUndefined(mainAxisSize) && child->processFlexBasis().isPoints() && + child->getConfig()->isExperimentalFeatureEnabled( + ExperimentalFeature::WebFlexBasis)) { + const float flexBasis = yoga::maxOrDefined( + resolvedFlexBasis.unwrap(), + paddingAndBorderForAxis(child, mainAxis, direction, ownerWidth)); + float flexBaseSize = child->getLayout().computedFlexBasis.unwrap(); + if (child->resolveFlexGrow() == 0) { + flexBaseSize = yoga::minOrDefined(flexBaseSize, flexBasis); + } + if (child->resolveFlexShrink() == 0) { + flexBaseSize = yoga::maxOrDefined(flexBaseSize, flexBasis); + } + child->setLayoutComputedFlexBasis(FloatOptional(flexBaseSize)); + } child->setLayoutComputedFlexBasisGeneration(generationCount); }