Skip to content

Commit baf378e

Browse files
Solve width bug when the size is less than min
Summary: This diff updates the logic which reassigns `remainingFreeSpace` when the node's calculated dimension falls below min width of the node. So we will have to update the `remainingFreeSpace` as there is more available space since the calculated nodes width is less than the min width. I have also added comments at relevant places in the code so that it is clearer. This diff solves the issue raised in litho support grp. The details can be found here T32199608. This diff also makes sure that it doesn't break fblite, as the earlier version broke it, details of which can be found here T32881750. Reviewed By: IanChilds Differential Revision: D9359026 fbshipit-source-id: 4168e385e962c168a9de9370220c75f14a6726a7
1 parent f1ed130 commit baf378e

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,20 +2420,32 @@ static void YGJustifyMainAxis(
24202420
const float& availableInnerWidth,
24212421
const bool& performLayout) {
24222422
const YGStyle& style = node->getStyle();
2423-
2424-
// If we are using "at most" rules in the main axis. Calculate the remaining
2425-
// space when constraint by the min size defined for the main axis.
2423+
const float leadingPaddingAndBorderMain = YGUnwrapFloatOptional(
2424+
node->getLeadingPaddingAndBorder(mainAxis, ownerWidth));
2425+
const float trailingPaddingAndBorderMain = YGUnwrapFloatOptional(
2426+
node->getTrailingPaddingAndBorder(mainAxis, ownerWidth));
2427+
// If we are using "at most" rules in the main axis, make sure that
2428+
// remainingFreeSpace is 0 when min main dimension is not given
24262429
if (measureModeMainDim == YGMeasureModeAtMost &&
24272430
collectedFlexItemsValues.remainingFreeSpace > 0) {
24282431
if (style.minDimensions[dim[mainAxis]].unit != YGUnitUndefined &&
24292432
!YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisownerSize)
24302433
.isUndefined()) {
2431-
collectedFlexItemsValues.remainingFreeSpace = YGFloatMax(
2432-
0,
2434+
// This condition makes sure that if the size of main dimension(after
2435+
// considering child nodes main dim, leading and trailing padding etc)
2436+
// falls below min dimension, then the remainingFreeSpace is reassigned
2437+
// considering the min dimension
2438+
2439+
// `minAvailableMainDim` denotes minimum available space in which child
2440+
// can be laid out, it will exclude space consumed by padding and border.
2441+
const float minAvailableMainDim =
24332442
YGUnwrapFloatOptional(YGResolveValue(
24342443
style.minDimensions[dim[mainAxis]], mainAxisownerSize)) -
2435-
(availableInnerMainDim -
2436-
collectedFlexItemsValues.remainingFreeSpace));
2444+
leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
2445+
const float occupiedSpaceByChildNodes =
2446+
availableInnerMainDim - collectedFlexItemsValues.remainingFreeSpace;
2447+
collectedFlexItemsValues.remainingFreeSpace =
2448+
YGFloatMax(0, minAvailableMainDim - occupiedSpaceByChildNodes);
24372449
} else {
24382450
collectedFlexItemsValues.remainingFreeSpace = 0;
24392451
}
@@ -2495,8 +2507,6 @@ static void YGJustifyMainAxis(
24952507
}
24962508
}
24972509

2498-
const float leadingPaddingAndBorderMain = YGUnwrapFloatOptional(
2499-
node->getLeadingPaddingAndBorder(mainAxis, ownerWidth));
25002510
collectedFlexItemsValues.mainDim =
25012511
leadingPaddingAndBorderMain + leadingMainDim;
25022512
collectedFlexItemsValues.crossDim = 0;
@@ -2579,8 +2589,7 @@ static void YGJustifyMainAxis(
25792589
}
25802590
}
25812591
}
2582-
collectedFlexItemsValues.mainDim += YGUnwrapFloatOptional(
2583-
node->getTrailingPaddingAndBorder(mainAxis, ownerWidth));
2592+
collectedFlexItemsValues.mainDim += trailingPaddingAndBorderMain;
25842593
}
25852594

25862595
//

0 commit comments

Comments
 (0)