Skip to content

Commit 0f63e5a

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
CSS Grid 1/9: Grid style types and public API (facebook#55665)
Summary: X-link: facebook/yoga#1879 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 352d73b commit 0f63e5a

30 files changed

Lines changed: 930 additions & 46 deletions

packages/react-native/React/Views/RCTLayout.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ UIUserInterfaceLayoutDirection RCTUIKitLayoutDirectionFromYogaLayoutDirection(YG
114114
YGDisplay RCTYogaDisplayTypeFromReactDisplayType(RCTDisplayType displayType)
115115
{
116116
switch (displayType) {
117-
case RCTDisplayTypeNone:
118-
return YGDisplayNone;
119117
case RCTDisplayTypeFlex:
120118
return YGDisplayFlex;
119+
case RCTDisplayTypeNone:
120+
return YGDisplayNone;
121121
case RCTDisplayTypeInline:
122122
RCTAssert(NO, @"RCTDisplayTypeInline cannot be converted to YGDisplay value.");
123123
return YGDisplayNone;
@@ -128,11 +128,10 @@ RCTDisplayType RCTReactDisplayTypeFromYogaDisplayType(YGDisplay displayType)
128128
{
129129
switch (displayType) {
130130
case YGDisplayFlex:
131+
case YGDisplayContents:
132+
case YGDisplayGrid:
131133
return RCTDisplayTypeFlex;
132134
case YGDisplayNone:
133135
return RCTDisplayTypeNone;
134-
case YGDisplayContents:
135-
RCTAssert(NO, @"YGDisplayContents cannot be converted to RCTDisplayType value.");
136-
return RCTDisplayTypeNone;
137136
}
138137
}

packages/react-native/ReactAndroid/src/main/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
}

packages/react-native/ReactAndroid/src/main/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+
}

packages/react-native/ReactAndroid/src/main/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
}

packages/react-native/ReactCommon/react/renderer/components/view/conversions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ inline DisplayType displayTypeFromYGDisplay(YGDisplay display)
129129
return DisplayType::Contents;
130130
case YGDisplayFlex:
131131
return DisplayType::Flex;
132+
case YGDisplayGrid:
133+
return DisplayType::Grid;
132134
}
133135
}
134136

packages/react-native/ReactCommon/react/renderer/core/LayoutPrimitives.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum class DisplayType {
2020
None = 0,
2121
Flex = 1,
2222
Contents = 2,
23+
Grid = 3,
2324
};
2425

2526
enum class PositionType {

packages/react-native/ReactCommon/react/renderer/core/conversions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ inline int toInt(const DisplayType &displayType)
4444
return 1;
4545
case DisplayType::Contents:
4646
return 2;
47+
case DisplayType::Grid:
48+
return 3;
4749
}
4850
}
4951

@@ -56,6 +58,8 @@ inline std::string toString(const DisplayType &displayType)
5658
return "flex";
5759
case DisplayType::Contents:
5860
return "contents";
61+
case DisplayType::Grid:
62+
return "grid";
5963
}
6064
}
6165

packages/react-native/ReactCommon/yoga/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
}

packages/react-native/ReactCommon/yoga/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)