From 6b94c7fec7bc46f72bc0b41b2447ae71701b73e0 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Tue, 17 Oct 2023 10:45:39 -0700 Subject: [PATCH] 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 https://github.com/facebook/yoga/pull/1013 probably still needs to happen) X-link: https://github.com/facebook/yoga/pull/1422 Reviewed By: yungsters Differential Revision: D50305438 Pulled By: NickGerleman --- .../java/com/facebook/yoga/YogaAlign.java | 4 ++- .../renderer/components/view/conversions.h | 34 ++----------------- .../ReactCommon/yoga/yoga/YGEnums.cpp | 2 ++ .../ReactCommon/yoga/yoga/YGEnums.h | 3 +- .../yoga/yoga/algorithm/CalculateLayout.cpp | 13 +++++++ .../ReactCommon/yoga/yoga/enums/Align.h | 5 +-- 6 files changed, 25 insertions(+), 36 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaAlign.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaAlign.java index a60d77e0f294b3..00535154fca164 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaAlign.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaAlign.java @@ -17,7 +17,8 @@ public enum YogaAlign { STRETCH(4), BASELINE(5), SPACE_BETWEEN(6), - SPACE_AROUND(7); + SPACE_AROUND(7), + SPACE_EVENLY(8); private final int mIntValue; @@ -39,6 +40,7 @@ public static YogaAlign fromInt(int value) { case 5: return BASELINE; case 6: return SPACE_BETWEEN; case 7: return SPACE_AROUND; + case 8: return SPACE_EVENLY; default: throw new IllegalArgumentException("Unknown enum value: " + value); } } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h index e38ab6b7b51805..d33d6daa01442c 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/conversions.h @@ -747,41 +747,11 @@ inline std::string toString(const yoga::FlexDirection& value) { } inline std::string toString(const yoga::Justify& value) { - switch (value) { - case yoga::Justify::FlexStart: - return "flex-start"; - case yoga::Justify::Center: - return "center"; - case yoga::Justify::FlexEnd: - return "flex-end"; - case yoga::Justify::SpaceBetween: - return "space-between"; - case yoga::Justify::SpaceAround: - return "space-around"; - case yoga::Justify::SpaceEvenly: - return "space-evenly"; - } + return YGJustifyToString(yoga::unscopedEnum(value)); } inline std::string toString(const yoga::Align& value) { - switch (value) { - case yoga::Align::Auto: - return "auto"; - case yoga::Align::FlexStart: - return "flex-start"; - case yoga::Align::Center: - return "center"; - case yoga::Align::FlexEnd: - return "flex-end"; - case yoga::Align::Stretch: - return "stretch"; - case yoga::Align::Baseline: - return "baseline"; - case yoga::Align::SpaceBetween: - return "space-between"; - case yoga::Align::SpaceAround: - return "space-around"; - } + return YGAlignToString(yoga::unscopedEnum(value)); } inline std::string toString(const yoga::PositionType& value) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp index b5916ca1ecf362..77e5c802376b8a 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp @@ -27,6 +27,8 @@ const char* YGAlignToString(const YGAlign value) { return "space-between"; case YGAlignSpaceAround: return "space-around"; + case YGAlignSpaceEvenly: + return "space-evenly"; } return "unknown"; } diff --git a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h index 55bbe9fc9d8d9a..ef09668c811e99 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h +++ b/packages/react-native/ReactCommon/yoga/yoga/YGEnums.h @@ -21,7 +21,8 @@ YG_ENUM_SEQ_DECL( YGAlignStretch, YGAlignBaseline, YGAlignSpaceBetween, - YGAlignSpaceAround) + YGAlignSpaceAround, + YGAlignSpaceEvenly) YG_ENUM_SEQ_DECL( YGDimension, diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index dc9f785eacf701..177f0b8181ee9b 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -2021,6 +2021,18 @@ static void calculateLayoutImpl( currentLead += remainingAlignContentDim / 2; } break; + case Align::SpaceEvenly: + if (availableInnerCrossDim > totalLineCrossDim) { + currentLead += + remainingAlignContentDim / static_cast(lineCount + 1); + if (lineCount > 1) { + crossDimLead = + remainingAlignContentDim / static_cast(lineCount + 1); + } + } else { + currentLead += remainingAlignContentDim / 2; + } + break; case Align::SpaceBetween: if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) { crossDimLead = @@ -2177,6 +2189,7 @@ static void calculateLayoutImpl( case Align::Auto: case Align::SpaceBetween: case Align::SpaceAround: + case Align::SpaceEvenly: break; } } diff --git a/packages/react-native/ReactCommon/yoga/yoga/enums/Align.h b/packages/react-native/ReactCommon/yoga/yoga/enums/Align.h index 95df12a79033c4..67777fc31b4545 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/enums/Align.h +++ b/packages/react-native/ReactCommon/yoga/yoga/enums/Align.h @@ -24,16 +24,17 @@ enum class Align : uint8_t { Baseline = YGAlignBaseline, SpaceBetween = YGAlignSpaceBetween, SpaceAround = YGAlignSpaceAround, + SpaceEvenly = YGAlignSpaceEvenly, }; template <> constexpr inline int32_t ordinalCount() { - return 8; + return 9; } template <> constexpr inline int32_t bitCount() { - return 3; + return 4; } constexpr inline Align scopedEnum(YGAlign unscoped) {