Repository navigation
Commit ed46a55
Size a wrapping row's min-content width by its widest child (#2104)
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
Differential Revision: D135341618
Signed-off-by: James Ide <ide@expo.dev>1 parent 2d0f6f0 commit ed46a55
1 file changed
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1027 | 1027 | | |
1028 | 1028 | | |
1029 | 1029 | | |
1030 | | - | |
1031 | | - | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
1032 | 1036 | | |
1033 | 1037 | | |
1034 | 1038 | | |
| |||
1052 | 1056 | | |
1053 | 1057 | | |
1054 | 1058 | | |
1055 | | - | |
| 1059 | + | |
1056 | 1060 | | |
1057 | 1061 | | |
1058 | 1062 | | |
1059 | 1063 | | |
1060 | 1064 | | |
1061 | 1065 | | |
1062 | 1066 | | |
1063 | | - | |
| 1067 | + | |
1064 | 1068 | | |
1065 | 1069 | | |
1066 | 1070 | | |
| |||
1190 | 1194 | | |
1191 | 1195 | | |
1192 | 1196 | | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
1196 | 1200 | | |
1197 | 1201 | | |
1198 | 1202 | | |
| |||
0 commit comments