From 3a0a86788e9b0b8daa5de91ae5ac1699e00bb9ab Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Thu, 21 Sep 2017 03:36:02 -0700 Subject: [PATCH] Revert D5874862: [yoga][PR] Fix shrinking in non strech alignments Summary: This reverts commit 1426aa6b60f6ba42c2be702e6f24cea935ab7acb bypass-lint Differential Revision: D5874862 fbshipit-source-id: 24517d26b18c11fb9f75c6d3b5faae360711ea9e --- .../tests/Facebook.Yoga/YGAlignItemsTest.cs | 69 ------------------ gentest/fixtures/YGAlignItemsTest.html | 7 -- .../com/facebook/yoga/YGAlignItemsTest.java | 68 ------------------ .../tests/Facebook.Yoga/YGAlignItemsTest.js | 72 ------------------- tests/YGAlignItemsTest.cpp | 69 ------------------ yoga/Yoga.c | 4 +- 6 files changed, 1 insertion(+), 288 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs index 9515bdff..cc3a74ab 100644 --- a/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs +++ b/csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs @@ -1958,74 +1958,5 @@ namespace Facebook.Yoga Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight); } - [Test] - public void Test_align_flex_start_with_shrinkin_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); - } - } } diff --git a/gentest/fixtures/YGAlignItemsTest.html b/gentest/fixtures/YGAlignItemsTest.html index d3605cd5..c7b3df1a 100644 --- a/gentest/fixtures/YGAlignItemsTest.html +++ b/gentest/fixtures/YGAlignItemsTest.html @@ -184,10 +184,3 @@ -
-
-
-
-
-
-
\ No newline at end of file diff --git a/java/tests/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/com/facebook/yoga/YGAlignItemsTest.java index 8a1dfecc..15d7d842 100644 --- a/java/tests/com/facebook/yoga/YGAlignItemsTest.java +++ b/java/tests/com/facebook/yoga/YGAlignItemsTest.java @@ -1932,72 +1932,4 @@ public class YGAlignItemsTest { assertEquals(20f, root_child0_child0_child0.getLayoutHeight(), 0.0f); } - @Test - public void test_align_flex_start_with_shrinkin_children() { - YogaConfig config = new YogaConfig(); - - final YogaNode root = new YogaNode(config); - root.setWidth(500f); - root.setHeight(500f); - - final YogaNode root_child0 = new YogaNode(config); - root_child0.setAlignItems(YogaAlign.FLEX_START); - root.addChildAt(root_child0, 0); - - final YogaNode root_child0_child0 = new YogaNode(config); - root_child0_child0.setFlexGrow(1f); - root_child0_child0.setFlexShrink(1f); - root_child0.addChildAt(root_child0_child0, 0); - - final YogaNode root_child0_child0_child0 = new YogaNode(config); - root_child0_child0_child0.setFlexGrow(1f); - root_child0_child0_child0.setFlexShrink(1f); - root_child0_child0.addChildAt(root_child0_child0_child0, 0); - root.setDirection(YogaDirection.LTR); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(500f, root.getLayoutWidth(), 0.0f); - assertEquals(500f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(500f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f); - assertEquals(0f, root_child0_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child0_child0_child0.getLayoutHeight(), 0.0f); - - root.setDirection(YogaDirection.RTL); - root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - - assertEquals(0f, root.getLayoutX(), 0.0f); - assertEquals(0f, root.getLayoutY(), 0.0f); - assertEquals(500f, root.getLayoutWidth(), 0.0f); - assertEquals(500f, root.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0.getLayoutY(), 0.0f); - assertEquals(500f, root_child0.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); - - assertEquals(500f, root_child0_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child0_child0.getLayoutHeight(), 0.0f); - - assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f); - assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f); - assertEquals(0f, root_child0_child0_child0.getLayoutWidth(), 0.0f); - assertEquals(0f, root_child0_child0_child0.getLayoutHeight(), 0.0f); - } - } diff --git a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js index 88fce0b9..28a9a980 100644 --- a/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js +++ b/javascript/tests/Facebook.Yoga/YGAlignItemsTest.js @@ -2027,75 +2027,3 @@ it("align_strech_should_size_based_on_parent", function () { config.free(); } }); -it("align_flex_start_with_shrinkin_children", function () { - var config = Yoga.Config.create(); - - try { - var root = Yoga.Node.create(config); - root.setWidth(500); - root.setHeight(500); - - var root_child0 = Yoga.Node.create(config); - root_child0.setAlignItems(Yoga.ALIGN_FLEX_START); - root.insertChild(root_child0, 0); - - var root_child0_child0 = Yoga.Node.create(config); - root_child0_child0.setFlexGrow(1); - root_child0_child0.setFlexShrink(1); - root_child0.insertChild(root_child0_child0, 0); - - var root_child0_child0_child0 = Yoga.Node.create(config); - root_child0_child0_child0.setFlexGrow(1); - root_child0_child0_child0.setFlexShrink(1); - root_child0_child0.insertChild(root_child0_child0_child0, 0); - root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); - - console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); - console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(500 === root.getComputedWidth(), "500 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(500 === root.getComputedHeight(), "500 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(500 === root_child0.getComputedWidth(), "500 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); - console.assert(0 === root_child0_child0.getComputedWidth(), "0 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); - console.assert(0 === root_child0_child0.getComputedHeight(), "0 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child0_child0_child0.getComputedLeft(), "0 === root_child0_child0_child0.getComputedLeft() (" + root_child0_child0_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0_child0_child0.getComputedTop(), "0 === root_child0_child0_child0.getComputedTop() (" + root_child0_child0_child0.getComputedTop() + ")"); - console.assert(0 === root_child0_child0_child0.getComputedWidth(), "0 === root_child0_child0_child0.getComputedWidth() (" + root_child0_child0_child0.getComputedWidth() + ")"); - console.assert(0 === root_child0_child0_child0.getComputedHeight(), "0 === root_child0_child0_child0.getComputedHeight() (" + root_child0_child0_child0.getComputedHeight() + ")"); - - root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); - - console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); - console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); - console.assert(500 === root.getComputedWidth(), "500 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); - console.assert(500 === root.getComputedHeight(), "500 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); - - console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); - console.assert(500 === root_child0.getComputedWidth(), "500 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); - console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); - - console.assert(500 === root_child0_child0.getComputedLeft(), "500 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")"); - console.assert(0 === root_child0_child0.getComputedWidth(), "0 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")"); - console.assert(0 === root_child0_child0.getComputedHeight(), "0 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")"); - - console.assert(0 === root_child0_child0_child0.getComputedLeft(), "0 === root_child0_child0_child0.getComputedLeft() (" + root_child0_child0_child0.getComputedLeft() + ")"); - console.assert(0 === root_child0_child0_child0.getComputedTop(), "0 === root_child0_child0_child0.getComputedTop() (" + root_child0_child0_child0.getComputedTop() + ")"); - console.assert(0 === root_child0_child0_child0.getComputedWidth(), "0 === root_child0_child0_child0.getComputedWidth() (" + root_child0_child0_child0.getComputedWidth() + ")"); - console.assert(0 === root_child0_child0_child0.getComputedHeight(), "0 === root_child0_child0_child0.getComputedHeight() (" + root_child0_child0_child0.getComputedHeight() + ")"); - } finally { - if (typeof root !== "undefined") { - root.freeRecursive(); - } - - config.free(); - } -}); diff --git a/tests/YGAlignItemsTest.cpp b/tests/YGAlignItemsTest.cpp index 3bdc8442..33eaab9c 100644 --- a/tests/YGAlignItemsTest.cpp +++ b/tests/YGAlignItemsTest.cpp @@ -1952,72 +1952,3 @@ TEST(YogaTest, align_strech_should_size_based_on_parent) { YGConfigFree(config); } - -TEST(YogaTest, align_flex_start_with_shrinkin_children) { - const YGConfigRef config = YGConfigNew(); - - const YGNodeRef root = YGNodeNewWithConfig(config); - YGNodeStyleSetWidth(root, 500); - YGNodeStyleSetHeight(root, 500); - - const YGNodeRef root_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetAlignItems(root_child0, YGAlignFlexStart); - YGNodeInsertChild(root, root_child0, 0); - - const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0, 1); - YGNodeInsertChild(root_child0, root_child0_child0, 0); - - const YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); - YGNodeStyleSetFlexGrow(root_child0_child0_child0, 1); - YGNodeStyleSetFlexShrink(root_child0_child0_child0, 1); - YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); - - ASSERT_FLOAT_EQ(500, YGNodeLayoutGetLeft(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0)); - - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0)); - ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0_child0_child0)); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 26489faa..84aa5a75 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -2308,7 +2308,6 @@ static void YGNodelayoutImpl(const YGNodeRef node, // If the main dimension size isn't known, it is computed based on // the line length, so there's no more space left to distribute. - bool sizeBasedOnContent = false; // If we don't measure with exact main dimension we want to ensure we don't violate min and max if (measureModeMainDim != YGMeasureModeExactly) { if (!YGFloatIsUndefined(minInnerMainDim) && sizeConsumedOnCurrentLine < minInnerMainDim) { @@ -2323,12 +2322,11 @@ static void YGNodelayoutImpl(const YGNodeRef node, // space we've used is all space we need. Root node also should be shrunk to minimum availableInnerMainDim = sizeConsumedOnCurrentLine; } - sizeBasedOnContent = true; } } float remainingFreeSpace = 0; - if (!sizeBasedOnContent && !YGFloatIsUndefined(availableInnerMainDim)) { + if (!YGFloatIsUndefined(availableInnerMainDim)) { remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine; } else if (sizeConsumedOnCurrentLine < 0) { // availableInnerMainDim is indefinite which means the node is being sized based on its