Skip to content

Commit

Permalink
fix: remove gap if its last element in line (fix flex gap extra spaci…
Browse files Browse the repository at this point in the history
…ng when children determine parents main axis size) (#1188)

Summary:
Fixes - #35553

## Approach
We're using `betweenMainDim` to add [gap between](https://github.com/intergalacticspacehighway/yoga/blob/bbeede82d36cd89657faf385aaa704f45443c326/yoga/Yoga.cpp#L2495) items in main axis. This is resulting in increased [main axis](https://github.com/intergalacticspacehighway/yoga/blob/bbeede82d36cd89657faf385aaa704f45443c326/yoga/Yoga.cpp#L2598) dimension of the container as it gets added even for the last element. One solution is to keep using it and subtract the gap when last element is reached.

## Aside
Mutating this value feels weird, but I think `betweenMainDim` gets initialized for every line so should be fine? I did some manual tests to verify. I tried running tests but I'll have to downgrade the java version. Let me know if anything fails. Thanks! 🙏

X-link: facebook/yoga#1188

Reviewed By: necolas

Differential Revision: D42078162

Pulled By: NickGerleman

fbshipit-source-id: 0e535618350422e001141a8786a83fc81651afe9
  • Loading branch information
intergalacticspacehighway authored and facebook-github-bot committed Dec 16, 2022
1 parent 621969b commit d867ec0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,11 @@ static void YGJustifyMainAxis(
const YGNodeRef child = node->getChild(i);
const YGStyle& childStyle = child->getStyle();
const YGLayout childLayout = child->getLayout();
const bool isLastChild = i == collectedFlexItemsValues.endOfLineIndex - 1;
// remove the gap if it is the last element of the line
if (isLastChild) {
betweenMainDim -= gap;
}
if (childStyle.display() == YGDisplayNone) {
continue;
}
Expand Down

1 comment on commit d867ec0

@leotm
Copy link
Contributor

@leotm leotm commented on d867ec0 Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: think #1188 (top link) is for facebook/yoga#1188 mentioned below

Please sign in to comment.