Skip to content

Commit d66ab59

Browse files
nicoburnsfacebook-github-bot
authored andcommitted
Support "align-content: space-evenly" (#41019)
Summary: Pull Request resolved: #41019 ### 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 fbshipit-source-id: ef9f6f14220a0db066bc30db8dd690a4a82a0b00
1 parent 2bf1a8f commit d66ab59

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
@@ -746,41 +746,11 @@ inline std::string toString(const yoga::FlexDirection& value) {
746746
}
747747

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

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

786756
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
@@ -2036,6 +2036,18 @@ static void calculateLayoutImpl(
20362036
currentLead += remainingAlignContentDim / 2;
20372037
}
20382038
break;
2039+
case Align::SpaceEvenly:
2040+
if (availableInnerCrossDim > totalLineCrossDim) {
2041+
currentLead +=
2042+
remainingAlignContentDim / static_cast<float>(lineCount + 1);
2043+
if (lineCount > 1) {
2044+
crossDimLead =
2045+
remainingAlignContentDim / static_cast<float>(lineCount + 1);
2046+
}
2047+
} else {
2048+
currentLead += remainingAlignContentDim / 2;
2049+
}
2050+
break;
20392051
case Align::SpaceBetween:
20402052
if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) {
20412053
crossDimLead =
@@ -2192,6 +2204,7 @@ static void calculateLayoutImpl(
21922204
case Align::Auto:
21932205
case Align::SpaceBetween:
21942206
case Align::SpaceAround:
2207+
case Align::SpaceEvenly:
21952208
break;
21962209
}
21972210
}

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)