From 5f99b1a55f4002c105a7005cabf720aad422b628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Mon, 27 Nov 2017 05:29:15 -0800 Subject: [PATCH] Measure nodes which have margin: auto and align-item: stretch Summary: If you have a measurable node and set ```marign-left: auto``` + ```align-item:stretch``` on it, it won't get measured and they get a width/height of ```-(nan)```. This change fixes that behaviour. Fixes #644. Closes https://github.com/facebook/yoga/pull/645 Differential Revision: D6413512 Pulled By: emilsjolander fbshipit-source-id: 755febeb33bb0d4520ca6b3c28d56ac333e4a14d --- ReactCommon/yoga/yoga/Yoga.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index a52749364..b910123fd 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -2327,7 +2327,9 @@ static void YGNodelayoutImpl(const YGNodeRef node, availableInnerCrossDim) && measureModeCrossDim == YGMeasureModeExactly && !(isNodeFlexWrap && flexBasisOverflows) && - YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) { + YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && + YGMarginLeadingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto && + YGMarginTrailingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto) { childCrossSize = availableInnerCrossDim; childCrossMeasureMode = YGMeasureModeExactly; } else if (!YGNodeIsStyleDimDefined(currentRelativeChild, @@ -2363,7 +2365,9 @@ static void YGNodelayoutImpl(const YGNodeRef node, const bool requiresStretchLayout = !YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) && - YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch; + YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch && + YGMarginLeadingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto && + YGMarginTrailingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto; const float childWidth = isMainAxisRow ? childMainSize : childCrossSize; const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;