Skip to content

Commit

Permalink
Fixing using flex in root node
Browse files Browse the repository at this point in the history
Summary: We should always try to make root node as small as possible, while previously this wasn't functioning this way

Reviewed By: emilsjolander

Differential Revision: D5071164

fbshipit-source-id: b8afef42477d0ed87d0c9fcfd26349e0a0babd6e
  • Loading branch information
Georgiy Kassabli authored and facebook-github-bot committed May 17, 2017
1 parent 49bccf4 commit f261219
Show file tree
Hide file tree
Showing 6 changed files with 822 additions and 1 deletion.
197 changes: 197 additions & 0 deletions csharp/tests/Facebook.Yoga/YGMinMaxDimensionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,203 @@ public void Test_flex_grow_within_constrained_max_width()
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
}

[Test]
public void Test_flex_root_ignored()
{
YogaConfig config = new YogaConfig();

YogaNode root = new YogaNode(config);
root.FlexGrow = 1;
root.Width = 100;
root.MinHeight = 100;
root.MaxHeight = 500;

YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.FlexBasis = 200;
root.Insert(0, root_child0);

YogaNode root_child1 = new YogaNode(config);
root_child1.Height = 100;
root.Insert(1, root_child1);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(300f, root.LayoutHeight);

Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0.LayoutHeight);

Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(200f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(100f, root_child1.LayoutHeight);

root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(300f, root.LayoutHeight);

Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0.LayoutHeight);

Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(200f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(100f, root_child1.LayoutHeight);
}

[Test]
public void Test_flex_grow_root_minimized()
{
YogaConfig config = new YogaConfig();

YogaNode root = new YogaNode(config);
root.Width = 100;
root.MinHeight = 100;
root.MaxHeight = 500;

YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.MinHeight = 100;
root_child0.MaxHeight = 500;
root.Insert(0, root_child0);

YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.FlexGrow = 1;
root_child0_child0.FlexBasis = 200;
root_child0.Insert(0, root_child0_child0);

YogaNode root_child0_child1 = new YogaNode(config);
root_child0_child1.Height = 100;
root_child0.Insert(1, root_child0_child1);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(300f, root.LayoutHeight);

Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(300f, root_child0.LayoutHeight);

Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);

Assert.AreEqual(0f, root_child0_child1.LayoutX);
Assert.AreEqual(200f, root_child0_child1.LayoutY);
Assert.AreEqual(100f, root_child0_child1.LayoutWidth);
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);

root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(300f, root.LayoutHeight);

Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(300f, root_child0.LayoutHeight);

Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);

Assert.AreEqual(0f, root_child0_child1.LayoutX);
Assert.AreEqual(200f, root_child0_child1.LayoutY);
Assert.AreEqual(100f, root_child0_child1.LayoutWidth);
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);
}

[Test]
public void Test_flex_grow_height_maximized()
{
YogaConfig config = new YogaConfig();

YogaNode root = new YogaNode(config);
root.Width = 100;
root.Height = 500;

YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.MinHeight = 100;
root_child0.MaxHeight = 500;
root.Insert(0, root_child0);

YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.FlexGrow = 1;
root_child0_child0.FlexBasis = 200;
root_child0.Insert(0, root_child0_child0);

YogaNode root_child0_child1 = new YogaNode(config);
root_child0_child1.Height = 100;
root_child0.Insert(1, root_child0_child1);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(500f, root.LayoutHeight);

Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(500f, root_child0.LayoutHeight);

Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
Assert.AreEqual(400f, root_child0_child0.LayoutHeight);

Assert.AreEqual(0f, root_child0_child1.LayoutX);
Assert.AreEqual(400f, root_child0_child1.LayoutY);
Assert.AreEqual(100f, root_child0_child1.LayoutWidth);
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);

root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(500f, root.LayoutHeight);

Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(500f, root_child0.LayoutHeight);

Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
Assert.AreEqual(400f, root_child0_child0.LayoutHeight);

Assert.AreEqual(0f, root_child0_child1.LayoutX);
Assert.AreEqual(400f, root_child0_child1.LayoutY);
Assert.AreEqual(100f, root_child0_child1.LayoutWidth);
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);
}

[Test]
public void Test_flex_grow_within_constrained_min_row()
{
Expand Down
19 changes: 19 additions & 0 deletions gentest/fixtures/YGMinMaxDimensionTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@
</div>
</div>

<div id="flex_root_ignored" style="width: 100px; min-height: 100px; max-height:500px;flex-grow:1">
<div style="flex-basis:200px; flex-grow:1;"></div>
<div style="height:100px; "></div>
</div>

<div id="flex_grow_root_minimized" style="width: 100px; min-height: 100px; max-height:500px">
<div style="min-height: 100px; max-height:500px;flex-grow:1">
<div style="flex-basis:200px; flex-grow:1;"></div>
<div style="height:100px; "></div>
</div>
</div>

<div id="flex_grow_height_maximized" style="width: 100px; height:500px">
<div style="min-height: 100px; max-height:500px;flex-grow:1">
<div style="flex-basis:200px; flex-grow:1;"></div>
<div style="height:100px; "></div>
</div>
</div>

<div id="flex_grow_within_constrained_min_row" style="min-width: 100px; height:100px; flex-direction: row;">
<div style="flex-grow:1;"></div>
<div style="width: 50px;"></div>
Expand Down
Loading

0 comments on commit f261219

Please sign in to comment.