Take parent size into account when determining if style dim is defined

Reviewed By: gkassabli

Differential Revision: D4494258

fbshipit-source-id: 36c31444cbd113a820b067fe9e7b9560ae1d4df7
This commit is contained in:
Emil Sjolander 2017-02-03 05:37:44 -08:00 committed by Facebook Github Bot
parent 95420152a6
commit eb54290a3a

View File

@ -1071,9 +1071,14 @@ static inline float YGNodeDimWithMargin(const YGNodeRef node,
YGNodeTrailingMargin(node, axis, widthSize); YGNodeTrailingMargin(node, axis, widthSize);
} }
static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node, const YGFlexDirection axis) { static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node,
return node->style.dimensions[dim[axis]].unit != YGUnitUndefined && const YGFlexDirection axis,
node->style.dimensions[dim[axis]].value >= 0.0f; const float parentSize) {
return !(
node->style.dimensions[dim[axis]].unit == YGUnitUndefined ||
(node->style.dimensions[dim[axis]].unit == YGUnitPixel &&
node->style.dimensions[dim[axis]].value < 0.0f) ||
(node->style.dimensions[dim[axis]].unit == YGUnitPercent && YGFloatIsUndefined(parentSize)));
} }
static inline bool YGNodeIsLayoutDimDefined(const YGNodeRef node, const YGFlexDirection axis) { static inline bool YGNodeIsLayoutDimDefined(const YGNodeRef node, const YGFlexDirection axis) {
@ -1244,17 +1249,18 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
YGMeasureMode childWidthMeasureMode; YGMeasureMode childWidthMeasureMode;
YGMeasureMode childHeightMeasureMode; YGMeasureMode childHeightMeasureMode;
const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow); const float resolvedFlexBasis =
const bool isColumnStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn); YGValueResolve(YGNodeStyleGetFlexBasisPtr(child), mainAxisParentSize);
const bool isRowStyleDimDefined = YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, parentWidth);
const bool isColumnStyleDimDefined =
YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, parentHeight);
if (YGNodeStyleGetFlexBasisPtr(child)->unit != YGUnitUndefined && if (!YGFloatIsUndefined(resolvedFlexBasis) && !YGFloatIsUndefined(mainAxisSize)) {
!YGFloatIsUndefined(mainAxisSize)) {
if (YGFloatIsUndefined(child->layout.computedFlexBasis) || if (YGFloatIsUndefined(child->layout.computedFlexBasis) ||
(YGIsExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis) && (YGIsExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis) &&
child->layout.computedFlexBasisGeneration != gCurrentGenerationCount)) { child->layout.computedFlexBasisGeneration != gCurrentGenerationCount)) {
child->layout.computedFlexBasis = child->layout.computedFlexBasis =
fmaxf(YGValueResolve(YGNodeStyleGetFlexBasisPtr(child), mainAxisParentSize), fmaxf(resolvedFlexBasis, YGNodePaddingAndBorderForAxis(child, mainAxis, parentWidth));
YGNodePaddingAndBorderForAxis(child, mainAxis, parentWidth));
} }
} else if (isMainAxisRow && isRowStyleDimDefined) { } else if (isMainAxisRow && isRowStyleDimDefined) {
// The width is definite, so use that as the flex basis. // The width is definite, so use that as the flex basis.
@ -1382,7 +1388,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
const float marginRow = YGNodeMarginForAxis(child, YGFlexDirectionRow, width); const float marginRow = YGNodeMarginForAxis(child, YGFlexDirectionRow, width);
const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, width); const float marginColumn = YGNodeMarginForAxis(child, YGFlexDirectionColumn, width);
if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow)) { if (YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, width)) {
childWidth = YGValueResolve(&child->style.dimensions[YGDimensionWidth], width) + marginRow; childWidth = YGValueResolve(&child->style.dimensions[YGDimensionWidth], width) + marginRow;
} else { } else {
// If the child doesn't have a specified width, compute the width based // If the child doesn't have a specified width, compute the width based
@ -1399,7 +1405,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
} }
} }
if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn)) { if (YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, height)) {
childHeight = childHeight =
YGValueResolve(&child->style.dimensions[YGDimensionHeight], height) + marginColumn; YGValueResolve(&child->style.dimensions[YGDimensionHeight], height) + marginColumn;
} else { } else {
@ -2230,12 +2236,16 @@ static void YGNodelayoutImpl(const YGNodeRef node,
childWidthMeasureMode = YGMeasureModeExactly; childWidthMeasureMode = YGMeasureModeExactly;
if (!YGFloatIsUndefined(availableInnerCrossDim) && if (!YGFloatIsUndefined(availableInnerCrossDim) &&
!YGNodeIsStyleDimDefined(currentRelativeChild, YGFlexDirectionColumn) && !YGNodeIsStyleDimDefined(currentRelativeChild,
YGFlexDirectionColumn,
availableInnerHeight) &&
heightMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly &&
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) { YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) {
childHeight = availableInnerCrossDim; childHeight = availableInnerCrossDim;
childHeightMeasureMode = YGMeasureModeExactly; childHeightMeasureMode = YGMeasureModeExactly;
} else if (!YGNodeIsStyleDimDefined(currentRelativeChild, YGFlexDirectionColumn)) { } else if (!YGNodeIsStyleDimDefined(currentRelativeChild,
YGFlexDirectionColumn,
availableInnerHeight)) {
childHeight = availableInnerCrossDim; childHeight = availableInnerCrossDim;
childHeightMeasureMode = childHeightMeasureMode =
YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeAtMost; YGFloatIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeAtMost;
@ -2250,12 +2260,16 @@ static void YGNodelayoutImpl(const YGNodeRef node,
childHeightMeasureMode = YGMeasureModeExactly; childHeightMeasureMode = YGMeasureModeExactly;
if (!YGFloatIsUndefined(availableInnerCrossDim) && if (!YGFloatIsUndefined(availableInnerCrossDim) &&
!YGNodeIsStyleDimDefined(currentRelativeChild, YGFlexDirectionRow) && !YGNodeIsStyleDimDefined(currentRelativeChild,
YGFlexDirectionRow,
availableInnerWidth) &&
widthMeasureMode == YGMeasureModeExactly && widthMeasureMode == YGMeasureModeExactly &&
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) { YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) {
childWidth = availableInnerCrossDim; childWidth = availableInnerCrossDim;
childWidthMeasureMode = YGMeasureModeExactly; childWidthMeasureMode = YGMeasureModeExactly;
} else if (!YGNodeIsStyleDimDefined(currentRelativeChild, YGFlexDirectionRow)) { } else if (!YGNodeIsStyleDimDefined(currentRelativeChild,
YGFlexDirectionRow,
availableInnerWidth)) {
childWidth = availableInnerCrossDim; childWidth = availableInnerCrossDim;
childWidthMeasureMode = childWidthMeasureMode =
YGFloatIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeAtMost; YGFloatIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeAtMost;
@ -2312,7 +2326,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
&childHeight); &childHeight);
const bool requiresStretchLayout = const bool requiresStretchLayout =
!YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis) && !YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) &&
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch; YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch;
// Recursively call the layout algorithm for this child with the updated // Recursively call the layout algorithm for this child with the updated
@ -2497,8 +2511,10 @@ static void YGNodelayoutImpl(const YGNodeRef node,
// current line. // current line.
if (alignItem == YGAlignStretch) { if (alignItem == YGAlignStretch) {
const bool isCrossSizeDefinite = const bool isCrossSizeDefinite =
(isMainAxisRow && YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn)) || (isMainAxisRow &&
(!isMainAxisRow && YGNodeIsStyleDimDefined(child, YGFlexDirectionRow)); YGNodeIsStyleDimDefined(child, YGFlexDirectionColumn, availableInnerHeight)) ||
(!isMainAxisRow &&
YGNodeIsStyleDimDefined(child, YGFlexDirectionRow, availableInnerWidth));
float childWidth; float childWidth;
float childHeight; float childHeight;
@ -3106,7 +3122,7 @@ void YGNodeCalculateLayout(const YGNodeRef node,
if (!YGFloatIsUndefined(width)) { if (!YGFloatIsUndefined(width)) {
widthMeasureMode = YGMeasureModeExactly; widthMeasureMode = YGMeasureModeExactly;
} else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow)) { } else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionRow, availableWidth)) {
width = YGValueResolve(&node->style.dimensions[dim[YGFlexDirectionRow]], availableWidth) + width = YGValueResolve(&node->style.dimensions[dim[YGFlexDirectionRow]], availableWidth) +
YGNodeMarginForAxis(node, YGFlexDirectionRow, availableWidth); YGNodeMarginForAxis(node, YGFlexDirectionRow, availableWidth);
widthMeasureMode = YGMeasureModeExactly; widthMeasureMode = YGMeasureModeExactly;
@ -3117,7 +3133,7 @@ void YGNodeCalculateLayout(const YGNodeRef node,
if (!YGFloatIsUndefined(height)) { if (!YGFloatIsUndefined(height)) {
heightMeasureMode = YGMeasureModeExactly; heightMeasureMode = YGMeasureModeExactly;
} else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn)) { } else if (YGNodeIsStyleDimDefined(node, YGFlexDirectionColumn, availableHeight)) {
height = YGValueResolve(&node->style.dimensions[dim[YGFlexDirectionColumn]], availableHeight) + height = YGValueResolve(&node->style.dimensions[dim[YGFlexDirectionColumn]], availableHeight) +
YGNodeMarginForAxis(node, YGFlexDirectionColumn, availableWidth); YGNodeMarginForAxis(node, YGFlexDirectionColumn, availableWidth);
heightMeasureMode = YGMeasureModeExactly; heightMeasureMode = YGMeasureModeExactly;