Skip to content

Commit

Permalink
Update align-content handling of overflow (facebook#43752)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#43752

Gentest tests started failing because Chrome changed behavior of overflowed align-content container. Spec says should fallback to "safe center", which is really just "start", instead of previous "center" behavior. This changes behavior accordingly.

There is one bit where I think we are doing the wrong thing wrt alignment of flex start vs start (which we don't support yet), but couldn't repro a failing chrome test.

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D55617689

fbshipit-source-id: 08f23d198c75f2c2f51ccaa8795289e6e4a92cb8
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Apr 2, 2024
1 parent 584e8b9 commit 2ba07df
Showing 1 changed file with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1745,41 +1745,50 @@ static void calculateLayoutImpl(
paddingAndBorderAxisCross;

const float remainingAlignContentDim = innerCrossDim - totalLineCrossDim;
switch (node->style().alignContent()) {

// Apply fallback alignments on overflow
// https://www.w3.org/TR/css-align-3/#distribution-values
const auto appliedAlignContent =
remainingAlignContentDim >= 0 ? node->style().alignContent() : [&]() {
switch (node->style().alignContent()) {
// Fallback to flex-start
case Align::SpaceBetween:
case Align::Stretch:
return Align::FlexStart;

// Fallback to safe center. TODO: This should be aligned to Start
// instead of FlexStart (for row-reverse containers)
case Align::SpaceAround:
case Align::SpaceEvenly:
return Align::FlexStart;
default:
return node->style().alignContent();
}
}();

switch (appliedAlignContent) {
case Align::FlexEnd:
currentLead += remainingAlignContentDim;
break;
case Align::Center:
currentLead += remainingAlignContentDim / 2;
break;
case Align::Stretch:
if (innerCrossDim > totalLineCrossDim) {
leadPerLine =
remainingAlignContentDim / static_cast<float>(lineCount);
}
leadPerLine = remainingAlignContentDim / static_cast<float>(lineCount);
break;
case Align::SpaceAround:
if (innerCrossDim > totalLineCrossDim) {
currentLead +=
remainingAlignContentDim / (2 * static_cast<float>(lineCount));
leadPerLine =
remainingAlignContentDim / static_cast<float>(lineCount);
} else {
currentLead += remainingAlignContentDim / 2;
}
currentLead +=
remainingAlignContentDim / (2 * static_cast<float>(lineCount));
leadPerLine = remainingAlignContentDim / static_cast<float>(lineCount);
break;
case Align::SpaceEvenly:
if (innerCrossDim > totalLineCrossDim) {
currentLead +=
remainingAlignContentDim / static_cast<float>(lineCount + 1);
leadPerLine =
remainingAlignContentDim / static_cast<float>(lineCount + 1);
} else {
currentLead += remainingAlignContentDim / 2;
}
currentLead +=
remainingAlignContentDim / static_cast<float>(lineCount + 1);
leadPerLine =
remainingAlignContentDim / static_cast<float>(lineCount + 1);
break;
case Align::SpaceBetween:
if (innerCrossDim > totalLineCrossDim && lineCount > 1) {
if (lineCount > 1) {
leadPerLine =
remainingAlignContentDim / static_cast<float>(lineCount - 1);
}
Expand Down

0 comments on commit 2ba07df

Please sign in to comment.