Skip to content

Commit

Permalink
Support "align-content: space-evenly"
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#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
  • Loading branch information
nicoburns authored and facebook-github-bot committed Oct 18, 2023
1 parent 130b348 commit 30b9985
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/yoga/src/main/cpp/yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
3 changes: 2 additions & 1 deletion lib/yoga/src/main/cpp/yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ YG_ENUM_SEQ_DECL(
YGAlignStretch,
YGAlignBaseline,
YGAlignSpaceBetween,
YGAlignSpaceAround)
YGAlignSpaceAround,
YGAlignSpaceEvenly)

YG_ENUM_SEQ_DECL(
YGDimension,
Expand Down
13 changes: 13 additions & 0 deletions lib/yoga/src/main/cpp/yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,18 @@ static void calculateLayoutImpl(
currentLead += remainingAlignContentDim / 2;
}
break;
case Align::SpaceEvenly:
if (availableInnerCrossDim > totalLineCrossDim) {
currentLead +=
remainingAlignContentDim / static_cast<float>(lineCount + 1);
if (lineCount > 1) {
crossDimLead =
remainingAlignContentDim / static_cast<float>(lineCount + 1);
}
} else {
currentLead += remainingAlignContentDim / 2;
}
break;
case Align::SpaceBetween:
if (availableInnerCrossDim > totalLineCrossDim && lineCount > 1) {
crossDimLead =
Expand Down Expand Up @@ -2192,6 +2204,7 @@ static void calculateLayoutImpl(
case Align::Auto:
case Align::SpaceBetween:
case Align::SpaceAround:
case Align::SpaceEvenly:
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/yoga/src/main/cpp/yoga/enums/Align.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ enum class Align : uint8_t {
Baseline = YGAlignBaseline,
SpaceBetween = YGAlignSpaceBetween,
SpaceAround = YGAlignSpaceAround,
SpaceEvenly = YGAlignSpaceEvenly,
};

template <>
constexpr inline int32_t ordinalCount<Align>() {
return 8;
return 9;
}

template <>
constexpr inline int32_t bitCount<Align>() {
return 3;
return 4;
}

constexpr inline Align scopedEnum(YGAlign unscoped) {
Expand Down
4 changes: 3 additions & 1 deletion lib/yoga/src/main/java/com/facebook/yoga/YogaAlign.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
Expand Down

0 comments on commit 30b9985

Please sign in to comment.