From f26a99764a1cbac557a2c844c2f2b8daf30941a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Tue, 11 Apr 2017 13:00:03 -0700 Subject: [PATCH] Fix min constraint incorrectly reducing available space Summary: If a min constraint exists. It incorrectly reduces the available space by that amount. This adds a test and fix for this. Closes https://github.com/facebook/yoga/pull/501 Differential Revision: D4867146 Pulled By: emilsjolander fbshipit-source-id: ceafe070bfe7f501929d316656ac44c4e1753059 --- ReactCommon/yoga/yoga/Yoga.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 10bd80e4447..f7be592aacd 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -2122,6 +2122,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, // either set the dimensions of the node if none already exist or to compute // the remaining space left for the flexible children. float sizeConsumedOnCurrentLine = 0; + float sizeConsumedOnCurrentLineIncludingMinConstraint = 0; float totalFlexGrowFactors = 0; float totalFlexShrinkScaledFactors = 0; @@ -2139,21 +2140,24 @@ static void YGNodelayoutImpl(const YGNodeRef node, child->lineIndex = lineCount; if (child->style.positionType != YGPositionTypeAbsolute) { + const float childMarginMainAxis = YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); const float outerFlexBasis = fmaxf(YGResolveValue(&child->style.minDimensions[dim[mainAxis]], mainAxisParentSize), child->layout.computedFlexBasis) + - YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); + childMarginMainAxis; // If this is a multi-line flow and this item pushes us over the // available size, we've // hit the end of the current line. Break out of the loop and lay out // the current line. - if (sizeConsumedOnCurrentLine + outerFlexBasis > availableInnerMainDim && isNodeFlexWrap && - itemsOnLine > 0) { + if (sizeConsumedOnCurrentLineIncludingMinConstraint + outerFlexBasis > + availableInnerMainDim && + isNodeFlexWrap && itemsOnLine > 0) { break; } - sizeConsumedOnCurrentLine += outerFlexBasis; + sizeConsumedOnCurrentLineIncludingMinConstraint += outerFlexBasis; + sizeConsumedOnCurrentLine += child->layout.computedFlexBasis + childMarginMainAxis; itemsOnLine++; if (YGNodeIsFlex(child)) {