Skip to content

Commit

Permalink
Fix aspect ratio when stretching with main axis margin (#834)
Browse files Browse the repository at this point in the history
Summary:
I've noticed that when a child's size is determined by `align-items: stretch` in combination with `aspect-ratio` its size is wrongly calculated to account for margin in the main axis when there is more than enough space.

See playground: https://goo.gl/tgW6cD

I've yet to figure out exactly how to solve this but i've started by writing a failing test when can be seen in the first commit here.

I assumed I had found the bug here https://github.com/facebook/yoga/blob/master/yoga/Yoga.cpp#L1838 where margin is being subtracted from the desired width even though the measure mode tells it to measure to exactly that size. However, if we don't remove this margin from the available width then 15 tests fail (including the one I just added) not quite figured out why yet. I'm also a bit confused at to why this would only happen for nodes with `aspect-ratio` and not for nodes where an explicit height and width is set.
Pull Request resolved: facebook/yoga#834

Reviewed By: astreet

Differential Revision: D13223579

Pulled By: davidaurelio

fbshipit-source-id: 6970e6072e79f3bb6f9097355ab6e441441bfd88
  • Loading branch information
Emil Sjölander authored and facebook-github-bot committed Dec 10, 2018
1 parent c8047bf commit ee6b0d6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,16 @@ static void YGNodeComputeFlexBasisForChild(
auto marginColumn = YGUnwrapFloatOptional(
child->getMarginForAxis(YGFlexDirectionColumn, ownerWidth));

if (YGNodeAlignItem(node, child) == YGAlignStretch) {
if (isMainAxisRow && !YGFloatIsUndefined(height)) {
childHeight = height;
childHeightMeasureMode = YGMeasureModeExactly;
} else if (!isMainAxisRow && !YGFloatIsUndefined(width)) {
childWidth = width;
childWidthMeasureMode = YGMeasureModeExactly;
}
}

if (isRowStyleDimDefined) {
childWidth =
YGUnwrapFloatOptional(YGResolveValue(
Expand Down

0 comments on commit ee6b0d6

Please sign in to comment.