Repository navigation
Conversation
…2101) 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 <div style="display: flex; width: 200px"> <div style="display: flex; flex-shrink: 1"> <!-- Chrome: 100px. Yoga: 20px --> <div style="width: 100px; height: 10px; flex-shrink: 0"></div> </div> <div style="width: 180px; flex-shrink: 0"></div> </div> ``` 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 <noreply@anthropic.com> --------- 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
…t#2102) 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
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
<div style="display: flex; width: 200px">
<div style="display: flex; flex-shrink: 1; gap: 20px"> <!-- Chrome: 130px. Yoga: 90px -->
<div style="width: 30px; flex-shrink: 0"></div>
<div style="width: 30px; flex-shrink: 0"></div>
<div style="width: 30px; flex-shrink: 0"></div>
</div>
<div style="width: 180px; flex-shrink: 0"></div>
</div>
```
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
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
<div style="display: flex; width: 200px">
<div style="display: flex; flex-wrap: wrap; flex-shrink: 1; gap: 20px">
<!-- Chrome: 70px wide, two lines. Yoga: 140px wide, one line -->
<div style="width: 50px; height: 10px"></div>
<div style="width: 60px; height: 10px; margin: 0 5px"></div>
</div>
<div style="width: 180px; flex-shrink: 0"></div>
</div>
```
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
) 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 <div style="display: flex; flex-direction: column; width: 50px; height: 20px"> <div style="flex-shrink: 1">aaaa aaaa aaaa</div> <!-- three lines. Chrome: 30px. Yoga: 10px --> <div style="height: 10px; flex-shrink: 0"></div> </div> ``` 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
… (react#60476) Summary: Pull Request resolved: react#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
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
|
@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135639056. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Treat Yoga's
overflow: clipas content-clipping in the view shadow node, alongsidehiddenandscroll. This keeps the overflow enum switch exhaustive and lets the renderer clip nodes configured with the new value. Add a native regression test for theFormsContentCliptrait; exposingoverflow: 'clip'to JavaScript remains separate.Changelog: [Internal]
Differential Revision: D135639056