Skip to content

Commit

Permalink
Fix shrinking in non strech alignments while retaining legacy behaviour
Browse files Browse the repository at this point in the history
Summary:
This fixes shrinking of elements which are in a non stretch alignment, but keeps the legacy stretch behaviour in place. Additionally this adds a testcase for ```useLegacyStretchBehaviour```

Fixes #633
Closes #635

Differential Revision: D6408037

Pulled By: emilsjolander

fbshipit-source-id: 377ab0308dd3a75a148a0af31ab5eb3ffb5b5d83
  • Loading branch information
woehrl01 authored and facebook-github-bot committed Nov 27, 2017
1 parent 5aa0f44 commit 5e39f1a
Show file tree
Hide file tree
Showing 7 changed files with 903 additions and 1 deletion.
206 changes: 206 additions & 0 deletions csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1958,5 +1958,211 @@ public void Test_align_strech_should_size_based_on_parent()
Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight);
}

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

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

YogaNode root_child0 = new YogaNode(config);
root_child0.AlignItems = YogaAlign.FlexStart;
root.Insert(0, root_child0);

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

YogaNode root_child0_child0_child0 = new YogaNode(config);
root_child0_child0_child0.FlexGrow = 1;
root_child0_child0_child0.FlexShrink = 1;
root_child0_child0.Insert(0, root_child0_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

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

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

Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutWidth);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutHeight);

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

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

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

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

Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutWidth);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutHeight);
}

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

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

YogaNode root_child0 = new YogaNode(config);
root.Insert(0, root_child0);

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

YogaNode root_child0_child0_child0 = new YogaNode(config);
root_child0_child0_child0.FlexGrow = 1;
root_child0_child0_child0.FlexShrink = 1;
root_child0_child0.Insert(0, root_child0_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

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

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

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

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

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

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

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

Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
Assert.AreEqual(500f, root_child0_child0_child0.LayoutWidth);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutHeight);
}

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

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

YogaNode root_child0 = new YogaNode(config);
root_child0.AlignItems = YogaAlign.FlexStart;
root.Insert(0, root_child0);

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

YogaNode root_child0_child0_child0 = new YogaNode(config);
root_child0_child0_child0.FlexGrow = 1;
root_child0_child0_child0.FlexShrink = 1;
root_child0_child0.Insert(0, root_child0_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

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

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

Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutWidth);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutHeight);

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

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

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

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

Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutWidth);
Assert.AreEqual(0f, root_child0_child0_child0.LayoutHeight);
}

}
}
23 changes: 23 additions & 0 deletions gentest/fixtures/YGAlignItemsTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,26 @@
</div>
</div>

<div id="align_flex_start_with_shrinking_children" style="height: 500px; width: 500px">
<div style="align-items: flex-start;">
<div style="flex-grow: 1; flex-shrink: 1;">
<div style="flex-grow: 1; flex-shrink: 1;"></div>
</div>
</div>
</div>

<div id="align_flex_start_with_stretching_children" style="height: 500px; width: 500px">
<div style="align-items: strech;">
<div style="flex-grow: 1; flex-shrink: 1;">
<div style="flex-grow: 1; flex-shrink: 1;"></div>
</div>
</div>
</div>

<div id="align_flex_start_with_shrinking_children_with_stretch" style="height: 500px; width: 500px">
<div style="align-items: flex-start;">
<div style="flex-grow: 1; flex-shrink: 1; align-items: stretch;">
<div style="flex-grow: 1; flex-shrink: 1;"></div>
</div>
</div>
</div>
Loading

0 comments on commit 5e39f1a

Please sign in to comment.