Skip to content

Commit

Permalink
Fix min/max percentage constraints on measured nodes
Browse files Browse the repository at this point in the history
Summary:
Fix min/max percentage constraints on measured nodes. Currently we passed in the available size instead of the parent size.
Fixes facebook#611
Closes facebook#649

Reviewed By: priteshrnandgaonkar

Differential Revision: D6408019

Pulled By: emilsjolander

fbshipit-source-id: 18be5056dbc0dc179970ec231ab8b4e2cdba65c5
  • Loading branch information
woehrl01 authored and facebook-github-bot committed Nov 30, 2017
1 parent 2e468d9 commit ad1240e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
53 changes: 53 additions & 0 deletions tests/YGMeasureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,56 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
YGNodeFreeRecursive(root);
YGConfigFree(config);
}

static YGSize _measure_90_10(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {

return YGSize{
.width = 90, .height = 10,
};
}

TEST(YogaTest, percent_with_text_node) {
const YGConfigRef config = YGConfigNew();

const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetJustifyContent(root, YGJustifySpaceBetween);
YGNodeStyleSetAlignItems(root, YGAlignCenter);
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 80);

const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeInsertChild(root, root_child0, 0);

const YGNodeRef root_child1 = YGNodeNewWithConfig(config);

YGNodeSetMeasureFunc(root_child1, _measure_90_10);
YGNodeStyleSetMaxWidthPercent(root_child1, 50);
YGNodeStyleSetPaddingPercent(root_child1, YGEdgeTop, 50);
YGNodeInsertChild(root, root_child1, 1);

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root));

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0));

ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(15, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));

YGNodeFreeRecursive(root);

YGConfigFree(config);
}
8 changes: 4 additions & 4 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,17 +1592,17 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node,
widthMeasureMode == YGMeasureModeAtMost)
? measuredSize.width + paddingAndBorderAxisRow
: availableWidth - marginAxisRow,
availableWidth,
availableWidth);
parentWidth,
parentWidth);
node->layout.measuredDimensions[YGDimensionHeight] =
YGNodeBoundAxis(node,
YGFlexDirectionColumn,
(heightMeasureMode == YGMeasureModeUndefined ||
heightMeasureMode == YGMeasureModeAtMost)
? measuredSize.height + paddingAndBorderAxisColumn
: availableHeight - marginAxisColumn,
availableHeight,
availableWidth);
parentHeight,
parentWidth);
}
}

Expand Down

0 comments on commit ad1240e

Please sign in to comment.