Skip to content

Commit

Permalink
Merge pull request facebook#2 from intergalacticspacehighway/flex-gap…
Browse files Browse the repository at this point in the history
…-fixes

Flex gap fixes
  • Loading branch information
jacobp100 authored Dec 21, 2021
2 parents 812d4de + a52740b commit 0428c95
Show file tree
Hide file tree
Showing 6 changed files with 942 additions and 5 deletions.
228 changes: 228 additions & 0 deletions csharp/tests/Facebook.Yoga/YGGapTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,5 +1411,233 @@ public void Test_column_gap_wrap_align_space_around()
Assert.AreEqual(20f, root_child5.LayoutHeight);
}

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

YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.AlignContent = YogaAlign.Stretch;
root.Wrap = YogaWrap.Wrap;
root.Width = 100;
root.Height = 200;
root.ColumnGap = 10;
root.RowGap = 20;

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

YogaNode root_child1 = new YogaNode(config);
root_child1.Width = 20;
root.Insert(1, root_child1);

YogaNode root_child2 = new YogaNode(config);
root_child2.Width = 20;
root.Insert(2, root_child2);

YogaNode root_child3 = new YogaNode(config);
root_child3.Width = 20;
root.Insert(3, root_child3);

YogaNode root_child4 = new YogaNode(config);
root_child4.Width = 20;
root.Insert(4, root_child4);

YogaNode root_child5 = new YogaNode(config);
root_child5.Width = 20;
root.Insert(5, root_child5);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

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

Assert.AreEqual(30f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(20f, root_child1.LayoutWidth);
Assert.AreEqual(90f, root_child1.LayoutHeight);

Assert.AreEqual(60f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(20f, root_child2.LayoutWidth);
Assert.AreEqual(90f, root_child2.LayoutHeight);

Assert.AreEqual(0f, root_child3.LayoutX);
Assert.AreEqual(110f, root_child3.LayoutY);
Assert.AreEqual(20f, root_child3.LayoutWidth);
Assert.AreEqual(90f, root_child3.LayoutHeight);

Assert.AreEqual(30f, root_child4.LayoutX);
Assert.AreEqual(110f, root_child4.LayoutY);
Assert.AreEqual(20f, root_child4.LayoutWidth);
Assert.AreEqual(90f, root_child4.LayoutHeight);

Assert.AreEqual(60f, root_child5.LayoutX);
Assert.AreEqual(110f, root_child5.LayoutY);
Assert.AreEqual(20f, root_child5.LayoutWidth);
Assert.AreEqual(90f, root_child5.LayoutHeight);

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

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

Assert.AreEqual(80f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(20f, root_child0.LayoutWidth);
Assert.AreEqual(90f, root_child0.LayoutHeight);

Assert.AreEqual(50f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(20f, root_child1.LayoutWidth);
Assert.AreEqual(90f, root_child1.LayoutHeight);

Assert.AreEqual(20f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(20f, root_child2.LayoutWidth);
Assert.AreEqual(90f, root_child2.LayoutHeight);

Assert.AreEqual(80f, root_child3.LayoutX);
Assert.AreEqual(110f, root_child3.LayoutY);
Assert.AreEqual(20f, root_child3.LayoutWidth);
Assert.AreEqual(90f, root_child3.LayoutHeight);

Assert.AreEqual(50f, root_child4.LayoutX);
Assert.AreEqual(110f, root_child4.LayoutY);
Assert.AreEqual(20f, root_child4.LayoutWidth);
Assert.AreEqual(90f, root_child4.LayoutHeight);

Assert.AreEqual(20f, root_child5.LayoutX);
Assert.AreEqual(110f, root_child5.LayoutY);
Assert.AreEqual(20f, root_child5.LayoutWidth);
Assert.AreEqual(90f, root_child5.LayoutHeight);
}

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

YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.AlignItems = YogaAlign.FlexEnd;
root.Wrap = YogaWrap.Wrap;
root.Width = 100;
root.Height = 200;
root.ColumnGap = 10;
root.RowGap = 20;

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

YogaNode root_child1 = new YogaNode(config);
root_child1.Width = 20;
root.Insert(1, root_child1);

YogaNode root_child2 = new YogaNode(config);
root_child2.Width = 20;
root.Insert(2, root_child2);

YogaNode root_child3 = new YogaNode(config);
root_child3.Width = 20;
root.Insert(3, root_child3);

YogaNode root_child4 = new YogaNode(config);
root_child4.Width = 20;
root.Insert(4, root_child4);

YogaNode root_child5 = new YogaNode(config);
root_child5.Width = 20;
root.Insert(5, root_child5);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

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

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

Assert.AreEqual(30f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(20f, root_child1.LayoutWidth);
Assert.AreEqual(0f, root_child1.LayoutHeight);

Assert.AreEqual(60f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(20f, root_child2.LayoutWidth);
Assert.AreEqual(0f, root_child2.LayoutHeight);

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

Assert.AreEqual(30f, root_child4.LayoutX);
Assert.AreEqual(20f, root_child4.LayoutY);
Assert.AreEqual(20f, root_child4.LayoutWidth);
Assert.AreEqual(0f, root_child4.LayoutHeight);

Assert.AreEqual(60f, root_child5.LayoutX);
Assert.AreEqual(20f, root_child5.LayoutY);
Assert.AreEqual(20f, root_child5.LayoutWidth);
Assert.AreEqual(0f, root_child5.LayoutHeight);

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

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

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

Assert.AreEqual(50f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(20f, root_child1.LayoutWidth);
Assert.AreEqual(0f, root_child1.LayoutHeight);

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

Assert.AreEqual(80f, root_child3.LayoutX);
Assert.AreEqual(20f, root_child3.LayoutY);
Assert.AreEqual(20f, root_child3.LayoutWidth);
Assert.AreEqual(0f, root_child3.LayoutHeight);

Assert.AreEqual(50f, root_child4.LayoutX);
Assert.AreEqual(20f, root_child4.LayoutY);
Assert.AreEqual(20f, root_child4.LayoutWidth);
Assert.AreEqual(0f, root_child4.LayoutHeight);

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

}
}
20 changes: 20 additions & 0 deletions gentest/fixtures/YGGapTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,23 @@
<div style="width: 20px; height: 20px"></div>
<div style="width: 20px; height: 20px"></div>
</div>

<div id="row_gap_align_items_stretch" style="flex-direction: row; flex-wrap: wrap; width: 100px; height: 200px; column-gap: 10px; row-gap: 20px; align-items:stretch; align-content: stretch">
<div style="width: 20px; "></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
</div>


<div id="row_gap_align_items_end" style="flex-direction: row; flex-wrap: wrap; width: 100px; height: 200px; column-gap: 10px; row-gap: 20px; align-items:flex-end;">
<div style="width: 20px; "></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
<div style="width: 20px;"></div>
</div>

Loading

0 comments on commit 0428c95

Please sign in to comment.