Skip to content

Commit

Permalink
Solve the bug related to baseline height
Browse files Browse the repository at this point in the history
Summary:
This diff fixes the height calculation logic for the nodes with baseline. Before height calculation for baseline was done at wrong place.

The task was created due to the regression caused by D9219678.

Reviewed By: IanChilds

Differential Revision: D9421551

fbshipit-source-id: 3fbb738314130b346c4186ec45d00c9ea63bc9f4
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Aug 22, 2018
1 parent f884a1b commit d85226f
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,9 @@ static void YGJustifyMainAxis(
leadingPaddingAndBorderMain + leadingMainDim;
collectedFlexItemsValues.crossDim = 0;

float maxAscentForCurrentLine = 0;
float maxDescentForCurrentLine = 0;
bool isNodeBaselineLayout = YGIsBaselineLayout(node);
for (uint32_t i = startOfLineIndex;
i < collectedFlexItemsValues.endOfLineIndex;
i++) {
Expand Down Expand Up @@ -2575,11 +2578,30 @@ static void YGJustifyMainAxis(
collectedFlexItemsValues.mainDim += betweenMainDim +
YGNodeDimWithMargin(child, mainAxis, availableInnerWidth);

// The cross dimension is the max of the elements dimension since
// there can only be one element in that cross dimension.
collectedFlexItemsValues.crossDim = YGFloatMax(
collectedFlexItemsValues.crossDim,
YGNodeDimWithMargin(child, crossAxis, availableInnerWidth));
if (isNodeBaselineLayout) {
// If the child is baseline aligned then the cross dimension is
// calculated by adding maxAscent and maxDescent from the baseline.
const float ascent = YGBaseline(child) +
YGUnwrapFloatOptional(child->getLeadingMargin(
YGFlexDirectionColumn, availableInnerWidth));
const float descent =
child->getLayout().measuredDimensions[YGDimensionHeight] +
YGUnwrapFloatOptional(child->getMarginForAxis(
YGFlexDirectionColumn, availableInnerWidth)) -
ascent;

maxAscentForCurrentLine =
YGFloatMax(maxAscentForCurrentLine, ascent);
maxDescentForCurrentLine =
YGFloatMax(maxDescentForCurrentLine, descent);
} else {
// The cross dimension is the max of the elements dimension since
// there can only be one element in that cross dimension in the case
// when the items are not baseline aligned
collectedFlexItemsValues.crossDim = YGFloatMax(
collectedFlexItemsValues.crossDim,
YGNodeDimWithMargin(child, crossAxis, availableInnerWidth));
}
}
} else if (performLayout) {
child->setLayoutPosition(
Expand All @@ -2590,6 +2612,11 @@ static void YGJustifyMainAxis(
}
}
collectedFlexItemsValues.mainDim += trailingPaddingAndBorderMain;

if (isNodeBaselineLayout) {
collectedFlexItemsValues.crossDim =
maxAscentForCurrentLine + maxDescentForCurrentLine;
}
}

//
Expand Down Expand Up @@ -3187,9 +3214,9 @@ static void YGNodelayoutImpl(

// STEP 8: MULTI-LINE CONTENT ALIGNMENT
// currentLead stores the size of the cross dim
float currentLead = leadingPaddingAndBorderCross;
if (performLayout && (lineCount > 1 || YGIsBaselineLayout(node))) {
float crossDimLead = 0;
float currentLead = leadingPaddingAndBorderCross;
if (!YGFloatIsUndefined(availableInnerCrossDim)) {
const float remainingAlignContentDim =
availableInnerCrossDim - totalLineCrossDim;
Expand Down Expand Up @@ -3372,7 +3399,6 @@ static void YGNodelayoutImpl(
}
}
}

currentLead += lineHeight;
}
}
Expand Down Expand Up @@ -3452,18 +3478,6 @@ static void YGNodelayoutImpl(
dim[crossAxis]);
}

if (performLayout &&
node->getStyle().dimensions[dim[crossAxis]].unit == YGUnitAuto &&
node->getStyle().alignItems == YGAlignBaseline) {
node->setLayoutMeasuredDimension(
YGNodeBoundAxis(
node,
crossAxis,
currentLead + paddingAndBorderAxisRow,
crossAxisownerSize,
ownerWidth),
dim[crossAxis]);
}
// As we only wrapped in normal direction yet, we need to reverse the
// positions on wrap-reverse.
if (performLayout && node->getStyle().flexWrap == YGWrapWrapReverse) {
Expand Down

0 comments on commit d85226f

Please sign in to comment.