Skip to content

Commit

Permalink
Measure nodes which have margin: auto and align-item: stretch
Browse files Browse the repository at this point in the history
Summary:
If you have a measurable node and set ```marign-left: auto``` + ```align-item:stretch``` on it, it won't get measured and they get a width/height of ```-(nan)```. This change fixes that behaviour. Fixes #644.
Closes facebook/yoga#645

Differential Revision: D6413512

Pulled By: emilsjolander

fbshipit-source-id: 755febeb33bb0d4520ca6b3c28d56ac333e4a14d
  • Loading branch information
woehrl01 authored and facebook-github-bot committed Nov 27, 2017
1 parent 1050e0b commit 5f99b1a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
availableInnerCrossDim) &&
measureModeCrossDim == YGMeasureModeExactly &&
!(isNodeFlexWrap && flexBasisOverflows) &&
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch) {
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch &&
YGMarginLeadingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto &&
YGMarginTrailingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto) {
childCrossSize = availableInnerCrossDim;
childCrossMeasureMode = YGMeasureModeExactly;
} else if (!YGNodeIsStyleDimDefined(currentRelativeChild,
Expand Down Expand Up @@ -2363,7 +2365,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,

const bool requiresStretchLayout =
!YGNodeIsStyleDimDefined(currentRelativeChild, crossAxis, availableInnerCrossDim) &&
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch;
YGNodeAlignItem(node, currentRelativeChild) == YGAlignStretch &&
YGMarginLeadingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto &&
YGMarginTrailingValue(currentRelativeChild, crossAxis)->unit != YGUnitAuto;

const float childWidth = isMainAxisRow ? childMainSize : childCrossSize;
const float childHeight = !isMainAxisRow ? childMainSize : childCrossSize;
Expand Down

0 comments on commit 5f99b1a

Please sign in to comment.