From c660d0c8363165b42412fb39b4321d048dd53253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Wed, 26 Apr 2017 11:31:06 -0700 Subject: [PATCH] Fix flex-wrap with max constraint Summary: Fixes `flex-wrap` with a max constraint and `justify-content`. Fixes facebook/yoga#514. Closes https://github.com/facebook/yoga/pull/519 Differential Revision: D4953727 Pulled By: emilsjolander fbshipit-source-id: 32dec48220be1392ea8dac5f34871d407eb8d49b --- ReactCommon/yoga/yoga/Yoga.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 01ea968f9..b90fb49fc 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -2141,23 +2141,29 @@ static void YGNodelayoutImpl(const YGNodeRef node, if (child->style.positionType != YGPositionTypeAbsolute) { const float childMarginMainAxis = YGNodeMarginForAxis(child, mainAxis, availableInnerWidth); - const float outerFlexBasis = + const float flexBasisWithMaxConstraints = + fminf(YGResolveValue(&child->style.maxDimensions[dim[mainAxis]], mainAxisParentSize), + fmaxf(YGResolveValue(&child->style.minDimensions[dim[mainAxis]], + mainAxisParentSize), + child->layout.computedFlexBasis)); + const float flexBasisWithMinAndMaxConstraints = fmaxf(YGResolveValue(&child->style.minDimensions[dim[mainAxis]], mainAxisParentSize), - child->layout.computedFlexBasis) + - childMarginMainAxis; + flexBasisWithMaxConstraints); // 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 (sizeConsumedOnCurrentLineIncludingMinConstraint + outerFlexBasis > + if (sizeConsumedOnCurrentLineIncludingMinConstraint + flexBasisWithMinAndMaxConstraints + + childMarginMainAxis > availableInnerMainDim && isNodeFlexWrap && itemsOnLine > 0) { break; } - sizeConsumedOnCurrentLineIncludingMinConstraint += outerFlexBasis; - sizeConsumedOnCurrentLine += child->layout.computedFlexBasis + childMarginMainAxis; + sizeConsumedOnCurrentLineIncludingMinConstraint += + flexBasisWithMinAndMaxConstraints + childMarginMainAxis; + sizeConsumedOnCurrentLine += flexBasisWithMaxConstraints + childMarginMainAxis; itemsOnLine++; if (YGNodeIsFlex(child)) {