Simplify YGNodeEmptyContainer / YGNodeWithMeasureFunc / YGNodeFixedSize
Summary: These methods are only ever called just after setting the various YGStyle props. Therefore we can read any padding / margin / border state from there rather than recalculating it. Changelog: [Internal] Reviewed By: SidharthGuglani Differential Revision: D27010098 fbshipit-source-id: a33f879b25c54cfdb0ffc724b6aa325858e97df5
This commit is contained in:
Родитель
3708181ca2
Коммит
07f9d21131
|
@ -1651,40 +1651,33 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
|
||||||
availableHeight = YGUndefined;
|
availableHeight = YGUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float paddingAndBorderAxisRow =
|
const auto& padding = node->getLayout().padding;
|
||||||
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth);
|
const auto& border = node->getLayout().border;
|
||||||
const float paddingAndBorderAxisColumn =
|
const float paddingAndBorderAxisRow = padding[YGEdgeLeft] +
|
||||||
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth);
|
padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight];
|
||||||
const float marginAxisRow =
|
const float paddingAndBorderAxisColumn = padding[YGEdgeTop] +
|
||||||
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap();
|
padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom];
|
||||||
const float marginAxisColumn =
|
|
||||||
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap();
|
|
||||||
|
|
||||||
// We want to make sure we don't call measure with negative size
|
// We want to make sure we don't call measure with negative size
|
||||||
const float innerWidth = YGFloatIsUndefined(availableWidth)
|
const float innerWidth = YGFloatIsUndefined(availableWidth)
|
||||||
? availableWidth
|
? availableWidth
|
||||||
: YGFloatMax(0, availableWidth - marginAxisRow - paddingAndBorderAxisRow);
|
: YGFloatMax(0, availableWidth - paddingAndBorderAxisRow);
|
||||||
const float innerHeight = YGFloatIsUndefined(availableHeight)
|
const float innerHeight = YGFloatIsUndefined(availableHeight)
|
||||||
? availableHeight
|
? availableHeight
|
||||||
: YGFloatMax(
|
: YGFloatMax(0, availableHeight - paddingAndBorderAxisColumn);
|
||||||
0, availableHeight - marginAxisColumn - paddingAndBorderAxisColumn);
|
|
||||||
|
|
||||||
if (widthMeasureMode == YGMeasureModeExactly &&
|
if (widthMeasureMode == YGMeasureModeExactly &&
|
||||||
heightMeasureMode == YGMeasureModeExactly) {
|
heightMeasureMode == YGMeasureModeExactly) {
|
||||||
// Don't bother sizing the text if both dimensions are already defined.
|
// Don't bother sizing the text if both dimensions are already defined.
|
||||||
node->setLayoutMeasuredDimension(
|
node->setLayoutMeasuredDimension(
|
||||||
YGNodeBoundAxis(
|
YGNodeBoundAxis(
|
||||||
node,
|
node, YGFlexDirectionRow, availableWidth, ownerWidth, ownerWidth),
|
||||||
YGFlexDirectionRow,
|
|
||||||
availableWidth - marginAxisRow,
|
|
||||||
ownerWidth,
|
|
||||||
ownerWidth),
|
|
||||||
YGDimensionWidth);
|
YGDimensionWidth);
|
||||||
node->setLayoutMeasuredDimension(
|
node->setLayoutMeasuredDimension(
|
||||||
YGNodeBoundAxis(
|
YGNodeBoundAxis(
|
||||||
node,
|
node,
|
||||||
YGFlexDirectionColumn,
|
YGFlexDirectionColumn,
|
||||||
availableHeight - marginAxisColumn,
|
availableHeight,
|
||||||
ownerHeight,
|
ownerHeight,
|
||||||
ownerWidth),
|
ownerWidth),
|
||||||
YGDimensionHeight);
|
YGDimensionHeight);
|
||||||
|
@ -1721,7 +1714,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
|
||||||
(widthMeasureMode == YGMeasureModeUndefined ||
|
(widthMeasureMode == YGMeasureModeUndefined ||
|
||||||
widthMeasureMode == YGMeasureModeAtMost)
|
widthMeasureMode == YGMeasureModeAtMost)
|
||||||
? measuredSize.width + paddingAndBorderAxisRow
|
? measuredSize.width + paddingAndBorderAxisRow
|
||||||
: availableWidth - marginAxisRow,
|
: availableWidth,
|
||||||
ownerWidth,
|
ownerWidth,
|
||||||
ownerWidth),
|
ownerWidth),
|
||||||
YGDimensionWidth);
|
YGDimensionWidth);
|
||||||
|
@ -1733,7 +1726,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
|
||||||
(heightMeasureMode == YGMeasureModeUndefined ||
|
(heightMeasureMode == YGMeasureModeUndefined ||
|
||||||
heightMeasureMode == YGMeasureModeAtMost)
|
heightMeasureMode == YGMeasureModeAtMost)
|
||||||
? measuredSize.height + paddingAndBorderAxisColumn
|
? measuredSize.height + paddingAndBorderAxisColumn
|
||||||
: availableHeight - marginAxisColumn,
|
: availableHeight,
|
||||||
ownerHeight,
|
ownerHeight,
|
||||||
ownerWidth),
|
ownerWidth),
|
||||||
YGDimensionHeight);
|
YGDimensionHeight);
|
||||||
|
@ -1750,37 +1743,28 @@ static void YGNodeEmptyContainerSetMeasuredDimensions(
|
||||||
const YGMeasureMode heightMeasureMode,
|
const YGMeasureMode heightMeasureMode,
|
||||||
const float ownerWidth,
|
const float ownerWidth,
|
||||||
const float ownerHeight) {
|
const float ownerHeight) {
|
||||||
const float paddingAndBorderAxisRow =
|
const auto& padding = node->getLayout().padding;
|
||||||
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth);
|
const auto& border = node->getLayout().border;
|
||||||
const float paddingAndBorderAxisColumn =
|
|
||||||
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth);
|
|
||||||
const float marginAxisRow =
|
|
||||||
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap();
|
|
||||||
const float marginAxisColumn =
|
|
||||||
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap();
|
|
||||||
|
|
||||||
|
float width = availableWidth;
|
||||||
|
if (widthMeasureMode == YGMeasureModeUndefined ||
|
||||||
|
widthMeasureMode == YGMeasureModeAtMost) {
|
||||||
|
width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] +
|
||||||
|
border[YGEdgeRight];
|
||||||
|
}
|
||||||
node->setLayoutMeasuredDimension(
|
node->setLayoutMeasuredDimension(
|
||||||
YGNodeBoundAxis(
|
YGNodeBoundAxis(node, YGFlexDirectionRow, width, ownerWidth, ownerWidth),
|
||||||
node,
|
|
||||||
YGFlexDirectionRow,
|
|
||||||
(widthMeasureMode == YGMeasureModeUndefined ||
|
|
||||||
widthMeasureMode == YGMeasureModeAtMost)
|
|
||||||
? paddingAndBorderAxisRow
|
|
||||||
: availableWidth - marginAxisRow,
|
|
||||||
ownerWidth,
|
|
||||||
ownerWidth),
|
|
||||||
YGDimensionWidth);
|
YGDimensionWidth);
|
||||||
|
|
||||||
|
float height = availableHeight;
|
||||||
|
if (heightMeasureMode == YGMeasureModeUndefined ||
|
||||||
|
heightMeasureMode == YGMeasureModeAtMost) {
|
||||||
|
height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] +
|
||||||
|
border[YGEdgeBottom];
|
||||||
|
}
|
||||||
node->setLayoutMeasuredDimension(
|
node->setLayoutMeasuredDimension(
|
||||||
YGNodeBoundAxis(
|
YGNodeBoundAxis(
|
||||||
node,
|
node, YGFlexDirectionColumn, height, ownerHeight, ownerWidth),
|
||||||
YGFlexDirectionColumn,
|
|
||||||
(heightMeasureMode == YGMeasureModeUndefined ||
|
|
||||||
heightMeasureMode == YGMeasureModeAtMost)
|
|
||||||
? paddingAndBorderAxisColumn
|
|
||||||
: availableHeight - marginAxisColumn,
|
|
||||||
ownerHeight,
|
|
||||||
ownerWidth),
|
|
||||||
YGDimensionHeight);
|
YGDimensionHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1798,11 +1782,6 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(
|
||||||
heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) ||
|
heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) ||
|
||||||
(widthMeasureMode == YGMeasureModeExactly &&
|
(widthMeasureMode == YGMeasureModeExactly &&
|
||||||
heightMeasureMode == YGMeasureModeExactly)) {
|
heightMeasureMode == YGMeasureModeExactly)) {
|
||||||
auto marginAxisColumn =
|
|
||||||
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap();
|
|
||||||
auto marginAxisRow =
|
|
||||||
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap();
|
|
||||||
|
|
||||||
node->setLayoutMeasuredDimension(
|
node->setLayoutMeasuredDimension(
|
||||||
YGNodeBoundAxis(
|
YGNodeBoundAxis(
|
||||||
node,
|
node,
|
||||||
|
@ -1811,7 +1790,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(
|
||||||
(widthMeasureMode == YGMeasureModeAtMost &&
|
(widthMeasureMode == YGMeasureModeAtMost &&
|
||||||
availableWidth < 0.0f)
|
availableWidth < 0.0f)
|
||||||
? 0.0f
|
? 0.0f
|
||||||
: availableWidth - marginAxisRow,
|
: availableWidth,
|
||||||
ownerWidth,
|
ownerWidth,
|
||||||
ownerWidth),
|
ownerWidth),
|
||||||
YGDimensionWidth);
|
YGDimensionWidth);
|
||||||
|
@ -1824,7 +1803,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(
|
||||||
(heightMeasureMode == YGMeasureModeAtMost &&
|
(heightMeasureMode == YGMeasureModeAtMost &&
|
||||||
availableHeight < 0.0f)
|
availableHeight < 0.0f)
|
||||||
? 0.0f
|
? 0.0f
|
||||||
: availableHeight - marginAxisColumn,
|
: availableHeight,
|
||||||
ownerHeight,
|
ownerHeight,
|
||||||
ownerWidth),
|
ownerWidth),
|
||||||
YGDimensionHeight);
|
YGDimensionHeight);
|
||||||
|
@ -2739,16 +2718,22 @@ static void YGNodelayoutImpl(
|
||||||
const YGEdge startEdge =
|
const YGEdge startEdge =
|
||||||
direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight;
|
direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight;
|
||||||
const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft;
|
const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft;
|
||||||
node->setLayoutMargin(
|
|
||||||
node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(), startEdge);
|
const float marginRowLeading =
|
||||||
node->setLayoutMargin(
|
node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap();
|
||||||
node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(), endEdge);
|
node->setLayoutMargin(marginRowLeading, startEdge);
|
||||||
node->setLayoutMargin(
|
const float marginRowTrailing =
|
||||||
node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(),
|
node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap();
|
||||||
YGEdgeTop);
|
node->setLayoutMargin(marginRowTrailing, endEdge);
|
||||||
node->setLayoutMargin(
|
const float marginColumnLeading =
|
||||||
node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(),
|
node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap();
|
||||||
YGEdgeBottom);
|
node->setLayoutMargin(marginColumnLeading, YGEdgeTop);
|
||||||
|
const float marginColumnTrailing =
|
||||||
|
node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap();
|
||||||
|
node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom);
|
||||||
|
|
||||||
|
const float marginAxisRow = marginRowLeading + marginRowTrailing;
|
||||||
|
const float marginAxisColumn = marginColumnLeading + marginColumnTrailing;
|
||||||
|
|
||||||
node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge);
|
node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge);
|
||||||
node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge);
|
node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge);
|
||||||
|
@ -2771,8 +2756,8 @@ static void YGNodelayoutImpl(
|
||||||
if (node->hasMeasureFunc()) {
|
if (node->hasMeasureFunc()) {
|
||||||
YGNodeWithMeasureFuncSetMeasuredDimensions(
|
YGNodeWithMeasureFuncSetMeasuredDimensions(
|
||||||
node,
|
node,
|
||||||
availableWidth,
|
availableWidth - marginAxisRow,
|
||||||
availableHeight,
|
availableHeight - marginAxisColumn,
|
||||||
widthMeasureMode,
|
widthMeasureMode,
|
||||||
heightMeasureMode,
|
heightMeasureMode,
|
||||||
ownerWidth,
|
ownerWidth,
|
||||||
|
@ -2787,8 +2772,8 @@ static void YGNodelayoutImpl(
|
||||||
if (childCount == 0) {
|
if (childCount == 0) {
|
||||||
YGNodeEmptyContainerSetMeasuredDimensions(
|
YGNodeEmptyContainerSetMeasuredDimensions(
|
||||||
node,
|
node,
|
||||||
availableWidth,
|
availableWidth - marginAxisRow,
|
||||||
availableHeight,
|
availableHeight - marginAxisColumn,
|
||||||
widthMeasureMode,
|
widthMeasureMode,
|
||||||
heightMeasureMode,
|
heightMeasureMode,
|
||||||
ownerWidth,
|
ownerWidth,
|
||||||
|
@ -2801,8 +2786,8 @@ static void YGNodelayoutImpl(
|
||||||
if (!performLayout &&
|
if (!performLayout &&
|
||||||
YGNodeFixedSizeSetMeasuredDimensions(
|
YGNodeFixedSizeSetMeasuredDimensions(
|
||||||
node,
|
node,
|
||||||
availableWidth,
|
availableWidth - marginAxisRow,
|
||||||
availableHeight,
|
availableHeight - marginAxisColumn,
|
||||||
widthMeasureMode,
|
widthMeasureMode,
|
||||||
heightMeasureMode,
|
heightMeasureMode,
|
||||||
ownerWidth,
|
ownerWidth,
|
||||||
|
@ -2845,11 +2830,6 @@ static void YGNodelayoutImpl(
|
||||||
const float paddingAndBorderAxisColumn =
|
const float paddingAndBorderAxisColumn =
|
||||||
isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain;
|
isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain;
|
||||||
|
|
||||||
const float marginAxisRow =
|
|
||||||
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap();
|
|
||||||
const float marginAxisColumn =
|
|
||||||
node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap();
|
|
||||||
|
|
||||||
// STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS
|
// STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS
|
||||||
|
|
||||||
float availableInnerWidth = YGNodeCalculateAvailableInnerDim(
|
float availableInnerWidth = YGNodeCalculateAvailableInnerDim(
|
||||||
|
|
Загрузка…
Ссылка в новой задаче