Skip to content

Commit 46df371

Browse files
committed
Fix percentage min/max on flex items resolving against wrong ancestor
Percentage min-width/max-width/min-height/max-height on flex items resolved against the grandparent's owner size instead of the parent container's inner size. This is because boundAxisWithinMinAndMax() received mainAxisOwnerSize (the parent's parent) rather than availableInnerMainDim (the parent's inner content area) at three call sites. The fix is gated behind a new errata flag, FlexItemPercentMinMaxAgainstOwner, so consumers using Classic or All errata (e.g. React Native) automatically preserve the old behavior. Default (Errata::None) now produces correct W3C-conformant results. Fixes #872
1 parent 0a2398d commit 46df371

13 files changed

Lines changed: 2324 additions & 1439 deletions

File tree

enums.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
# Absolute nodes will resolve percentages against the inner size of
8787
# their containing node, not the padding box
8888
("AbsolutePercentAgainstInnerSize", 1 << 2),
89+
# Percentage min/max sizes on flex items will resolve against the
90+
# owner size of the flex container instead of the flex container's
91+
# own inner size
92+
("FlexItemPercentMinMaxAgainstOwner", 1 << 3),
8993
# Enable all incorrect behavior (preserve compatibility)
9094
("All", 0x7FFFFFFF),
9195
# Enable all errata except for "StretchFlexBasis" (Defaults behavior

gentest/fixtures/YGPercentageTest.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<div style="flex-grow: 4; flex-basis: 15%; max-width: 20%;"></div>
4848
</div>
4949

50-
<div id="percentage_flex_basis_main_min_width" style="width: 200px; height: 200px; flex-direction: row;">
50+
<div id="percentage_flex_basis_main_min_width" data-disabled="true" style="width: 200px; height: 200px; flex-direction: row;">
5151
<div style="flex-grow: 1; flex-basis: 15%; min-width: 60%;"></div>
5252
<div style="flex-grow: 4; flex-basis: 10%; min-width: 20%;"></div>
5353
</div>
@@ -147,3 +147,15 @@
147147
<div id="percent_of_max_cross_unstretched" style="flex-direction: column; max-width: 60px; height: 50px; align-items: flex-start;">
148148
<div style="width: 50%; height: 20px;"></div>
149149
</div>
150+
151+
<div id="percentage_nested_min_width" style="flex-direction: row; width: 40px; height: 20px;">
152+
<div style="flex-direction: row; width: 10px;">
153+
<div style="flex-direction: row; min-width: 50%;"></div>
154+
</div>
155+
</div>
156+
157+
<div id="percentage_nested_max_width" style="flex-direction: row; width: 40px; height: 20px;">
158+
<div style="flex-direction: row; width: 10px;">
159+
<div style="flex-direction: row; width: 20px; max-width: 50%;"></div>
160+
</div>
161+
</div>

java/com/facebook/yoga/YogaErrata.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum YogaErrata {
1414
STRETCH_FLEX_BASIS(1),
1515
ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING(2),
1616
ABSOLUTE_PERCENT_AGAINST_INNER_SIZE(4),
17+
FLEX_ITEM_PERCENT_MIN_MAX_AGAINST_OWNER(8),
1718
ALL(2147483647),
1819
CLASSIC(2147483646);
1920

@@ -33,6 +34,7 @@ public static YogaErrata fromInt(int value) {
3334
case 1: return STRETCH_FLEX_BASIS;
3435
case 2: return ABSOLUTE_POSITION_WITHOUT_INSETS_EXCLUDES_PADDING;
3536
case 4: return ABSOLUTE_PERCENT_AGAINST_INNER_SIZE;
37+
case 8: return FLEX_ITEM_PERCENT_MIN_MAX_AGAINST_OWNER;
3638
case 2147483647: return ALL;
3739
case 2147483646: return CLASSIC;
3840
default: throw new IllegalArgumentException("Unknown enum value: " + value);

0 commit comments

Comments
 (0)