From 0b3190e8df03eb23a329b259895eefe65326eacf Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Mon, 30 Nov 2026 09:02:42 -0800 Subject: [PATCH] Apply a length flex basis in a container sized by its content (#2108) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: * Apply a length flex basis in a container sized by its content A flex basis that is a length was used only when the container's main size was known. In a container sized by its content, such as the row of a horizontal scroll view, an item with `flex-basis: 300px` was as wide as its content instead. With the `WebFlexBasis` experimental feature, an item's flex base size in such a container is its size in the main axis, or its content size, capped by the flex basis if the item cannot grow and floored by it if the item cannot shrink. This is the item's max-content contribution (css-flexbox-1 §9.9.3). Co-Authored-By: Claude Fable 5.2 * Document the flex basis of items in a container sized by its content Co-Authored-By: Claude Fable 5.2 --------- Reviewed By: javache Differential Revision: D135044797 --- .../yoga/yoga/algorithm/CalculateLayout.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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); }