Skip to content

Commit 54ec3a2

Browse files
nicoburnsfacebook-github-bot
authored andcommitted
Support "align-content: space-evenly" (#41019)
Summary: ### Changes made - Regenerated tests (as some aspect ratio tests seem to be out of date compared to the fixtures) - Added SpaceEvenly variant to the "Align" enums (via enums.py) - Implemented `align-content: space-evenly` alignment in CalculateLayout.cpp - Added generated tests `align-content: space-evenly` - Updated NumericBitfield test to account for the fact that the Align enum now requires more bits (this bit could do with being reviewed as I am not 100% certain that it's valid to just update the test like this). ### Changes not made - Any attempt to improve the spec-compliance of content alignment in general (e.g. I think facebook/yoga#1013 probably still needs to happen) X-link: facebook/yoga#1422 Reviewed By: yungsters Differential Revision: D50305438 Pulled By: NickGerleman
1 parent 81ae532 commit 54ec3a2

File tree

6 files changed

+25
-36
lines changed

6 files changed

+25
-36
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaAlign.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public enum YogaAlign {
1717
STRETCH(4),
1818
BASELINE(5),
1919
SPACE_BETWEEN(6),
20-
SPACE_AROUND(7);
20+
SPACE_AROUND(7),
21+
SPACE_EVENLY(8);
2122

2223
private final int mIntValue;
2324

@@ -39,6 +40,7 @@ public static YogaAlign fromInt(int value) {
3940
case 5: return BASELINE;
4041
case 6: return SPACE_BETWEEN;
4142
case 7: return SPACE_AROUND;
43+
case 8: return SPACE_EVENLY;
4244
default: throw new IllegalArgumentException("Unknown enum value: " + value);
4345
}
4446
}

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -747,41 +747,11 @@ inline std::string toString(const yoga::FlexDirection& value) {
747747
}
748748

749749
inline std::string toString(const yoga::Justify& value) {
750-
switch (value) {
751-
case yoga::Justify::FlexStart:
752-
return "flex-start";
753-
case yoga::Justify::Center:
754-
return "center";
755-
case yoga::Justify::FlexEnd:
756-
return "flex-end";
757-
case yoga::Justify::SpaceBetween:
758-
return "space-between";
759-
case yoga::Justify::SpaceAround:
760-
return "space-around";
761-
case yoga::Justify::SpaceEvenly:
762-
return "space-evenly";
763-
}
750+
return YGJustifyToString(yoga::unscopedEnum(value));
764751
}
765752

766753
inline std::string toString(const yoga::Align& value) {
767-
switch (value) {
768-
case yoga::Align::Auto:
769-
return "auto";
770-
case yoga::Align::FlexStart:
771-
return "flex-start";
772-
case yoga::Align::Center:
773-
return "center";
774-
case yoga::Align::FlexEnd:
775-
return "flex-end";
776-
case yoga::Align::Stretch:
777-
return "stretch";
778-
case yoga::Align::Baseline:
779-
return "baseline";
780-
case yoga::Align::SpaceBetween:
781-
return "space-between";
782-
case yoga::Align::SpaceAround:
783-
return "space-around";
784-
}
754+
return YGAlignToString(yoga::unscopedEnum(value));
785755
}
786756

787757
inline std::string toString(const yoga::PositionType& value) {

packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const char* YGAlignToString(const YGAlign value) {
2727
return "space-between";
2828
case YGAlignSpaceAround:
2929
return "space-around";
30+
case YGAlignSpaceEvenly:
31+
return "space-evenly";
3032
}
3133
return "unknown";
3234
}

packages/react-native/ReactCommon/yoga/yoga/YGEnums.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ YG_ENUM_SEQ_DECL(
2121
YGAlignStretch,
2222
YGAlignBaseline,
2323
YGAlignSpaceBetween,
24-
YGAlignSpaceAround)
24+
YGAlignSpaceAround,
25+
YGAlignSpaceEvenly)
2526

2627
YG_ENUM_SEQ_DECL(
2728
YGDimension,

packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,18 @@ static void calculateLayoutImpl(
20212021
currentLead += remainingAlignContentDim / 2;
20222022
}
20232023
break;
2024+
case Align::SpaceEvenly:
2025+
if (availableInnerCrossDim > totalLineCrossDim) {
2026+
currentLead +=
2027+
remainingAlignContentDim / static_cast<float>(lineCount + 1);
2028+
if (lineCount > 1) {
2029+
crossDimLead =
2030+
remainingAlignContentDim / static_cast<float>(lineCount + 1);
2031+
}
2032+
} else {
2033+
currentLead += remainingAlignContentDim / 2;
2034+
}
2035+
break;
20242036
case Align::SpaceBetween:
20252037
if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) {
20262038
crossDimLead =
@@ -2177,6 +2189,7 @@ static void calculateLayoutImpl(
21772189
case Align::Auto:
21782190
case Align::SpaceBetween:
21792191
case Align::SpaceAround:
2192+
case Align::SpaceEvenly:
21802193
break;
21812194
}
21822195
}

packages/react-native/ReactCommon/yoga/yoga/enums/Align.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ enum class Align : uint8_t {
2424
Baseline = YGAlignBaseline,
2525
SpaceBetween = YGAlignSpaceBetween,
2626
SpaceAround = YGAlignSpaceAround,
27+
SpaceEvenly = YGAlignSpaceEvenly,
2728
};
2829

2930
template <>
3031
constexpr inline int32_t ordinalCount<Align>() {
31-
return 8;
32+
return 9;
3233
}
3334

3435
template <>
3536
constexpr inline int32_t bitCount<Align>() {
36-
return 3;
37+
return 4;
3738
}
3839

3940
constexpr inline Align scopedEnum(YGAlign unscoped) {

0 commit comments

Comments
 (0)