From 1532d65550d9bae2000cfdc7f1064bf1b36572f7 Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Fri, 4 Dec 2026 02:13:20 -0800 Subject: [PATCH] Size a baseline-aligned line by its other items' own sizes (#2138) (#60545) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/react/react-native/pull/60545 Why === A flex line holds its baseline-aligned items, placed on their shared baseline, and its other items, and its cross size is the larger of the two groups' extents ([css-flexbox-1 §9.4, step 8](https://www.w3.org/TR/css-flexbox-1/#algo-cross-line)). When a row has any baseline-aligned item, Yoga sizes each line as if every item were baseline-aligned: it adds the largest distance above a baseline to the largest distance below one, over all items. ```html
``` Chrome makes the row 60 high, the second item's height and margin, and stretches the fourth item to 60. Yoga makes both 90: the first item's 50 above its bottom edge plus the second item's 40 margin below its own. How === `justifyMainAxis` counts an item toward the line's ascent and descent only if it is baseline-aligned, and takes the line's cross size as the larger of that sum and the largest outer cross size among the other items. The pass that positions the items of a baseline or wrapping container already computes each line's height this way, so in a wrapping container the lines were already placed by the right heights while the container was sized by the wrong ones. No erratum gates this, as none gated #2107, which changed the same sum for a hidden baseline item. Only a row whose container or items ask for baseline alignment changes, and only when an item that is not baseline-aligned sets the largest ascent or descent, through a margin or through content that puts its baseline above its bottom edge; its line shrinks to what the positioning pass already uses. Test Plan ========= `yarn gentest -f YGAlignItemsTest` adds three fixtures with Chrome's values, and `cmake --build tests/build && tests/build/yogatests` passes. With `yoga/algorithm/CalculateLayout.cpp` reverted, two fail: in `align_self_baseline_line_stretches_items_to_its_size` (the markup above) the row and its stretched item are 90 high where Chrome has 60, and in `align_self_baseline_multiline_fits_lines`, a wrapping row of two lines, the row is 100 high where Chrome has 70. `align_baseline_line_fits_taller_flex_end_item` passes before and after: its tallest item is not baseline-aligned, and it fails (50 where Chrome has 70) if the line's size is taken from the baseline-aligned items alone. `yarn format-check` and `yarn lint` pass. Not run: the generated Java and JavaScript tests. Changelog: [General][Fixed] - Fix Yoga making a row with a baseline-aligned item taller than its items when another item's content or margins extend past the shared baseline Reviewed By: javache Differential Revision: D135515833 Signed-off-by: GitHub Workflows Support --- .../yoga/yoga/algorithm/CalculateLayout.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 398e5e9af6f..3728235181c 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -2018,7 +2018,8 @@ static void justifyMainAxis( flexLine.layout.mainDim += child->dimensionWithMargin(mainAxis, availableInnerWidth); - if (isNodeBaselineLayout) { + if (isNodeBaselineLayout && + resolveChildAlignment(node, child) == Align::Baseline) { // If the child is baseline aligned then the cross dimension is // calculated by adding maxAscent and maxDescent from the baseline. const float ascent = calculateBaseline(child) + @@ -2037,7 +2038,7 @@ static void justifyMainAxis( } else { // The cross dimension is the max of the elements dimension since // there can only be one element in that cross dimension in the case - // when the items are not baseline aligned + // when the item is not baseline aligned flexLine.layout.crossDim = yoga::maxOrDefined( flexLine.layout.crossDim, child->dimensionWithMargin(crossAxis, availableInnerWidth)); @@ -2047,8 +2048,11 @@ static void justifyMainAxis( flexLine.layout.mainDim += trailingPaddingAndBorderMain; if (isNodeBaselineLayout) { - flexLine.layout.crossDim = - maxAscentForCurrentLine + maxDescentForCurrentLine; + // The line fits both its baseline-aligned items, placed on their shared + // baseline, and its largest other item (css-flexbox-1 §9.4, step 8). + flexLine.layout.crossDim = yoga::maxOrDefined( + flexLine.layout.crossDim, + maxAscentForCurrentLine + maxDescentForCurrentLine); } }