Skip to content

Commit d867ec0

Browse files
fix: remove gap if its last element in line (fix flex gap extra spacing 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
1 parent 621969b commit d867ec0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,11 @@ static void YGJustifyMainAxis(
25402540
const YGNodeRef child = node->getChild(i);
25412541
const YGStyle& childStyle = child->getStyle();
25422542
const YGLayout childLayout = child->getLayout();
2543+
const bool isLastChild = i == collectedFlexItemsValues.endOfLineIndex - 1;
2544+
// remove the gap if it is the last element of the line
2545+
if (isLastChild) {
2546+
betweenMainDim -= gap;
2547+
}
25432548
if (childStyle.display() == YGDisplayNone) {
25442549
continue;
25452550
}

0 commit comments

Comments
 (0)