From 48e346193a477561b137684bd656c8247985bca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Thu, 26 Jan 2017 13:36:35 -0800 Subject: [PATCH] Fix absolute position if align-item or justify-content is center or flex-end Summary: Fix #310 (```center```) additionally fixes if ```flex-end``` is set. Closes https://github.com/facebook/yoga/pull/349 Reviewed By: dshahidehpour Differential Revision: D4458528 Pulled By: emilsjolander fbshipit-source-id: f073c80bfc3ea6675cb95b00283074d10e91a042 --- ReactCommon/yoga/yoga/Yoga.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 51a9287c5..ff944368b 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -1471,6 +1471,14 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, child->layout.measuredDimensions[dim[mainAxis]] - YGNodeTrailingBorder(node, mainAxis) - YGNodeTrailingPosition(child, mainAxis, width); + } else if (!YGNodeIsLeadingPosDefined(child, mainAxis) && + node->style.justifyContent == YGJustifyCenter) { + child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] - + child->layout.measuredDimensions[dim[mainAxis]]) / 2.0f; + } else if (!YGNodeIsLeadingPosDefined(child, mainAxis) && + node->style.justifyContent == YGJustifyFlexEnd) { + child->layout.position[leading[mainAxis]] = (node->layout.measuredDimensions[dim[mainAxis]] - + child->layout.measuredDimensions[dim[mainAxis]]); } if (YGNodeIsTrailingPosDefined(child, crossAxis) && @@ -1479,6 +1487,14 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node, child->layout.measuredDimensions[dim[crossAxis]] - YGNodeTrailingBorder(node, crossAxis) - YGNodeTrailingPosition(child, crossAxis, width); + } else if (!YGNodeIsLeadingPosDefined(child, crossAxis) && + YGNodeAlignItem(node, child) == YGAlignCenter) { + child->layout.position[leading[crossAxis]] = (node->layout.measuredDimensions[dim[crossAxis]] - + child->layout.measuredDimensions[dim[crossAxis]]) / 2.0f; + } else if (!YGNodeIsLeadingPosDefined(child, crossAxis) && + YGNodeAlignItem(node, child) == YGAlignFlexEnd) { + child->layout.position[leading[crossAxis]] = (node->layout.measuredDimensions[dim[crossAxis]] - + child->layout.measuredDimensions[dim[crossAxis]]); } } @@ -2785,7 +2801,7 @@ static inline bool YGMeasureModeOldSizeIsUnspecifiedAndStillFits(YGMeasureMode s YGMeasureMode lastSizeMode, float lastComputedSize) { return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined && - size >= lastComputedSize; + (size >= lastComputedSize || YGFloatsEqual(size, lastComputedSize)); } static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode, @@ -2794,7 +2810,7 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureM float lastSize, float lastComputedSize) { return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost && - lastSize > size && lastComputedSize <= size; + lastSize > size && (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize)); } bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,