Skip to content

Commit 4b1dc68

Browse files
intergalacticspacehighwayzoontek
authored andcommitted
CSS Grid 1/9: Grid style types and public API (facebook#55876)
Summary: Pull Request resolved: facebook#55876 - Add foundational data types, enums, style properties, and C API for expressing CSS Grid layouts - Includes `GridLine.h`, `GridTrack.h`, `GridTrackType.h`, `Display::Grid`, new alignment enums (`Align::Start/End`, `Justify::Auto/Stretch/Start/End`) - C API: `YGGridTrackList.h/cpp`, `YGNodeStyle` grid setters/getters - Layout helper updates, `Node.h` `relativePosition` made public Split from facebook/yoga#1865. Part of the CSS Grid implementation series. Changelog: [Internal] X-link: facebook/yoga#1893 Reviewed By: sammy-SC Differential Revision: D94867121 Pulled By: NickGerleman fbshipit-source-id: adcb6d107cdd782550a614f87f84cff3ecefd806
1 parent 0b21772 commit 4b1dc68

28 files changed

Lines changed: 902 additions & 47 deletions

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ 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;
136+
default:
137+
return RCTDisplayTypeFlex;
137138
}
138139
}

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
@@ -133,6 +133,8 @@ inline DisplayType displayTypeFromYGDisplay(YGDisplay display)
133133
return DisplayType::Contents;
134134
case YGDisplayFlex:
135135
return DisplayType::Flex;
136+
case YGDisplayGrid:
137+
return DisplayType::Grid;
136138
}
137139
}
138140

packages/react-native/ReactCommon/react/renderer/core/LayoutMetrics.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ std::vector<DebugStringConvertibleObject> getDebugProps(
4444
",bottom:" + getDebugDescription(object.overflowInset.bottom, {}) +
4545
",left:" + getDebugDescription(object.overflowInset.left, {}) + "}"},
4646
{.name = "displayType",
47-
.value = object.displayType == DisplayType::None
48-
? "None"
49-
: (object.displayType == DisplayType::Flex ? "Flex" : "Inline")},
47+
.value = object.displayType == DisplayType::None ? "None"
48+
: object.displayType == DisplayType::Flex ? "Flex"
49+
: object.displayType == DisplayType::Grid ? "Grid"
50+
: object.displayType == DisplayType::Contents ? "Contents"
51+
: "Unknown"},
5052
{.name = "layoutDirection",
5153
.value = object.layoutDirection == LayoutDirection::Undefined
5254
? "Undefined"

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
}
@@ -143,6 +149,22 @@ const char* YGFlexDirectionToString(const YGFlexDirection value) {
143149
return "unknown";
144150
}
145151

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

158180
const char* YGJustifyToString(const YGJustify value) {
159181
switch (value) {
182+
case YGJustifyAuto:
183+
return "auto";
160184
case YGJustifyFlexStart:
161185
return "flex-start";
162186
case YGJustifyCenter:
@@ -169,6 +193,12 @@ const char* YGJustifyToString(const YGJustify value) {
169193
return "space-around";
170194
case YGJustifySpaceEvenly:
171195
return "space-evenly";
196+
case YGJustifyStretch:
197+
return "stretch";
198+
case YGJustifyStart:
199+
return "start";
200+
case YGJustifyEnd:
201+
return "end";
172202
}
173203
return "unknown";
174204
}

0 commit comments

Comments
 (0)