From 751addcb734905235bb23e7c8b160f4602be07bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Thu, 9 Mar 2017 03:48:33 -0800 Subject: [PATCH] Take margin into account on max dimension Summary: We need to take the margin into account if we clip on max dimension. Fixes #466. Closes https://github.com/facebook/yoga/pull/467 Differential Revision: D4681342 Pulled By: emilsjolander fbshipit-source-id: 56311df9864a284d553c31f1c6db382f337f1fad --- ReactCommon/yoga/yoga/Yoga.c | 55 +++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 6d7595b63..764f8bf34 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -1334,7 +1334,14 @@ static float YGNodeRelativePosition(const YGNodeRef node, : -YGNodeTrailingPosition(node, axis, axisSize); } -static void YGConstrainMaxSizeForMode(const float maxSize, YGMeasureMode *mode, float *size) { +static void YGConstrainMaxSizeForMode(const YGNodeRef node, + const enum YGFlexDirection axis, + const float parentAxisSize, + const float parentWidth, + YGMeasureMode *mode, + float *size) { + const float maxSize = YGValueResolve(&node->style.maxDimensions[dim[axis]], parentAxisSize) + + YGNodeMarginForAxis(node, axis, parentWidth); switch (*mode) { case YGMeasureModeExactly: case YGMeasureModeAtMost: @@ -1480,14 +1487,10 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node, } } - YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[YGDimensionWidth], - parentWidth), - &childWidthMeasureMode, - &childWidth); - YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[YGDimensionHeight], - parentHeight), - &childHeightMeasureMode, - &childHeight); + YGConstrainMaxSizeForMode( + child, YGFlexDirectionRow, parentWidth, parentWidth, &childWidthMeasureMode, &childWidth); + YGConstrainMaxSizeForMode( + child, YGFlexDirectionColumn, parentHeight, parentWidth, &childHeightMeasureMode, &childHeight); // Measure the child YGLayoutNodeInternal(child, @@ -2443,16 +2446,18 @@ static void YGNodelayoutImpl(const YGNodeRef node, childCrossSize += marginCross; } - YGConstrainMaxSizeForMode( - YGValueResolve(¤tRelativeChild->style.maxDimensions[dim[mainAxis]], - availableInnerWidth), - &childMainMeasureMode, - &childMainSize); - YGConstrainMaxSizeForMode( - YGValueResolve(¤tRelativeChild->style.maxDimensions[dim[crossAxis]], - availableInnerHeight), - &childCrossMeasureMode, - &childCrossSize); + YGConstrainMaxSizeForMode(currentRelativeChild, + mainAxis, + availableInnerMainDim, + availableInnerWidth, + &childMainMeasureMode, + &childMainSize); + YGConstrainMaxSizeForMode(currentRelativeChild, + crossAxis, + availableInnerCrossDim, + availableInnerWidth, + &childCrossMeasureMode, + &childCrossSize); const bool requiresStretchLayout = !YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) && @@ -2690,12 +2695,16 @@ static void YGNodelayoutImpl(const YGNodeRef node, YGMeasureMode childMainMeasureMode = YGMeasureModeExactly; YGMeasureMode childCrossMeasureMode = YGMeasureModeExactly; - YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[dim[mainAxis]], - availableInnerMainDim), + YGConstrainMaxSizeForMode(child, + mainAxis, + availableInnerMainDim, + availableInnerWidth, &childMainMeasureMode, &childMainSize); - YGConstrainMaxSizeForMode(YGValueResolve(&child->style.maxDimensions[dim[crossAxis]], - availableInnerCrossDim), + YGConstrainMaxSizeForMode(child, + crossAxis, + availableInnerCrossDim, + availableInnerWidth, &childCrossMeasureMode, &childCrossSize);