Skip to content

Commit 4f5c7ed

Browse files
woehrl01facebook-github-bot
authored andcommitted
Fix align-content:strech overriding align-item
Summary: Fix for #413. This was a hangover from a previous attept to fix other align-content problems. Closes #417 Reviewed By: astreet Differential Revision: D4604727 Pulled By: emilsjolander fbshipit-source-id: 92fd31a385d8182c6b201c891d5ae478372d525d
1 parent 60ffa19 commit 4f5c7ed

File tree

6 files changed

+229
-2
lines changed

6 files changed

+229
-2
lines changed

csharp/tests/Facebook.Yoga/YGAlignContentTest.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,5 +1790,61 @@ public void Test_align_content_stretch_column()
17901790
Assert.AreEqual(50f, root_child4.LayoutHeight);
17911791
}
17921792

1793+
[Test]
1794+
public void Test_align_content_stretch_is_not_overriding_align_items()
1795+
{
1796+
YogaNode root = new YogaNode();
1797+
root.AlignContent = YogaAlign.Stretch;
1798+
1799+
YogaNode root_child0 = new YogaNode();
1800+
root_child0.FlexDirection = YogaFlexDirection.Row;
1801+
root_child0.AlignContent = YogaAlign.Stretch;
1802+
root_child0.AlignItems = YogaAlign.Center;
1803+
root_child0.Width = 100;
1804+
root_child0.Height = 100;
1805+
root.Insert(0, root_child0);
1806+
1807+
YogaNode root_child0_child0 = new YogaNode();
1808+
root_child0_child0.AlignContent = YogaAlign.Stretch;
1809+
root_child0_child0.Width = 10;
1810+
root_child0_child0.Height = 10;
1811+
root_child0.Insert(0, root_child0_child0);
1812+
root.StyleDirection = YogaDirection.LTR;
1813+
root.CalculateLayout();
1814+
1815+
Assert.AreEqual(0f, root.LayoutX);
1816+
Assert.AreEqual(0f, root.LayoutY);
1817+
Assert.AreEqual(100f, root.LayoutWidth);
1818+
Assert.AreEqual(100f, root.LayoutHeight);
1819+
1820+
Assert.AreEqual(0f, root_child0.LayoutX);
1821+
Assert.AreEqual(0f, root_child0.LayoutY);
1822+
Assert.AreEqual(100f, root_child0.LayoutWidth);
1823+
Assert.AreEqual(100f, root_child0.LayoutHeight);
1824+
1825+
Assert.AreEqual(0f, root_child0_child0.LayoutX);
1826+
Assert.AreEqual(45f, root_child0_child0.LayoutY);
1827+
Assert.AreEqual(10f, root_child0_child0.LayoutWidth);
1828+
Assert.AreEqual(10f, root_child0_child0.LayoutHeight);
1829+
1830+
root.StyleDirection = YogaDirection.RTL;
1831+
root.CalculateLayout();
1832+
1833+
Assert.AreEqual(0f, root.LayoutX);
1834+
Assert.AreEqual(0f, root.LayoutY);
1835+
Assert.AreEqual(100f, root.LayoutWidth);
1836+
Assert.AreEqual(100f, root.LayoutHeight);
1837+
1838+
Assert.AreEqual(0f, root_child0.LayoutX);
1839+
Assert.AreEqual(0f, root_child0.LayoutY);
1840+
Assert.AreEqual(100f, root_child0.LayoutWidth);
1841+
Assert.AreEqual(100f, root_child0.LayoutHeight);
1842+
1843+
Assert.AreEqual(90f, root_child0_child0.LayoutX);
1844+
Assert.AreEqual(45f, root_child0_child0.LayoutY);
1845+
Assert.AreEqual(10f, root_child0_child0.LayoutWidth);
1846+
Assert.AreEqual(10f, root_child0_child0.LayoutHeight);
1847+
}
1848+
17931849
}
17941850
}

gentest/fixtures/YGAlignContentTest.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,9 @@
142142
<div style="height: 50px;"></div>
143143
<div style="height: 50px;"></div>
144144
</div>
145+
146+
<div id="align_content_stretch_is_not_overriding_align_items" style="align-content:stretch;">
147+
<div style="width:100px; height: 100px; align-items: center; flex-direction: row; align-content:stretch;">
148+
<div style="height: 10px; width: 10px; align-content:stretch;"></div>
149+
</div>
150+
</div>

java/tests/com/facebook/yoga/YGAlignContentTest.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,4 +1771,59 @@ public void test_align_content_stretch_column() {
17711771
assertEquals(50f, root_child4.getLayoutHeight(), 0.0f);
17721772
}
17731773

1774+
@Test
1775+
public void test_align_content_stretch_is_not_overriding_align_items() {
1776+
final YogaNode root = new YogaNode();
1777+
root.setAlignContent(YogaAlign.STRETCH);
1778+
1779+
final YogaNode root_child0 = new YogaNode();
1780+
root_child0.setFlexDirection(YogaFlexDirection.ROW);
1781+
root_child0.setAlignContent(YogaAlign.STRETCH);
1782+
root_child0.setAlignItems(YogaAlign.CENTER);
1783+
root_child0.setWidth(100f);
1784+
root_child0.setHeight(100f);
1785+
root.addChildAt(root_child0, 0);
1786+
1787+
final YogaNode root_child0_child0 = new YogaNode();
1788+
root_child0_child0.setAlignContent(YogaAlign.STRETCH);
1789+
root_child0_child0.setWidth(10f);
1790+
root_child0_child0.setHeight(10f);
1791+
root_child0.addChildAt(root_child0_child0, 0);
1792+
root.setDirection(YogaDirection.LTR);
1793+
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
1794+
1795+
assertEquals(0f, root.getLayoutX(), 0.0f);
1796+
assertEquals(0f, root.getLayoutY(), 0.0f);
1797+
assertEquals(100f, root.getLayoutWidth(), 0.0f);
1798+
assertEquals(100f, root.getLayoutHeight(), 0.0f);
1799+
1800+
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
1801+
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
1802+
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
1803+
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
1804+
1805+
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
1806+
assertEquals(45f, root_child0_child0.getLayoutY(), 0.0f);
1807+
assertEquals(10f, root_child0_child0.getLayoutWidth(), 0.0f);
1808+
assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
1809+
1810+
root.setDirection(YogaDirection.RTL);
1811+
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
1812+
1813+
assertEquals(0f, root.getLayoutX(), 0.0f);
1814+
assertEquals(0f, root.getLayoutY(), 0.0f);
1815+
assertEquals(100f, root.getLayoutWidth(), 0.0f);
1816+
assertEquals(100f, root.getLayoutHeight(), 0.0f);
1817+
1818+
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
1819+
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
1820+
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
1821+
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
1822+
1823+
assertEquals(90f, root_child0_child0.getLayoutX(), 0.0f);
1824+
assertEquals(45f, root_child0_child0.getLayoutY(), 0.0f);
1825+
assertEquals(10f, root_child0_child0.getLayoutWidth(), 0.0f);
1826+
assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
1827+
}
1828+
17741829
}

javascript/tests/Facebook.Yoga/YGAlignContentTest.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,3 +1802,60 @@ it("align_content_stretch_column", function () {
18021802
}
18031803
}
18041804
});
1805+
it("align_content_stretch_is_not_overriding_align_items", function () {
1806+
try {
1807+
var root = Yoga.Node.create();
1808+
root.setAlignContent(Yoga.ALIGN_STRETCH);
1809+
1810+
var root_child0 = Yoga.Node.create();
1811+
root_child0.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
1812+
root_child0.setAlignContent(Yoga.ALIGN_STRETCH);
1813+
root_child0.setAlignItems(Yoga.ALIGN_CENTER);
1814+
root_child0.setWidth(100);
1815+
root_child0.setHeight(100);
1816+
root.insertChild(root_child0, 0);
1817+
1818+
var root_child0_child0 = Yoga.Node.create();
1819+
root_child0_child0.setAlignContent(Yoga.ALIGN_STRETCH);
1820+
root_child0_child0.setWidth(10);
1821+
root_child0_child0.setHeight(10);
1822+
root_child0.insertChild(root_child0_child0, 0);
1823+
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
1824+
1825+
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
1826+
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
1827+
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
1828+
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
1829+
1830+
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
1831+
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
1832+
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
1833+
console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
1834+
1835+
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
1836+
console.assert(45 === root_child0_child0.getComputedTop(), "45 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
1837+
console.assert(10 === root_child0_child0.getComputedWidth(), "10 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
1838+
console.assert(10 === root_child0_child0.getComputedHeight(), "10 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
1839+
1840+
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
1841+
1842+
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
1843+
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
1844+
console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
1845+
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
1846+
1847+
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
1848+
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
1849+
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
1850+
console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
1851+
1852+
console.assert(90 === root_child0_child0.getComputedLeft(), "90 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
1853+
console.assert(45 === root_child0_child0.getComputedTop(), "45 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
1854+
console.assert(10 === root_child0_child0.getComputedWidth(), "10 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
1855+
console.assert(10 === root_child0_child0.getComputedHeight(), "10 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
1856+
} finally {
1857+
if (typeof root !== "undefined") {
1858+
root.freeRecursive();
1859+
}
1860+
}
1861+
});

tests/YGAlignContentTest.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,3 +1748,57 @@ TEST(YogaTest, align_content_stretch_column) {
17481748

17491749
YGNodeFreeRecursive(root);
17501750
}
1751+
1752+
TEST(YogaTest, align_content_stretch_is_not_overriding_align_items) {
1753+
const YGNodeRef root = YGNodeNew();
1754+
YGNodeStyleSetAlignContent(root, YGAlignStretch);
1755+
1756+
const YGNodeRef root_child0 = YGNodeNew();
1757+
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
1758+
YGNodeStyleSetAlignContent(root_child0, YGAlignStretch);
1759+
YGNodeStyleSetAlignItems(root_child0, YGAlignCenter);
1760+
YGNodeStyleSetWidth(root_child0, 100);
1761+
YGNodeStyleSetHeight(root_child0, 100);
1762+
YGNodeInsertChild(root, root_child0, 0);
1763+
1764+
const YGNodeRef root_child0_child0 = YGNodeNew();
1765+
YGNodeStyleSetAlignContent(root_child0_child0, YGAlignStretch);
1766+
YGNodeStyleSetWidth(root_child0_child0, 10);
1767+
YGNodeStyleSetHeight(root_child0_child0, 10);
1768+
YGNodeInsertChild(root_child0, root_child0_child0, 0);
1769+
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
1770+
1771+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
1772+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
1773+
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
1774+
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
1775+
1776+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
1777+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
1778+
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
1779+
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
1780+
1781+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
1782+
ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child0_child0));
1783+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0_child0));
1784+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0));
1785+
1786+
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
1787+
1788+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
1789+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
1790+
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
1791+
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
1792+
1793+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
1794+
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
1795+
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
1796+
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
1797+
1798+
ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0_child0));
1799+
ASSERT_FLOAT_EQ(45, YGNodeLayoutGetTop(root_child0_child0));
1800+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0_child0));
1801+
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0));
1802+
1803+
YGNodeFreeRecursive(root);
1804+
}

yoga/Yoga.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,8 +2666,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
26662666
}
26672667

26682668
// STEP 8: MULTI-LINE CONTENT ALIGNMENT
2669-
if (performLayout &&
2670-
(lineCount > 1 || node->style.alignContent == YGAlignStretch || YGIsBaselineLayout(node)) &&
2669+
if (performLayout && (lineCount > 1 || YGIsBaselineLayout(node)) &&
26712670
!YGFloatIsUndefined(availableInnerCrossDim)) {
26722671
const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim;
26732672

0 commit comments

Comments
 (0)