From 5be1726d286162678bd8ecac43dfd1411c6b7f0b Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Mon, 20 Aug 2018 06:14:50 -0700 Subject: [PATCH] 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 --- ReactCommon/yoga/yoga/Yoga.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index f35b70b57c..621564f4a3 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -2420,20 +2420,32 @@ static void YGJustifyMainAxis( const float& availableInnerWidth, const bool& performLayout) { const YGStyle& style = node->getStyle(); - - // If we are using "at most" rules in the main axis. Calculate the remaining - // space when constraint by the min size defined for the main axis. + const float leadingPaddingAndBorderMain = YGUnwrapFloatOptional( + node->getLeadingPaddingAndBorder(mainAxis, ownerWidth)); + const float trailingPaddingAndBorderMain = YGUnwrapFloatOptional( + node->getTrailingPaddingAndBorder(mainAxis, ownerWidth)); + // If we are using "at most" rules in the main axis, make sure that + // remainingFreeSpace is 0 when min main dimension is not given if (measureModeMainDim == YGMeasureModeAtMost && collectedFlexItemsValues.remainingFreeSpace > 0) { if (style.minDimensions[dim[mainAxis]].unit != YGUnitUndefined && !YGResolveValue(style.minDimensions[dim[mainAxis]], mainAxisownerSize) .isUndefined()) { - collectedFlexItemsValues.remainingFreeSpace = YGFloatMax( - 0, + // This condition makes sure that if the size of main dimension(after + // considering child nodes main dim, leading and trailing padding etc) + // falls below min dimension, then the remainingFreeSpace is reassigned + // considering the min dimension + + // `minAvailableMainDim` denotes minimum available space in which child + // can be laid out, it will exclude space consumed by padding and border. + const float minAvailableMainDim = YGUnwrapFloatOptional(YGResolveValue( style.minDimensions[dim[mainAxis]], mainAxisownerSize)) - - (availableInnerMainDim - - collectedFlexItemsValues.remainingFreeSpace)); + leadingPaddingAndBorderMain - trailingPaddingAndBorderMain; + const float occupiedSpaceByChildNodes = + availableInnerMainDim - collectedFlexItemsValues.remainingFreeSpace; + collectedFlexItemsValues.remainingFreeSpace = + YGFloatMax(0, minAvailableMainDim - occupiedSpaceByChildNodes); } else { collectedFlexItemsValues.remainingFreeSpace = 0; } @@ -2495,8 +2507,6 @@ static void YGJustifyMainAxis( } } - const float leadingPaddingAndBorderMain = YGUnwrapFloatOptional( - node->getLeadingPaddingAndBorder(mainAxis, ownerWidth)); collectedFlexItemsValues.mainDim = leadingPaddingAndBorderMain + leadingMainDim; collectedFlexItemsValues.crossDim = 0; @@ -2579,8 +2589,7 @@ static void YGJustifyMainAxis( } } } - collectedFlexItemsValues.mainDim += YGUnwrapFloatOptional( - node->getTrailingPaddingAndBorder(mainAxis, ownerWidth)); + collectedFlexItemsValues.mainDim += trailingPaddingAndBorderMain; } //