Skip to content

Commit bf233ac

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
CSS Grid 1/9: Grid style types and public API (#1879)
Summary: X-link: react/react-native#55665 Add the foundational data types, enums, style properties, and C API for expressing CSS Grid layouts in Yoga. Includes: - Grid style types (GridLine.h, GridTrack.h, GridTrackType.h) - Updated enums (Display::Grid, Align::Start/End, Justify::Auto/Stretch/Start/End) - Grid event (LayoutPassReason::kGridLayout) - Style property accessors and member variables - Public C API (YGGridTrackList.h/cpp, YGNodeStyle grid setters/getters) - Layout helpers updated for new enum values (Align.h, AbsoluteLayout.cpp, CalculateLayout.cpp/h partial) - Node.h: relativePosition made public - Website playground grid property support - React Native mirror of all C++ changes Differential Revision: D93946262
1 parent 9dff914 commit bf233ac

28 files changed

Lines changed: 960 additions & 48 deletions

enums.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
],
2020
"FlexDirection": ["Column", "ColumnReverse", "Row", "RowReverse"],
2121
"Justify": [
22+
"Auto",
2223
"FlexStart",
2324
"Center",
2425
"FlexEnd",
2526
"SpaceBetween",
2627
"SpaceAround",
2728
"SpaceEvenly",
29+
"Stretch",
30+
"Start",
31+
"End",
2832
],
2933
"Overflow": ["Visible", "Hidden", "Scroll"],
3034
"Align": [
@@ -37,9 +41,11 @@
3741
"SpaceBetween",
3842
"SpaceAround",
3943
"SpaceEvenly",
44+
"Start",
45+
"End",
4046
],
4147
"PositionType": ["Static", "Relative", "Absolute"],
42-
"Display": ["Flex", "None", "Contents"],
48+
"Display": ["Flex", "None", "Contents", "Grid"],
4349
"Wrap": ["NoWrap", "Wrap", "WrapReverse"],
4450
"BoxSizing": ["BorderBox", "ContentBox"],
4551
"MeasureMode": ["Undefined", "Exactly", "AtMost"],
@@ -62,6 +68,7 @@
6268
"WebFlexBasis",
6369
],
6470
"Gutter": ["Column", "Row", "All"],
71+
"GridTrackType": ["Auto", "Points", "Percent", "Fr", "Minmax"],
6572
# Known incorrect behavior which can be enabled for compatibility
6673
"Errata": [
6774
# Default: Standards conformant mode

java/com/facebook/yoga/YogaAlign.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public enum YogaAlign {
1818
BASELINE(5),
1919
SPACE_BETWEEN(6),
2020
SPACE_AROUND(7),
21-
SPACE_EVENLY(8);
21+
SPACE_EVENLY(8),
22+
START(9),
23+
END(10);
2224

2325
private final int mIntValue;
2426

@@ -41,6 +43,8 @@ public static YogaAlign fromInt(int value) {
4143
case 6: return SPACE_BETWEEN;
4244
case 7: return SPACE_AROUND;
4345
case 8: return SPACE_EVENLY;
46+
case 9: return START;
47+
case 10: return END;
4448
default: throw new IllegalArgumentException("Unknown enum value: " + value);
4549
}
4650
}

java/com/facebook/yoga/YogaDisplay.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
public enum YogaDisplay {
1313
FLEX(0),
1414
NONE(1),
15-
CONTENTS(2);
15+
CONTENTS(2),
16+
GRID(3);
1617

1718
private final int mIntValue;
1819

@@ -29,6 +30,7 @@ public static YogaDisplay fromInt(int value) {
2930
case 0: return FLEX;
3031
case 1: return NONE;
3132
case 2: return CONTENTS;
33+
case 3: return GRID;
3234
default: throw new IllegalArgumentException("Unknown enum value: " + value);
3335
}
3436
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// @generated by enums.py
9+
10+
package com.facebook.yoga;
11+
12+
public enum YogaGridTrackType {
13+
AUTO(0),
14+
POINTS(1),
15+
PERCENT(2),
16+
FR(3),
17+
MINMAX(4);
18+
19+
private final int mIntValue;
20+
21+
YogaGridTrackType(int intValue) {
22+
mIntValue = intValue;
23+
}
24+
25+
public int intValue() {
26+
return mIntValue;
27+
}
28+
29+
public static YogaGridTrackType fromInt(int value) {
30+
switch (value) {
31+
case 0: return AUTO;
32+
case 1: return POINTS;
33+
case 2: return PERCENT;
34+
case 3: return FR;
35+
case 4: return MINMAX;
36+
default: throw new IllegalArgumentException("Unknown enum value: " + value);
37+
}
38+
}
39+
}

java/com/facebook/yoga/YogaJustify.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
package com.facebook.yoga;
1111

1212
public enum YogaJustify {
13-
FLEX_START(0),
14-
CENTER(1),
15-
FLEX_END(2),
16-
SPACE_BETWEEN(3),
17-
SPACE_AROUND(4),
18-
SPACE_EVENLY(5);
13+
AUTO(0),
14+
FLEX_START(1),
15+
CENTER(2),
16+
FLEX_END(3),
17+
SPACE_BETWEEN(4),
18+
SPACE_AROUND(5),
19+
SPACE_EVENLY(6),
20+
STRETCH(7),
21+
START(8),
22+
END(9);
1923

2024
private final int mIntValue;
2125

@@ -29,12 +33,16 @@ public int intValue() {
2933

3034
public static YogaJustify fromInt(int value) {
3135
switch (value) {
32-
case 0: return FLEX_START;
33-
case 1: return CENTER;
34-
case 2: return FLEX_END;
35-
case 3: return SPACE_BETWEEN;
36-
case 4: return SPACE_AROUND;
37-
case 5: return SPACE_EVENLY;
36+
case 0: return AUTO;
37+
case 1: return FLEX_START;
38+
case 2: return CENTER;
39+
case 3: return FLEX_END;
40+
case 4: return SPACE_BETWEEN;
41+
case 5: return SPACE_AROUND;
42+
case 6: return SPACE_EVENLY;
43+
case 7: return STRETCH;
44+
case 8: return START;
45+
case 9: return END;
3846
default: throw new IllegalArgumentException("Unknown enum value: " + value);
3947
}
4048
}

javascript/src/generated/YGEnums.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export enum Align {
1717
SpaceBetween = 6,
1818
SpaceAround = 7,
1919
SpaceEvenly = 8,
20+
Start = 9,
21+
End = 10,
2022
}
2123

2224
export enum BoxSizing {
@@ -39,6 +41,7 @@ export enum Display {
3941
Flex = 0,
4042
None = 1,
4143
Contents = 2,
44+
Grid = 3,
4245
}
4346

4447
export enum Edge {
@@ -73,19 +76,31 @@ export enum FlexDirection {
7376
RowReverse = 3,
7477
}
7578

79+
export enum GridTrackType {
80+
Auto = 0,
81+
Points = 1,
82+
Percent = 2,
83+
Fr = 3,
84+
Minmax = 4,
85+
}
86+
7687
export enum Gutter {
7788
Column = 0,
7889
Row = 1,
7990
All = 2,
8091
}
8192

8293
export enum Justify {
83-
FlexStart = 0,
84-
Center = 1,
85-
FlexEnd = 2,
86-
SpaceBetween = 3,
87-
SpaceAround = 4,
88-
SpaceEvenly = 5,
94+
Auto = 0,
95+
FlexStart = 1,
96+
Center = 2,
97+
FlexEnd = 3,
98+
SpaceBetween = 4,
99+
SpaceAround = 5,
100+
SpaceEvenly = 6,
101+
Stretch = 7,
102+
Start = 8,
103+
End = 9,
89104
}
90105

91106
export enum LogLevel {
@@ -146,6 +161,8 @@ const constants = {
146161
ALIGN_SPACE_BETWEEN: Align.SpaceBetween,
147162
ALIGN_SPACE_AROUND: Align.SpaceAround,
148163
ALIGN_SPACE_EVENLY: Align.SpaceEvenly,
164+
ALIGN_START: Align.Start,
165+
ALIGN_END: Align.End,
149166
BOX_SIZING_BORDER_BOX: BoxSizing.BorderBox,
150167
BOX_SIZING_CONTENT_BOX: BoxSizing.ContentBox,
151168
DIMENSION_WIDTH: Dimension.Width,
@@ -156,6 +173,7 @@ const constants = {
156173
DISPLAY_FLEX: Display.Flex,
157174
DISPLAY_NONE: Display.None,
158175
DISPLAY_CONTENTS: Display.Contents,
176+
DISPLAY_GRID: Display.Grid,
159177
EDGE_LEFT: Edge.Left,
160178
EDGE_TOP: Edge.Top,
161179
EDGE_RIGHT: Edge.Right,
@@ -176,15 +194,24 @@ const constants = {
176194
FLEX_DIRECTION_COLUMN_REVERSE: FlexDirection.ColumnReverse,
177195
FLEX_DIRECTION_ROW: FlexDirection.Row,
178196
FLEX_DIRECTION_ROW_REVERSE: FlexDirection.RowReverse,
197+
GRID_TRACK_TYPE_AUTO: GridTrackType.Auto,
198+
GRID_TRACK_TYPE_POINTS: GridTrackType.Points,
199+
GRID_TRACK_TYPE_PERCENT: GridTrackType.Percent,
200+
GRID_TRACK_TYPE_FR: GridTrackType.Fr,
201+
GRID_TRACK_TYPE_MINMAX: GridTrackType.Minmax,
179202
GUTTER_COLUMN: Gutter.Column,
180203
GUTTER_ROW: Gutter.Row,
181204
GUTTER_ALL: Gutter.All,
205+
JUSTIFY_AUTO: Justify.Auto,
182206
JUSTIFY_FLEX_START: Justify.FlexStart,
183207
JUSTIFY_CENTER: Justify.Center,
184208
JUSTIFY_FLEX_END: Justify.FlexEnd,
185209
JUSTIFY_SPACE_BETWEEN: Justify.SpaceBetween,
186210
JUSTIFY_SPACE_AROUND: Justify.SpaceAround,
187211
JUSTIFY_SPACE_EVENLY: Justify.SpaceEvenly,
212+
JUSTIFY_STRETCH: Justify.Stretch,
213+
JUSTIFY_START: Justify.Start,
214+
JUSTIFY_END: Justify.End,
188215
LOG_LEVEL_ERROR: LogLevel.Error,
189216
LOG_LEVEL_WARN: LogLevel.Warn,
190217
LOG_LEVEL_INFO: LogLevel.Info,

yoga/YGEnums.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const char* YGAlignToString(const YGAlign value) {
2929
return "space-around";
3030
case YGAlignSpaceEvenly:
3131
return "space-evenly";
32+
case YGAlignStart:
33+
return "start";
34+
case YGAlignEnd:
35+
return "end";
3236
}
3337
return "unknown";
3438
}
@@ -73,6 +77,8 @@ const char* YGDisplayToString(const YGDisplay value) {
7377
return "none";
7478
case YGDisplayContents:
7579
return "contents";
80+
case YGDisplayGrid:
81+
return "grid";
7682
}
7783
return "unknown";
7884
}
@@ -141,6 +147,22 @@ const char* YGFlexDirectionToString(const YGFlexDirection value) {
141147
return "unknown";
142148
}
143149

150+
const char* YGGridTrackTypeToString(const YGGridTrackType value) {
151+
switch (value) {
152+
case YGGridTrackTypeAuto:
153+
return "auto";
154+
case YGGridTrackTypePoints:
155+
return "points";
156+
case YGGridTrackTypePercent:
157+
return "percent";
158+
case YGGridTrackTypeFr:
159+
return "fr";
160+
case YGGridTrackTypeMinmax:
161+
return "minmax";
162+
}
163+
return "unknown";
164+
}
165+
144166
const char* YGGutterToString(const YGGutter value) {
145167
switch (value) {
146168
case YGGutterColumn:
@@ -155,6 +177,8 @@ const char* YGGutterToString(const YGGutter value) {
155177

156178
const char* YGJustifyToString(const YGJustify value) {
157179
switch (value) {
180+
case YGJustifyAuto:
181+
return "auto";
158182
case YGJustifyFlexStart:
159183
return "flex-start";
160184
case YGJustifyCenter:
@@ -167,6 +191,12 @@ const char* YGJustifyToString(const YGJustify value) {
167191
return "space-around";
168192
case YGJustifySpaceEvenly:
169193
return "space-evenly";
194+
case YGJustifyStretch:
195+
return "stretch";
196+
case YGJustifyStart:
197+
return "start";
198+
case YGJustifyEnd:
199+
return "end";
170200
}
171201
return "unknown";
172202
}

yoga/YGEnums.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ YG_ENUM_DECL(
2222
YGAlignBaseline,
2323
YGAlignSpaceBetween,
2424
YGAlignSpaceAround,
25-
YGAlignSpaceEvenly)
25+
YGAlignSpaceEvenly,
26+
YGAlignStart,
27+
YGAlignEnd)
2628

2729
YG_ENUM_DECL(
2830
YGBoxSizing,
@@ -44,7 +46,8 @@ YG_ENUM_DECL(
4446
YGDisplay,
4547
YGDisplayFlex,
4648
YGDisplayNone,
47-
YGDisplayContents)
49+
YGDisplayContents,
50+
YGDisplayGrid)
4851

4952
YG_ENUM_DECL(
5053
YGEdge,
@@ -79,6 +82,14 @@ YG_ENUM_DECL(
7982
YGFlexDirectionRow,
8083
YGFlexDirectionRowReverse)
8184

85+
YG_ENUM_DECL(
86+
YGGridTrackType,
87+
YGGridTrackTypeAuto,
88+
YGGridTrackTypePoints,
89+
YGGridTrackTypePercent,
90+
YGGridTrackTypeFr,
91+
YGGridTrackTypeMinmax)
92+
8293
YG_ENUM_DECL(
8394
YGGutter,
8495
YGGutterColumn,
@@ -87,12 +98,16 @@ YG_ENUM_DECL(
8798

8899
YG_ENUM_DECL(
89100
YGJustify,
101+
YGJustifyAuto,
90102
YGJustifyFlexStart,
91103
YGJustifyCenter,
92104
YGJustifyFlexEnd,
93105
YGJustifySpaceBetween,
94106
YGJustifySpaceAround,
95-
YGJustifySpaceEvenly)
107+
YGJustifySpaceEvenly,
108+
YGJustifyStretch,
109+
YGJustifyStart,
110+
YGJustifyEnd)
96111

97112
YG_ENUM_DECL(
98113
YGLogLevel,

0 commit comments

Comments
 (0)