Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shrinking in non strech alignments while retaining legacy behaviour #635

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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