Fix flex within max width constraint

Summary:
Max dimension constraints were not correctly passed down to children.

see https://github.com/facebook/css-layout/issues/230 for more info
fixes #230

Reviewed By: gkassabli

Differential Revision: D4147199

fbshipit-source-id: feb335eb8687a1b7939ee8cd8649e455e0c069a9
This commit is contained in:
Emil Sjolander
2016-11-08 09:45:58 -08:00
committed by Facebook Github Bot
parent 1baa239389
commit 3e567fdcae
5 changed files with 210 additions and 0 deletions

View File

@@ -41,6 +41,12 @@
<div style="width: 50px; height: 50px;"></div>
<div style="width: 50px; height: 50px;"></div>
</div>
<div id="flex_grow_within_max_width" style="width: 200px; height: 100px;">
<div style="flex-direction: row; max-width: 100px;">
<div style="height: 20px; flex-grow: 1;"></div>
</div>
</div>
*
*/
@@ -363,3 +369,54 @@ TEST(CSSLayoutTest, justify_content_overflow_min_max) {
CSSNodeFreeRecursive(root);
}
TEST(CSSLayoutTest, flex_grow_within_max_width) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetWidth(root, 200);
CSSNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root_child0, CSSFlexDirectionRow);
CSSNodeStyleSetMaxWidth(root_child0, 100);
CSSNodeInsertChild(root, root_child0, 0);
const CSSNodeRef root_child0_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0_child0, 1);
CSSNodeStyleSetHeight(root_child0_child0, 20);
CSSNodeInsertChild(root_child0, root_child0_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(0, CSSNodeLayoutGetLeft(root));
ASSERT_EQ(0, CSSNodeLayoutGetTop(root));
ASSERT_EQ(200, CSSNodeLayoutGetWidth(root));
ASSERT_EQ(100, CSSNodeLayoutGetHeight(root));
ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0));
ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0));
ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child0));
ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0_child0));
ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0_child0));
ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0_child0));
ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child0_child0));
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL);
ASSERT_EQ(0, CSSNodeLayoutGetLeft(root));
ASSERT_EQ(0, CSSNodeLayoutGetTop(root));
ASSERT_EQ(200, CSSNodeLayoutGetWidth(root));
ASSERT_EQ(100, CSSNodeLayoutGetHeight(root));
ASSERT_EQ(100, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0));
ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0));
ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child0));
ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0_child0));
ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child0_child0));
ASSERT_EQ(100, CSSNodeLayoutGetWidth(root_child0_child0));
ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child0_child0));
CSSNodeFreeRecursive(root);
}