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
This commit is contained in:
Lukas Wöhrl 2017-01-26 13:36:35 -08:00 committed by Facebook Github Bot
parent 8b4272b2fd
commit 48e346193a
1 changed files with 18 additions and 2 deletions

View File

@ -1471,6 +1471,14 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->layout.measuredDimensions[dim[mainAxis]] - child->layout.measuredDimensions[dim[mainAxis]] -
YGNodeTrailingBorder(node, mainAxis) - YGNodeTrailingBorder(node, mainAxis) -
YGNodeTrailingPosition(child, mainAxis, width); 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) && if (YGNodeIsTrailingPosDefined(child, crossAxis) &&
@ -1479,6 +1487,14 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->layout.measuredDimensions[dim[crossAxis]] - child->layout.measuredDimensions[dim[crossAxis]] -
YGNodeTrailingBorder(node, crossAxis) - YGNodeTrailingBorder(node, crossAxis) -
YGNodeTrailingPosition(child, crossAxis, width); 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, YGMeasureMode lastSizeMode,
float lastComputedSize) { float lastComputedSize) {
return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined && return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined &&
size >= lastComputedSize; (size >= lastComputedSize || YGFloatsEqual(size, lastComputedSize));
} }
static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode, static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode,
@ -2794,7 +2810,7 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(YGMeasureM
float lastSize, float lastSize,
float lastComputedSize) { float lastComputedSize) {
return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost && return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost &&
lastSize > size && lastComputedSize <= size; lastSize > size && (lastComputedSize <= size || YGFloatsEqual(size, lastComputedSize));
} }
bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode, bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,