Skip to content

Commit

Permalink
Fix align-content: center, flex-end alignment with margin
Browse files Browse the repository at this point in the history
Summary:
This fixes ```align-content: center``` and ```align-content: flex-end``` when the child exceeds the parents size. See facebook#476. It also fixes those layouts if the child has ```margin: auto``` set.
Closes facebook#477

Differential Revision: D4697833

Pulled By: emilsjolander

fbshipit-source-id: d081ec7ea559a5f2bd3271c3a4dc272960beddfa
  • Loading branch information
woehrl01 authored and facebook-github-bot committed Mar 15, 2017
1 parent 1105205 commit b94466e
Show file tree
Hide file tree
Showing 11 changed files with 1,623 additions and 9 deletions.
228 changes: 228 additions & 0 deletions csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,5 +1587,233 @@ public void Test_align_baseline_multiline_row_and_column()
Assert.AreEqual(20f, root_child3.LayoutHeight);
}

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

YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.Width = 52;
root.Height = 52;

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

YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.MarginLeft = 10;
root_child0_child0.MarginRight = 10;
root_child0_child0.Width = 52;
root_child0_child0.Height = 52;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0.LayoutHeight);

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

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

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

Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0.LayoutHeight);

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

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

YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.Width = 52;
root.Height = 52;

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

YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.MarginLeft = 10;
root_child0_child0.MarginRight = 10;
root_child0_child0.Width = 52;
root_child0_child0.Height = 52;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0.LayoutHeight);

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

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

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

Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0.LayoutHeight);

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

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

YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.Width = 52;
root.Height = 52;

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

YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.Width = 72;
root_child0_child0.Height = 72;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);

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

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

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

Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);

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

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

YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.Width = 52;
root.Height = 52;

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

YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.Width = 72;
root_child0_child0.Height = 72;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);

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

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

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

Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);

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

}
}
Loading

0 comments on commit b94466e

Please sign in to comment.