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
This commit is contained in:
Lukas Wöhrl 2017-04-26 11:31:06 -07:00 committed by Facebook Github Bot
parent c7e0f56d75
commit c660d0c836
1 changed files with 12 additions and 6 deletions

View File

@ -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)) {