From 1a5319a8b04fe3c8aa5a455bf183306d91557da6 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 2 Dec 2026 06:04:15 -0800 Subject: [PATCH 1/7] Count the sizes nested boxes state in automatic minimum sizes (#2101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: * Count the sizes nested boxes state in automatic minimum sizes Why === With automatic minimum sizes on (`YGErrataMinSizeUndefinedInsteadOfAuto` off), a flex item does not shrink below its min-content size (css-flexbox-1 §4.5). That size is built from its children's min-content contributions (css-sizing-3 §5.2), and a child that states a size contributes that size. Yoga's min-content walk reads only content (measure functions, padding, border, margins) and ignores `width`, `height`, `min-*`, `max-*` and `aspect-ratio` on everything below the item: ```html
``` How === The walk takes each child's min-content contribution along the axis it is asked for: - the size the child states, with its padding and border for a content-box size; - otherwise its content's min-content size, as before, or, where larger, the size its aspect ratio transfers from the size it states on the other axis (css-sizing-4); - clamped to the minimum and maximum it states, and no less than its padding and border (`boundAxis`). A percentage size, minimum or maximum depends on the size being found, so it behaves as `auto` or as no limit (css-sizing-3 §5.2.1). A child that states its size on an axis is not measured, walked or cloned for that axis. The item's own specified size suggestion is unchanged. The walk still differs from the specifications or from Chrome in these ways: - A child's `flex-basis` and flex factors are not read. css-flexbox-1 §9.9.3 caps a flex item's contribution at its flex base size if it cannot grow and floors it there if it cannot shrink, and Chrome counts a definite flex basis for a child that cannot shrink. An item around a `flex: 0 0 70px` child is 70px in Chrome; with this change and without it, the item is the size of the child's content. - §9.9.3 also takes the larger of a flex item's min-content size and its stated size. The walk takes the stated size, as css-sizing-3 does. For a child that cannot grow, the cap gives the same result (`child_width_smaller_than_content`: 20px in Chrome). Chrome was not checked for a child that can grow. - A `display: contents` child is still walked, and counted, as a box of its own. - A percentage padding or margin resolves against the owner's width, as it does elsewhere in the walk. Chrome resolves it against zero for an intrinsic contribution (css-sizing-3 §5.2.1): a content-box child with `width: 30px; padding-left: 10%` contributes 30px in Chrome and 50px under a 200px owner in Yoga. Following Chrome would remove most of the walk's owner-width memo key, so it belongs in a change of its own. - The aspect-ratio transfer uses the border-box size, also for a content-box child. `container_min_content_memo_respects_owner_width` relied on a 20px spacer not counting toward its parent's min-content size. The parent now has `max-width: 70px`, which keeps the two probes the test compares apart. Test Plan ========= `yarn gentest -f YGAutoMinSizeTest` generates the new fixtures in `YGAutoMinSizeTest.html` from Chrome. `cmake --build tests/build && tests/build/yogatests` passes with them and with the hand-written tests for whether the probe runs and for the memo. With the change to `CalculateLayout.cpp` reverted, every new test fails. The width or height of the shrinking item, in Chrome and without the change: | Fixture | Chrome | Without the change | | --- | --- | --- | | `counts_child_width` | 100 | 20 | | `counts_child_height` | 100 | 20 | | `counts_widest_child_of_column` | 60 | 20 | | `item_width_larger_than_content` | 30 | 10 | | `child_width_larger_than_content` | 100 | 20 | | `child_width_smaller_than_content` | 20 | 10 | | `child_min_width` | 50 | 20 | | `child_max_width` | 40 | 20 | | `child_percent_width` | 30 | 20 | | `child_content_box_width` | 66 | 20 | | `child_padding_exceeds_width` | 40 | 20 | | `child_aspect_ratio` | 60 | 20 | | `child_aspect_ratio_column` | 60 | 20 | | `counts_content_of_overflow_hidden_child` | 130 | 60 | `child_with_stated_size_skips_min_content_probe` sees 2 probes where it expects none, and `stated_size_with_percentage_padding_follows_owner_width` sees 10 and 0 where it expects 50 and 40. `yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes. The generated Java tests were not run, because the Gradle project has no unit-test source set, and neither were the generated JavaScript tests, which need Emscripten. Changelog: [General][Fixed] - Fix Yoga's automatic minimum size ignoring the width, height, min/max sizes and aspect ratio of boxes inside a flex item * Mark percentage padding in a child's min-content contribution An empty child, or one with a static min-content size, reports a contribution that does not depend on the owner's width, but boundAxis then floors it at the child's padding and border. With a percentage padding the result depends on the owner's width, so the memo of the container around it has to be keyed on that width. Co-Authored-By: Claude Opus 5.5 --------- Wearable integration ==================== The wearable UI adapter retains zero automatic minima for unmeasured, untyped app boxes and size-contained boxes, without disabling Yoga's native WSS and measured-text minima. Explicit minima remain authoritative; containment and type-rule changes remap both minimum axes so compatibility defaults do not persist after they stop applying. Differential Revision: D135304422 --- .../yoga/yoga/algorithm/CalculateLayout.cpp | 80 +++++++++++++++++-- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index db21f29fbff..03032cf0535 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -982,11 +982,11 @@ static std::optional readMinContentMainSize( return std::nullopt; } -static MinContentSize computeChildMinContentMainSize( +static MinContentSize computeChildMinContentContribution( yoga::Node* node, size_t index, - FlexDirection requestedAxis, - Direction ownerDirection, + FlexDirection axis, + Direction direction, float ownerWidth, float ownerHeight, uint32_t generationCount); @@ -1042,7 +1042,7 @@ static MinContentSize measureOrWalkMinContentMainSize( continue; } - const MinContentSize childMain = computeChildMinContentMainSize( + const MinContentSize childMain = computeChildMinContentContribution( node, i, nodeMainAxis, @@ -1050,7 +1050,7 @@ static MinContentSize measureOrWalkMinContentMainSize( ownerWidth, ownerHeight, generationCount); - const MinContentSize childCross = computeChildMinContentMainSize( + const MinContentSize childCross = computeChildMinContentContribution( node, i, nodeCrossAxis, @@ -1118,6 +1118,72 @@ static MinContentSize computeChildMinContentMainSize( generationCount); } +// The size `style` states on `dimension`, as a border-box size. A percentage +// resolves against the size the min-content walk is finding, so it behaves as +// auto there (css-sizing-3 §5.2.1). +static FloatOptional statedSize( + const Style& style, + const Direction direction, + const Dimension dimension, + const float ownerWidth) { + const FloatOptional size = style.dimension(dimension).resolve(YGUndefined); + if (size.isUndefined() || style.boxSizing() == BoxSizing::BorderBox) { + return size; + } + return size + + FloatOptional{style.computePaddingAndBorderForDimension( + direction, dimension, ownerWidth)}; +} + +// The min-content contribution along `axis` of the child of `node` at `index`, +// without its margins (css-sizing-3 §5.2): the size the child states on that +// axis, else its content's min-content size or, where that is larger, the size +// its aspect ratio transfers from the size it states on the other axis +// (css-sizing-4), within the minimum and maximum it states. A child that states +// its size on `axis` is not measured, walked or cloned for it. +static MinContentSize computeChildMinContentContribution( + yoga::Node* const node, + const size_t index, + const FlexDirection axis, + const Direction direction, + const float ownerWidth, + const float ownerHeight, + const uint32_t generationCount) { + // A clone made below has the same style. + const Style& style = node->getChild(index)->style(); + MinContentSize contribution{0.0f, false}; + const FloatOptional stated = + statedSize(style, direction, dimension(axis), ownerWidth); + if (stated.isDefined()) { + contribution = {stated.unwrap(), style.hasPercentPadding()}; + } else { + contribution = computeChildMinContentMainSize( + node, index, axis, direction, ownerWidth, ownerHeight, generationCount); + const FloatOptional aspectRatio = style.aspectRatio(); + const FloatOptional statedAcross = statedSize( + style, + direction, + isRow(axis) ? Dimension::Height : Dimension::Width, + ownerWidth); + if (aspectRatio.isDefined() && statedAcross.isDefined()) { + contribution.size = std::max( + contribution.size, + isRow(axis) ? statedAcross.unwrap() * aspectRatio.unwrap() + : statedAcross.unwrap() / aspectRatio.unwrap()); + } + } + + return { + boundAxis( + node->getChild(index), + axis, + direction, + contribution.size, + YGUndefined, + ownerWidth), + contribution.resolvesAgainstOwnerWidth || style.hasPercentPadding()}; +} + // Returns the min-content size of `node` along `requestedAxis`, used by CSS // Flexbox §4.5 automatic minimum sizing. // @@ -1135,8 +1201,8 @@ static MinContentSize computeChildMinContentMainSize( // respond with 0 along their scroll axis. // * Empty leaf: return 0. // * Container: iterate in-flow children. For each, take its -// min-content along the container's own main axis (sum into -// `mainTotal`) and along its cross axis (max into `crossMax`), +// 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`. // From ea48331206f1ca9708b36dabe07f0a35963d5bce Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Wed, 2 Dec 2026 06:04:20 -0800 Subject: [PATCH 2/7] Walk only the requested axis for a container's min-content size (#2102) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: * Walk only the requested axis for a container's min-content size Why === The min-content walk behind automatic minimum sizes (css-flexbox-1 §4.5) is asked for a container's size on one axis. For every child it computed the size on both of the container's axes, summed one, took the largest of the other, and returned only the one it was asked for. The work on the other axis was wasted: a leaf was measured, and a container walked, on an axis no flex line needed. How === The walk asks each child for the requested axis alone. It sums the children where that is the container's main axis and takes the largest where it is the cross axis. Layout results are unchanged. The memo already kept a leaf to one probe per axis per layout, so the saving is one measure call per leaf, and one walk per container, on the axis nobody asked for. Test Plan ========= `cmake --build tests/build && tests/build/yogatests` passes. `nested_leaf_probed_at_most_once_per_axis_per_layout`, a measured leaf ten containers deep in a shrinking row, accepted up to two probes. It now expects one, and sees 2 without this change. `yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes. Changelog: [General][Changed] - Yoga calls a measure function for an automatic minimum size only on the axis it needs * Simplify alongMainAxis check and assert probed axis in test --------- Reviewed By: javache Differential Revision: D135328393 --- .../yoga/yoga/algorithm/CalculateLayout.cpp | 58 ++++++------------- 1 file changed, 18 insertions(+), 40 deletions(-) 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 From d1bb32458f2c687486ffe20f456ecd1622fdbd22 Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Wed, 2 Dec 2026 06:04:28 -0800 Subject: [PATCH 3/7] Count gaps in a flex container's min-content size (#2103) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Why === A flex item does not shrink below its min-content size (css-flexbox-1 §4.5). When the item is itself a flex container, Chrome counts the gaps between its children along its main axis in that size. Yoga's min-content walk leaves them out, so the item can shrink until its children overflow it by the gaps: ```html
``` How === The walk adds one gap between each two in-flow children when it sums them along the container's main axis. A percentage gap counts as zero, because a percentage gutter resolves against zero for an intrinsic size contribution (css-sizing-3 §5.2.1). Chrome does the same. Test Plan ========= `yarn gentest -f YGAutoMinSizeTest` generates the new fixtures from Chrome, and `cmake --build tests/build && tests/build/yogatests` passes. With the change reverted, two fixtures fail: | Fixture | Chrome | Without the change | | --- | --- | --- | | `counts_column_gaps` (item width) | 130 | 90 | | `counts_row_gaps` (item height) | 80 | 60 | `gaps_skip_cross_axis_and_absolute_children` and `percent_gap_counts_as_zero` pass with and without the change; they pin what must not count. Adding cross-axis gaps, counting an absolutely positioned child, or resolving a percentage gap against the owner's width makes one of them fail (50 becomes 70, 30 becomes 50, and 60 becomes 80). `yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes. The generated Java tests were not run, because the Gradle project has no unit-test source set, and neither were the generated JavaScript tests, which need Emscripten. Changelog: [General][Fixed] - Fix Yoga's automatic minimum size leaving out the gaps between a flex item's children Reviewed By: javache Differential Revision: D135335463 --- .../yoga/yoga/algorithm/CalculateLayout.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 From 84c48c5a54863d6c325930c278f4e213741b6bd4 Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Wed, 2 Dec 2026 06:04:31 -0800 Subject: [PATCH 4/7] Size a wrapping row's min-content width by its widest child (#2104) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Why === A flex item does not shrink below its min-content size (css-flexbox-1 §4.5). A wrapping row can put each child on a line of its own, so its min-content width is that of its widest child (§9.9.1: "for a multi-line container, the min-content main size is simply the largest min-content contribution of all the non-collapsed flex items"). Yoga's walk sums the children whether or not the container wraps, so a wrapping row never narrows enough to wrap: ```html
``` How === The walk takes the largest child, and no gaps, along the main axis of a wrapping row. A wrapping column keeps the sum, which differs from §9.9.1: its sentence covers both directions. Chrome finds a min-content height by laying the box out at an indefinite height, where a column never wraps, as css-sizing-3 §2.1 has it for block containers (the min-content block size equals the max-content block size). `wrapping_column_counts_all_children` records this. Only Chrome was checked. The min-content height of a wrapping row is not addressed. It depends on where the row's lines break, which the walk cannot know. The walk still takes the tallest child, so a column can shrink a wrapping row below the lines it wraps to. Test Plan ========= `yarn gentest -f YGAutoMinSizeTest` generates the new fixtures from Chrome, and `cmake --build tests/build && tests/build/yogatests` passes. With the change reverted, `wrapping_row_counts_widest_child` fails: the row is 140 wide and 10 tall where Chrome has 70 and 40. `wrapping_column_counts_all_children` passes with and without the change (110 tall), and fails with 60 if the rule also applies to columns. `yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes. The generated Java tests were not run, because the Gradle project has no unit-test source set, and neither were the generated JavaScript tests, which need Emscripten. Changelog: [General][Fixed] - Fix Yoga's automatic minimum size keeping a wrapping row as wide as all of its children Reviewed By: javache Differential Revision: D135341618 --- .../yoga/yoga/algorithm/CalculateLayout.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 1eccc7c1fba..b490dcca869 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -1027,8 +1027,12 @@ static MinContentSize measureOrWalkMinContentMainSize( const Direction direction = node->resolveDirection(ownerDirection); // Children add up along the container's main axis; across it the largest - // counts. - const bool alongMainAxis = isRow(node->style().flexDirection()) == wantRow; + // counts. A wrapping row can put each child on a line of its own, so its + // largest child counts along it too (css-flexbox-1 §9.9.1). A wrapping + // column still adds up: Chrome finds a min-content height by layout at an + // indefinite height, where nothing wraps. + const bool childrenAddUp = isRow(node->style().flexDirection()) == wantRow && + (node->style().flexWrap() == Wrap::NoWrap || !wantRow); float minContent = 0.0f; size_t itemCount = 0; @@ -1052,7 +1056,7 @@ static MinContentSize measureOrWalkMinContentMainSize( generationCount); const float childSize = child.size + childStyle.computeMarginForAxis(requestedAxis, ownerWidth); - minContent = alongMainAxis ? minContent + childSize + minContent = childrenAddUp ? minContent + childSize : std::max(minContent, childSize); resolvesAgainstOwnerWidth = resolvesAgainstOwnerWidth || child.resolvesAgainstOwnerWidth || childStyle.hasPercentMargin(); @@ -1060,7 +1064,7 @@ static MinContentSize measureOrWalkMinContentMainSize( // A percentage gap resolves against the size being found, so it counts as // zero (css-sizing-3 §5.2.1). - if (alongMainAxis && itemCount > 1) { + if (childrenAddUp && itemCount > 1) { minContent += node->style().computeGapForAxis(requestedAxis, 0.0f) * static_cast(itemCount - 1); } @@ -1190,9 +1194,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 gaps between them -// along the main axis, and the container's own padding and border -// on both ends of the axis. +// largest where it is its cross axis or the container is a +// wrapping row. Add the gaps between the children that add up, 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 From f797618d73ba9e1022a1eaef8a2b7b3c466cfd44 Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Wed, 2 Dec 2026 06:04:36 -0800 Subject: [PATCH 5/7] Measure a leaf's min-content height at the width it is given (#2105) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: * Proposal: measure a leaf's min-content height at the width it is given Why === A flex item does not shrink below its min-content size (css-flexbox-1 §4.5). In a column that size is a height, and for text it is the height of the lines it wraps to at the box's width (css-sizing-3 §2.1: a block container's min-content block size equals its max-content block size). Yoga's min-content walk probes a measured leaf with at most zero on the probed axis and no limit on the other, so a text measurer answers with zero or with one unbroken line, and the text overflows its box: ```html
aaaa aaaa aaaa
``` This is a proposal because it changes the arguments a host's measure function is called with. How === With the experimental feature `MinContentHeightAtGivenWidth`, the walk measures the leaf at its content width (`AtMost`) with no limit on its height. Without the feature nothing changes. The walk finds the width on the way down from the flex container: a box's stated width, or its owner's content box less its margins, within its minimum and maximum. That is the box's width when it is stretched in a column; a narrower box that is not stretched may wrap to more lines than were measured. A row's children are walked against no width, so text below a row counts as unwrapped unless it, or a box between it and the row, states a width. In both cases the item can shrink further than its content needs. A wrapping column is treated as a column, since Chrome wraps its text at the column's width (`text_in_wrapping_column_keeps_wrapped_lines`). In a height walk, a percentage padding below the item resolves against this width. The leaf's height now depends on the owner's width, so its memo and those above it on that axis are keyed on `minContentOwnerWidth` (the existing `minContentResolvesAgainstOwnerWidth` flag). A new width measures the leaf again. The gate is the open question. The layout change exists only with `MinSizeUndefinedInsteadOfAuto` off; what needs a gate is the callback contract. `YGMinContentMeasureFunc`, and a leaf's `YGMeasureFunc` when it has none, is documented as called with `AtMost 0` on the probed axis, and a host that recognizes a height probe by those arguments would stop recognizing it. An experimental feature lets each host turn the fix on when its measure functions are ready. The alternative is an erratum that keeps the old probe, set by default like `MinSizeUndefinedInsteadOfAuto`: one switch fewer for a host that asks for `YGErrataNone`, but it changes the callback arguments for every such host at once. I will switch to it if you prefer. `YGNode.h` documents the new arguments either way. React Native's `MinContentTest` cases (`packages/react-native/ReactCommon/yoga/test/BaselineTest.cpp`) assert that a new width leaves a clean leaf shared. With the feature on, three of them hold only if the leaf's height is static (`YGNodeSetMinContentHeight`). Test Plan ========= `python3 enums.py` regenerates the enum files with no change, `yarn gentest -f YGAutoMinSizeTest` generates the new fixtures from Chrome, and `cmake --build tests/build && tests/build/yogatests` passes with them and with the hand-written tests for the measure function's arguments and the memo. The height of the shrinking item, in Chrome and with the change to `CalculateLayout.cpp` reverted: | Fixture | Chrome | Without the change | | --- | --- | --- | | `text_keeps_wrapped_lines` | 30 | 10 | | `nested_text_keeps_wrapped_lines` | 35 | 10 | | `text_wraps_inside_margin_and_padding` | 30 | 10 | | `text_wraps_at_stated_width` | 30 | 10 | | `text_wraps_at_stated_content_box_width` | 20 | 5 | | `text_wraps_inside_padded_parent` | 30 | 10 | | `text_wraps_at_max_width` | 30 | 10 | | `text_in_wrapping_column_keeps_wrapped_lines` | 30 | 5 | `text_fits_wider_parent`, `text_fits_min_width` and `text_below_row_is_not_wrapped` keep text wider than the container on one line (10). Without the change they give 5, and measuring at the container's width instead of the box's would give 30. `min_content_height_follows_given_width` gets 16 where it expects 32 and then 48, and `min_content_height_without_owner_width_is_unconstrained` fails on the measure modes. `min_content_height_probe_asks_for_at_most_zero` pins the contract with the feature off, and passes with and without the change. `yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes. The generated Java and JavaScript tests were not run. Changelog: [General][Added] - Add the Yoga experimental feature MinContentHeightAtGivenWidth, which keeps wrapped text in a column from shrinking below its lines when automatic minimum sizes are on * Resolve percentage margins in the min-content height walk against the parent's content width The walk gave each child its parent's content width for its padding, but its margins still used the grandparent's width. * Wrap text at its max-width when the min-content height walk has no width Below a row the walk passes no width, so a box's max-width was never applied and its text was measured on one line. --------- Reviewed By: javache Differential Revision: D135502567 --- .../facebook/yoga/YogaExperimentalFeature.kt | 4 +- .../ReactCommon/yoga/yoga/YGEnums.cpp | 2 + .../ReactCommon/yoga/yoga/YGEnums.h | 3 +- .../ReactCommon/yoga/yoga/YGNode.h | 17 ++- .../yoga/yoga/algorithm/CalculateLayout.cpp | 144 +++++++++++++----- .../yoga/yoga/enums/ExperimentalFeature.h | 3 +- 6 files changed, 125 insertions(+), 48 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaExperimentalFeature.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaExperimentalFeature.kt index aec70ac2469..bf122ae07f5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaExperimentalFeature.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaExperimentalFeature.kt @@ -11,7 +11,8 @@ package com.facebook.yoga public enum class YogaExperimentalFeature(public val intValue: Int) { WEB_FLEX_BASIS(0), - FIX_FLEX_BASIS_FIT_CONTENT(1); + FIX_FLEX_BASIS_FIT_CONTENT(1), + MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH(2); public fun intValue(): Int = intValue @@ -21,6 +22,7 @@ public enum class YogaExperimentalFeature(public val intValue: Int) { when (value) { 0 -> WEB_FLEX_BASIS 1 -> FIX_FLEX_BASIS_FIT_CONTENT + 2 -> MIN_CONTENT_HEIGHT_AT_GIVEN_WIDTH else -> throw IllegalArgumentException("Unknown enum value: $value") } } diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp index 017d6ee45ad..194e99a6aa6 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp @@ -135,6 +135,8 @@ const char* YGExperimentalFeatureToString(const YGExperimentalFeature value) { return "web-flex-basis"; case YGExperimentalFeatureFixFlexBasisFitContent: return "fix-flex-basis-fit-content"; + case YGExperimentalFeatureMinContentHeightAtGivenWidth: + return "min-content-height-at-given-width"; } return "unknown"; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h index c672870023a..b10b74f98fb 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h +++ b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h @@ -76,7 +76,8 @@ YG_DEFINE_ENUM_FLAG_OPERATORS(YGErrata) YG_ENUM_DECL( YGExperimentalFeature, YGExperimentalFeatureWebFlexBasis, - YGExperimentalFeatureFixFlexBasisFitContent) + YGExperimentalFeatureFixFlexBasisFitContent, + YGExperimentalFeatureMinContentHeightAtGivenWidth) YG_ENUM_DECL( YGFlexDirection, diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGNode.h b/packages/react-native/ReactCommon/yoga/yoga/YGNode.h index 4f8cdf81a52..89aa72b99d4 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGNode.h +++ b/packages/react-native/ReactCommon/yoga/yoga/YGNode.h @@ -226,17 +226,20 @@ YG_EXPORT bool YGNodeHasMeasureFunc(YGNodeConstRef node); * size along the main axis. * * The signature mirrors `YGMeasureFunc`. The algorithm calls this with - * `AtMost 0` along the probed axis and `Undefined` on the other. A + * `AtMost 0` along the probed axis and `Undefined` on the other. With + * `YGExperimentalFeatureMinContentHeightAtGivenWidth`, it probes a height + * with the node's width as an `AtMost` width and an `Undefined` height. A * min-content-aware Primitive can return its true minimum (e.g., `Image` * and `Collection` along the scroll axis can return 0; text returns its * longest-word width; etc.) without doing a full measure pass. * - * When unset, the algorithm falls back to the regular `YGMeasureFunc` - * invoked with the same `AtMost 0` constraint — preserving today's - * behavior. Setting this is a perf opt-in for Primitives whose min-content - * size is cheap to compute or differs from what the regular measure would - * return. Its results are kept, as a measure function's are, until the node is - * marked dirty. + * When unset, the algorithm falls back to the regular `YGMeasureFunc` with + * the same arguments. Setting this is a perf opt-in for Primitives whose + * min-content size is cheap to compute or differs from what the regular + * measure would return. Its results are kept, as a measure function's are, + * until the node is marked dirty. With + * `YGExperimentalFeatureMinContentHeightAtGivenWidth`, a height result is also + * measured again when the width it was measured at changes. */ typedef YGSize (*YGMinContentMeasureFunc)( YGNodeConstRef node, diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index b490dcca869..aa6131b410b 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -916,7 +916,8 @@ struct MinContentSize { }; // The min-content of a leaf with a measure function: its memoized measurement, -// which leaves out its padding and border, with them added. +// which leaves out its padding and border, with them added. A height measured +// at the leaf's width depends on the owner's width as well. static MinContentSize leafMinContentSize( const yoga::Node* const node, const FlexDirection requestedAxis, @@ -927,11 +928,12 @@ static MinContentSize leafMinContentSize( requestedAxis, leafDirection, ownerWidth) + node->style().computeFlexEndPaddingAndBorder( requestedAxis, leafDirection, ownerWidth); + const LayoutResults& layout = node->getLayout(); + const Dimension axisDimension = dimension(requestedAxis); return { - node->getLayout() - .minContent[yoga::to_underlying(dimension(requestedAxis))] + - paddingAndBorder, - node->style().hasPercentPadding()}; + layout.minContent[yoga::to_underlying(axisDimension)] + paddingAndBorder, + node->style().hasPercentPadding() || + layout.minContentResolvesAgainstOwnerWidth(axisDimension)}; } // The min-content of `node` that reading it gives, without writing to it: a @@ -955,31 +957,26 @@ static std::optional readMinContentMainSize( return MinContentSize{staticMin.unwrap(), false}; } - const Dimension axisDimension = dimension(requestedAxis); - if (node->hasMeasureFunc()) { - if (!hasMemoizedMinContent( - node, axisDimension, ownerDirection, generationCount)) { - return std::nullopt; - } - return leafMinContentSize(node, requestedAxis, ownerDirection, ownerWidth); - } - - if (node->getChildCount() == 0) { + if (!node->hasMeasureFunc() && node->getChildCount() == 0) { return MinContentSize{0.0f, false}; } + const Dimension axisDimension = dimension(requestedAxis); const LayoutResults& layout = node->getLayout(); const auto axisIndex = yoga::to_underlying(axisDimension); - if (hasMemoizedMinContent( - node, axisDimension, ownerDirection, generationCount) && - (!layout.minContentResolvesAgainstOwnerWidth(axisDimension) || - yoga::inexactEquals( + if (!hasMemoizedMinContent( + node, axisDimension, ownerDirection, generationCount) || + (layout.minContentResolvesAgainstOwnerWidth(axisDimension) && + !yoga::inexactEquals( layout.minContentOwnerWidth[axisIndex], ownerWidth))) { - return MinContentSize{ - layout.minContent[axisIndex], - layout.minContentResolvesAgainstOwnerWidth(axisDimension)}; + return std::nullopt; } - return std::nullopt; + if (node->hasMeasureFunc()) { + return leafMinContentSize(node, requestedAxis, ownerDirection, ownerWidth); + } + return MinContentSize{ + layout.minContent[axisIndex], + layout.minContentResolvesAgainstOwnerWidth(axisDimension)}; } static MinContentSize computeChildMinContentContribution( @@ -991,6 +988,52 @@ static MinContentSize computeChildMinContentContribution( float ownerHeight, uint32_t generationCount); +// The content-box width of `node` under an owner whose content box is +// `ownerWidth` wide: the width it states, else the owner's less its margins, +// within the minimum and maximum it states. This is its width as a stretched +// item of a column; one that is not stretched may be narrower, which the walk +// does not model. +static float contentWidthUnderOwner( + const yoga::Node* const node, + const Direction ownerDirection, + const float ownerWidth) { + const Style& style = node->style(); + const Direction direction = node->resolveDirection(ownerDirection); + const float paddingAndBorder = style.computePaddingAndBorderForDimension( + direction, Dimension::Width, ownerWidth); + const FloatOptional stated = + style.dimension(Dimension::Width).resolve(ownerWidth); + FloatOptional borderBoxWidth{ + ownerWidth - style.computeMarginForAxis(FlexDirection::Row, ownerWidth)}; + if (stated.isDefined()) { + borderBoxWidth = style.boxSizing() == BoxSizing::ContentBox + ? stated + FloatOptional{paddingAndBorder} + : stated; + } + borderBoxWidth = boundAxisWithinMinAndMax( + node, + direction, + FlexDirection::Row, + borderBoxWidth, + ownerWidth, + ownerWidth); + if (borderBoxWidth.isUndefined()) { + // With no width to fill, the box is still no wider than its maximum. + borderBoxWidth = boundAxisWithinMinAndMax( + node, + direction, + FlexDirection::Row, + style.resolvedMaxDimension( + direction, Dimension::Width, ownerWidth, ownerWidth), + ownerWidth, + ownerWidth); + } + if (borderBoxWidth.isUndefined()) { + return YGUndefined; + } + return yoga::maxOrDefined(borderBoxWidth.unwrap() - paddingAndBorder, 0.0f); +} + // Measures or walks `node`, which the tree being laid out owns, and memoizes // the result. static MinContentSize measureOrWalkMinContentMainSize( @@ -1007,20 +1050,31 @@ static MinContentSize measureOrWalkMinContentMainSize( if (node->hasMeasureFunc()) { // 2. Dynamic min-content callback if set (for Primitives whose // min-content depends on state). Otherwise fall back to the regular - // measure function with `AtMost 0`, which text measurers naturally - // answer with longest-word width. + // measure function. A width is probed with `AtMost 0`, which text + // measurers naturally answer with longest-word width. A height is probed + // the same way unless `MinContentHeightAtGivenWidth` is on: a text + // measurer answers `AtMost 0` with no height at all, where a min-content + // height is the height the content takes at the box's width (css-sizing-3 + // §2.1), so the leaf is measured at its width with no limit on its height. + const bool heightAtGivenWidth = !wantRow && + node->getConfig()->isExperimentalFeatureEnabled( + ExperimentalFeature::MinContentHeightAtGivenWidth); + float width = wantRow ? 0.0f : YGUndefined; + if (heightAtGivenWidth) { + width = contentWidthUnderOwner(node, ownerDirection, ownerWidth); + } + const MeasureMode widthMode = + yoga::isDefined(width) ? MeasureMode::AtMost : MeasureMode::Undefined; + const float height = wantRow || heightAtGivenWidth ? YGUndefined : 0.0f; + const MeasureMode heightMode = + yoga::isDefined(height) ? MeasureMode::AtMost : MeasureMode::Undefined; const YGSize size = node->hasMinContentMeasureFunc() - ? node->measureMinContent( - wantRow ? 0.0f : YGUndefined, - wantRow ? MeasureMode::AtMost : MeasureMode::Undefined, - wantRow ? YGUndefined : 0.0f, - wantRow ? MeasureMode::Undefined : MeasureMode::AtMost) - : node->measure( - wantRow ? 0.0f : YGUndefined, - wantRow ? MeasureMode::AtMost : MeasureMode::Undefined, - wantRow ? YGUndefined : 0.0f, - wantRow ? MeasureMode::Undefined : MeasureMode::AtMost); + ? node->measureMinContent(width, widthMode, height, heightMode) + : node->measure(width, widthMode, height, heightMode); layout.minContent[axisIndex] = wantRow ? size.width : size.height; + layout.minContentOwnerWidth[axisIndex] = ownerWidth; + layout.setMinContentResolvesAgainstOwnerWidth( + dimension(requestedAxis), heightAtGivenWidth); layout.minContentGeneration[axisIndex] = generationCount; return leafMinContentSize(node, requestedAxis, ownerDirection, ownerWidth); } @@ -1034,6 +1088,20 @@ static MinContentSize measureOrWalkMinContentMainSize( const bool childrenAddUp = isRow(node->style().flexDirection()) == wantRow && (node->style().flexWrap() == Wrap::NoWrap || !wantRow); + // A height measured at a leaf's width needs the width of each box above the + // leaf. A column's children are walked against its content width, which a + // stretched child fills. A row's children share its width by their content, + // which the walk does not know, so they are walked against no width and + // their text is as tall as it is unwrapped, the least it can be. + float childOwnerWidth = ownerWidth; + if (!wantRow && + node->getConfig()->isExperimentalFeatureEnabled( + ExperimentalFeature::MinContentHeightAtGivenWidth)) { + childOwnerWidth = childrenAddUp + ? contentWidthUnderOwner(node, ownerDirection, ownerWidth) + : YGUndefined; + } + float minContent = 0.0f; size_t itemCount = 0; bool resolvesAgainstOwnerWidth = node->style().hasPercentPadding(); @@ -1051,11 +1119,11 @@ static MinContentSize measureOrWalkMinContentMainSize( i, requestedAxis, direction, - ownerWidth, + childOwnerWidth, ownerHeight, generationCount); - const float childSize = - child.size + childStyle.computeMarginForAxis(requestedAxis, ownerWidth); + const float childSize = child.size + + childStyle.computeMarginForAxis(requestedAxis, childOwnerWidth); minContent = childrenAddUp ? minContent + childSize : std::max(minContent, childSize); resolvesAgainstOwnerWidth = resolvesAgainstOwnerWidth || diff --git a/packages/react-native/ReactCommon/yoga/yoga/enums/ExperimentalFeature.h b/packages/react-native/ReactCommon/yoga/yoga/enums/ExperimentalFeature.h index 7e6c5eb8b6c..26328d6abb5 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/enums/ExperimentalFeature.h +++ b/packages/react-native/ReactCommon/yoga/yoga/enums/ExperimentalFeature.h @@ -18,11 +18,12 @@ namespace facebook::yoga { enum class ExperimentalFeature : uint8_t { WebFlexBasis = YGExperimentalFeatureWebFlexBasis, FixFlexBasisFitContent = YGExperimentalFeatureFixFlexBasisFitContent, + MinContentHeightAtGivenWidth = YGExperimentalFeatureMinContentHeightAtGivenWidth, }; template <> constexpr int32_t ordinalCount() { - return 2; + return 3; } constexpr ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) { From 20fa796e39584f07c458ebd0d14e4278bb443170 Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Wed, 2 Dec 2026 06:04:39 -0800 Subject: [PATCH 6/7] Add overflow: clip, which keeps the automatic minimum size (#2106) (#60476) 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/60476 * Proposal: add overflow: clip, which keeps the automatic minimum size Why === A flex item that is a scroll container has an automatic minimum size of zero; any other has a content-based one (css-flexbox-1 §4.5). `overflow: hidden` makes a scroll container; `overflow: clip` clips without making one (css-overflow-3 §3.1: "the `visible` and `clip` values are known as the non-scrollable values", and "if neither axis computes to a scrollable value, the box is not a scroll container"). Yoga has `visible`, `hidden` and `scroll`. An app that only wants an item's content clipped, as React Native apps do with `overflow: 'hidden'` for rounded corners, has to say `hidden`, which with automatic minimum sizes on also gives up the item's minimum. This is a proposal because it adds a value to a public enum. How === `YGOverflowClip` clips and keeps the minimum: the automatic minimum is zero for `hidden` and `scroll` and content-based for `visible` and `clip`. Everywhere else Yoga only asks whether a box is `scroll`, so `clip` lays out as `hidden`. Clipping is the host's job, as for `hidden`. The value is not behind an erratum or an experimental feature: no existing value changes meaning, and only a node given the new value behaves differently. A `switch` over `YGOverflow` with no `default` gains a `-Wswitch` warning. React Native's in `YogaLayoutableShadowNode.cpp`, which sets `FormsContentClip`, has to handle `YGOverflowClip` in the same sync. Mapping the `overflow: 'clip'` style value to it is a separate React Native change. Test Plan ========= `python3 enums.py` regenerates the enum files with no change, and `yarn gentest` changes only the `YGAutoMinSizeTest` files, which gain `overflow_clip_item_keeps_content_size` next to the existing `overflow_hidden_item_shrinks_past_content`. `cmake --build tests/build && tests/build/yogatests` and `yarn format-check && yarn lint` pass. The new fixture cannot be built without the enum value. With `clip` treated as `hidden`, the item is 60 wide where Chrome has 120. `yarn gentest -h` leaves the tree clean, and `node ./scripts/clang-format.js --check` passes. The generated Java tests were not run, because the Gradle project has no unit-test source set; the Kotlin library compiles with the new enum value. The generated JavaScript tests were not run either, because they need Emscripten. Changelog: [General][Added] - Add `YGOverflowClip` to Yoga: an item that clips without being a scroll container keeps its automatic minimum size * Document overflow and what each value changes in layout Why === The website has no page for `overflow`, and the property affects layout in ways a reader cannot guess from its name: `hidden` and `scroll` make a scroll container, which has an automatic minimum size of zero (css-flexbox-1 §4.5), and `clip` does not. How === The new page `website/docs/styling/overflow.mdx` covers `visible`, `hidden`, `scroll` and `clip` as Yoga reads them: which make a scroll container, what that does to an item's automatic minimum size, and how a `scroll` node's content is measured. It states the limits: Yoga clips nothing, one value covers both axes, and automatic minimum sizes apply only with `MinSizeUndefinedInsteadOfAuto` off, so with a default config `clip` lays out exactly as `visible` and `hidden` do. The playground accepts `overflow: 'clip'`. Test Plan ========= The site builds with `docusaurus build`, which fails on a broken link, against a stub of the WebAssembly module, because the real build needs Emscripten. The playgrounds were therefore not run in a browser. `yarn tsc` in `website/` passes, and `prettier --check` and `eslint` pass on the changed TypeScript. The numbers on the page come from a program run against `libyogacore` built from this branch. Changelog: [Internal] * Deserialize overflow: clip in benchmark TreeDeserialization * Build the base with its own benchmark program when the PR's does not build The instruction-count job builds the base Yoga with the PR's benchmark program. When that program uses an API the PR adds, such as YGOverflowClip, the base build failed. Fall back to the base's own benchmark program, with a warning. --------- Differential Revision: D135507378 --- .../src/main/java/com/facebook/yoga/YogaOverflow.kt | 4 +++- .../react-native/ReactCommon/yoga/yoga/YGEnums.cpp | 2 ++ packages/react-native/ReactCommon/yoga/yoga/YGEnums.h | 3 ++- .../yoga/yoga/algorithm/CalculateLayout.cpp | 10 ++++++---- .../ReactCommon/yoga/yoga/enums/Overflow.h | 3 ++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaOverflow.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaOverflow.kt index 90ca7c8a255..98a4b1eb102 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaOverflow.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaOverflow.kt @@ -12,7 +12,8 @@ package com.facebook.yoga public enum class YogaOverflow(public val intValue: Int) { VISIBLE(0), HIDDEN(1), - SCROLL(2); + SCROLL(2), + CLIP(3); public fun intValue(): Int = intValue @@ -23,6 +24,7 @@ public enum class YogaOverflow(public val intValue: Int) { 0 -> VISIBLE 1 -> HIDDEN 2 -> SCROLL + 3 -> CLIP else -> throw IllegalArgumentException("Unknown enum value: $value") } } diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp index 194e99a6aa6..6d9c77fe69b 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp @@ -257,6 +257,8 @@ const char* YGOverflowToString(const YGOverflow value) { return "hidden"; case YGOverflowScroll: return "scroll"; + case YGOverflowClip: + return "clip"; } return "unknown"; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h index b10b74f98fb..a65af836fb8 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h +++ b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h @@ -137,7 +137,8 @@ YG_ENUM_DECL( YGOverflow, YGOverflowVisible, YGOverflowHidden, - YGOverflowScroll) + YGOverflowScroll, + YGOverflowClip) YG_ENUM_DECL( YGPositionType, diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index aa6131b410b..610dae1e370 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -1330,10 +1330,12 @@ static FloatOptional computeAutoMinMainSize( if (child->style().minDimension(dimension(mainAxis)).isDefined()) { return FloatOptional{}; } - // Per CSS §4.5: a flex item whose own `overflow` is not `visible` gets - // auto-min = 0 (let scroll/clip handle overflow rather than enforce a - // content-based minimum). - if (child->style().overflow() != Overflow::Visible) { + // Per CSS §4.5: a flex item that is a scroll container gets auto-min = 0 + // (let scrolling handle overflow rather than enforce a content-based + // minimum). `overflow: clip` clips without making a scroll container + // (css-overflow-3 §3.1), so it keeps its content-based minimum. + const Overflow overflow = child->style().overflow(); + if (overflow == Overflow::Hidden || overflow == Overflow::Scroll) { return FloatOptional{0.0f}; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/enums/Overflow.h b/packages/react-native/ReactCommon/yoga/yoga/enums/Overflow.h index 20901b02c05..0df9518b818 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/enums/Overflow.h +++ b/packages/react-native/ReactCommon/yoga/yoga/enums/Overflow.h @@ -19,11 +19,12 @@ enum class Overflow : uint8_t { Visible = YGOverflowVisible, Hidden = YGOverflowHidden, Scroll = YGOverflowScroll, + Clip = YGOverflowClip, }; template <> constexpr int32_t ordinalCount() { - return 3; + return 4; } constexpr Overflow scopedEnum(YGOverflow unscoped) { From 032958b371a9e0af049c0d7cc4acba0705d8f6a5 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 2 Dec 2026 06:04:43 -0800 Subject: [PATCH 7/7] Handle Yoga overflow clip in content-clipping traits Summary: Treat Yoga's `overflow: clip` as content-clipping in the view shadow node, alongside `hidden` and `scroll`. This keeps the overflow enum switch exhaustive and lets the renderer clip nodes configured with the new value. Add a native regression test for the `FormsContentClip` trait; exposing `overflow: 'clip'` to JavaScript remains separate. Changelog: [Internal] Differential Revision: D135639056 --- .../components/view/YogaLayoutableShadowNode.cpp | 1 + .../renderer/components/view/tests/LayoutTest.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp index 71019a44767..2739eefb9ba 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -453,6 +453,7 @@ void YogaLayoutableShadowNode::updateYogaProps() { break; case YGOverflowHidden: case YGOverflowScroll: + case YGOverflowClip: ShadowNode::traits_.set(ShadowNodeTraits::Trait::FormsContentClip); break; } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp index 7bcbc7588e0..2612f531260 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/tests/LayoutTest.cpp @@ -184,6 +184,20 @@ class LayoutTest : public ::testing::Test { } }; +TEST_F(LayoutTest, overflowClipFormsContentClip) { + std::shared_ptr viewShadowNode; + auto element = Element().reference(viewShadowNode).props([] { + auto props = std::make_shared(); + props->yogaStyle.setOverflow(yoga::Overflow::Clip); + return props; + }); + + builder_.build(element); + + EXPECT_TRUE(viewShadowNode->getTraits().check( + ShadowNodeTraits::Trait::FormsContentClip)); +} + // Test the layout as described above with no extra changes TEST_F(LayoutTest, overflowInsetTest) { initialize(AS_IS);