Skip to content

Keep cross axis margins and relative insets of items in wrapping containers - #59396

Open
javache wants to merge 1 commit into
react:mainfrom
javache:export-D127132637
Open

javache wants to merge 1 commit into
react:mainfrom
javache:export-D127132637

Conversation

@javache

@javache javache commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Summary:
Fixes react/yoga#1856
Fixes react/yoga#1067

In wrapping containers, STEP 8 (multi line alignment) of CalculateLayout.cpp repositions items on the cross axis and drops part of each box. In react/yoga#1856 the container is a column (Yoga's default), so left is on the cross axis.

Every case now uses the leading margin, trailing margin and relativePosition. wrap-reverse mirrors positions afterwards, so it leads with the flex end margin and applies the inset after mirroring, keeping each margin on its edge and top: 10 moving the item down.

Also, a percentage inset on a flex-start item now resolves against the container's cross size, as without wrap (top: 10% in a 100x200 row: 10 to 20), and baseline rows, which run this pass even without wrap, honor bottom and ignore insets on static items.

Column container, padding 10, flex-wrap: wrap, default align-content: flex-start, item with margin 5 and left: 10 (item left; expected worked out from the spec):

align-items main this PR expected
flex-start 20 25 25
stretch 15 25 25
center 15 25 25
flex-end 15 25 25
flex-start, no inset 10 15 15

The react/yoga#1067 repro goes from top 50 to 100.

I added tests/YGFlexWrapCrossAlignmentTest.cpp: 9 hand written gtest cases like the other non generated tests, covering row and column, LTR and RTL, wrap and wrap-reverse (including one sided margins), baseline, static items and both issue repros. All 9 fail without the CalculateLayout.cpp change; with it, all 877 tests pass (868 plus 9). I can move them into gentest fixtures or add an Errata flag if you prefer.

X-link: react/yoga#2045

Differential Revision: D127132637

Pulled By: javache

…ainers

Summary:
Fixes react/yoga#1856
Fixes react/yoga#1067

In wrapping containers, STEP 8 (multi line alignment) of `CalculateLayout.cpp` repositions items on the cross axis and drops part of each box. In react/yoga#1856 the container is a column (Yoga's default), so `left` is on the cross axis.

- `flex-start` uses `computeFlexStartPosition` (the inset) where `computeFlexStartMargin` belongs. v2.0.1 used the margin, so this is a 3.0 regression from react/yoga#1561.
- `stretch`, `center` and `flex-end` never add the relative inset.
- `center` centers the border box instead of the margin box, which is react/yoga#1067.

Every case now uses the leading margin, trailing margin and `relativePosition`. `wrap-reverse` mirrors positions afterwards, so it leads with the flex end margin and applies the inset after mirroring, keeping each margin on its edge and `top: 10` moving the item down.

Also, a percentage inset on a `flex-start` item now resolves against the container's cross size, as without wrap (`top: 10%` in a 100x200 row: 10 to 20), and baseline rows, which run this pass even without wrap, honor `bottom` and ignore insets on static items.

Column container, padding 10, `flex-wrap: wrap`, default `align-content: flex-start`, item with margin 5 and `left: 10` (item left; expected worked out from the spec):

| `align-items` | main | this PR | expected |
|---|---|---|---|
| `flex-start` | 20 | 25 | 25 |
| `stretch` | 15 | 25 | 25 |
| `center` | 15 | 25 | 25 |
| `flex-end` | 15 | 25 | 25 |
| `flex-start`, no inset | 10 | 15 | 15 |

The react/yoga#1067 repro goes from top 50 to 100.

I added `tests/YGFlexWrapCrossAlignmentTest.cpp`: 9 hand written gtest cases like the other non generated tests, covering row and column, LTR and RTL, `wrap` and `wrap-reverse` (including one sided margins), baseline, static items and both issue repros. All 9 fail without the `CalculateLayout.cpp` change; with it, all 877 tests pass (868 plus 9). I can move them into gentest fixtures or add an `Errata` flag if you prefer.

X-link: react/yoga#2045

Differential Revision: D127132637

Pulled By: javache
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 23, 2026
@meta-codesync

meta-codesync Bot commented Oct 23, 2026

Copy link
Copy Markdown

@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D127132637.

@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at eb9993fb3ee3.

android: no capture

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

2 participants