Skip to content

Commit 87e7912

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Add YGGutter Enum
Summary: This adds the YGGutter enum, used to choose between row/column gap variants (row-gap, column-gap, gap). This used later in changes from facebook/yoga#1116, in the APIs which deal with setting gap on style on yoga node. Note the original PR called this `YGGap`, but this ending up leading to a couple public method signatures that could appear ambiguous: 1. `SetGap(YGGap gap, float gapLength)`: Enums like `YGAlign` are the vaues for an `align` prop. `YGGap` controls the variant of the gap (like `YGEdge` does for left/right/top/bottom variants). So the enum reads as if it is the `gapValue`, and it looks like we have two of the same parameter. 2. `SetGap(YGGap gapDirection, float gap)`: This is misleading, because the direction gaps flow is the cross-axis of flex-direction. 3. `GetGap(YGGap gap)`: `gap` is the variant, but looks like an out param. The [CSS Box Alignment](https://www.w3.org/TR/css-align-3/#column-row-gap) spec refers to these gaps as "Gutters", which removes the ambiguity. Changelog: [General][Added] - Add YGGutter Enum Reviewed By: yungsters Differential Revision: D39922412 fbshipit-source-id: 4b0baf800fecb3d03560a4267c7fb4c4330fd39e
1 parent 5f9689a commit 87e7912

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 YogaGutter {
13+
COLUMN(0),
14+
ROW(1),
15+
ALL(2);
16+
17+
private final int mIntValue;
18+
19+
YogaGutter(int intValue) {
20+
mIntValue = intValue;
21+
}
22+
23+
public int intValue() {
24+
return mIntValue;
25+
}
26+
27+
public static YogaGutter fromInt(int value) {
28+
switch (value) {
29+
case 0: return COLUMN;
30+
case 1: return ROW;
31+
case 2: return ALL;
32+
default: throw new IllegalArgumentException("Unknown enum value: " + value);
33+
}
34+
}
35+
}

ReactCommon/yoga/yoga/YGEnums.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ const char* YGFlexDirectionToString(const YGFlexDirection value) {
109109
return "unknown";
110110
}
111111

112+
const char* YGGutterToString(const YGGutter value) {
113+
switch (value) {
114+
case YGGutterColumn:
115+
return "column";
116+
case YGGutterRow:
117+
return "row";
118+
case YGGutterAll:
119+
return "all";
120+
}
121+
return "unknown";
122+
}
123+
112124
const char* YGJustifyToString(const YGJustify value) {
113125
switch (value) {
114126
case YGJustifyFlexStart:

ReactCommon/yoga/yoga/YGEnums.h

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ YG_ENUM_SEQ_DECL(
6464
YGFlexDirectionRow,
6565
YGFlexDirectionRowReverse)
6666

67+
YG_ENUM_SEQ_DECL(
68+
YGGutter,
69+
YGGutterColumn,
70+
YGGutterRow,
71+
YGGutterAll)
72+
6773
YG_ENUM_SEQ_DECL(
6874
YGJustify,
6975
YGJustifyFlexStart,

0 commit comments

Comments
 (0)