From ae8ede9b53cfc0ab123119ac66b4069c987e7566 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Thu, 8 Aug 2024 22:41:29 -0700 Subject: [PATCH] Fix crash when you layout multiple absolute nodes in the same static subtree (#1686) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: X-link: https://github.com/facebook/react-native/pull/45952 Pull Request resolved: https://github.com/facebook/yoga/pull/1686 https://en.wikipedia.org/wiki/Short-circuit_evaluation 🫠 Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D60997231 fbshipit-source-id: 11d70086eecfb5481c578477f288138370016a83 --- gentest/fixtures/YGStaticPositionTest.html | 17 ++ .../facebook/yoga/YGStaticPositionTest.java | 140 ++++++++++++++++- .../generated/YGStaticPositionTest.test.ts | 145 +++++++++++++++++- tests/YGRelayoutTest.cpp | 8 +- tests/generated/YGStaticPositionTest.cpp | 141 ++++++++++++++++- yoga/algorithm/AbsoluteLayout.cpp | 6 +- 6 files changed, 450 insertions(+), 7 deletions(-) diff --git a/gentest/fixtures/YGStaticPositionTest.html b/gentest/fixtures/YGStaticPositionTest.html index 7d093f5e0e..41887bf6c8 100644 --- a/gentest/fixtures/YGStaticPositionTest.html +++ b/gentest/fixtures/YGStaticPositionTest.html @@ -693,3 +693,20 @@ style="height: 50%; width: 50%; position: absolute; border-width: 3px 2px 1px 4px; padding: 7px 5px 4px 3px; margin: 11px 15px 1px 12px"> + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/tests/generated/com/facebook/yoga/YGStaticPositionTest.java b/java/tests/generated/com/facebook/yoga/YGStaticPositionTest.java index 32befb3702..fecb5c0130 100644 --- a/java/tests/generated/com/facebook/yoga/YGStaticPositionTest.java +++ b/java/tests/generated/com/facebook/yoga/YGStaticPositionTest.java @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<997d12880828a3c2881898b769618b43>> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGStaticPositionTest.html */ @@ -5887,6 +5887,144 @@ public void test_static_position_static_root() { assertEquals(100f, root_child0.getLayoutHeight(), 0.0f); } + @Test + public void test_static_position_absolute_child_multiple() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setPositionType(YogaPositionType.ABSOLUTE); + + final YogaNode root_child0 = createNode(config); + root_child0.setPadding(YogaEdge.LEFT, 100); + root_child0.setPadding(YogaEdge.TOP, 100); + root_child0.setPadding(YogaEdge.RIGHT, 100); + root_child0.setPadding(YogaEdge.BOTTOM, 100); + root_child0.setWidth(400f); + root_child0.setHeight(400f); + root.addChildAt(root_child0, 0); + + final YogaNode root_child0_child0 = createNode(config); + root_child0_child0.setPositionType(YogaPositionType.STATIC); + root_child0_child0.setWidth(100f); + root_child0_child0.setHeight(100f); + root_child0.addChildAt(root_child0_child0, 0); + + final YogaNode root_child0_child0_child0 = createNode(config); + root_child0_child0_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0_child0_child0.setWidthPercent(10f); + root_child0_child0_child0.setHeight(50f); + root_child0_child0.addChildAt(root_child0_child0_child0, 0); + + final YogaNode root_child0_child1 = createNode(config); + root_child0_child1.setPositionType(YogaPositionType.STATIC); + root_child0_child1.setWidth(100f); + root_child0_child1.setHeight(100f); + root_child0.addChildAt(root_child0_child1, 1); + + final YogaNode root_child0_child1_child0 = createNode(config); + root_child0_child1_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0_child1_child0.setWidthPercent(50f); + root_child0_child1_child0.setHeight(50f); + root_child0_child1.addChildAt(root_child0_child1_child0, 0); + + final YogaNode root_child0_child1_child1 = createNode(config); + root_child0_child1_child1.setPositionType(YogaPositionType.ABSOLUTE); + root_child0_child1_child1.setWidthPercent(50f); + root_child0_child1_child1.setHeight(50f); + root_child0_child1.addChildAt(root_child0_child1_child1, 1); + + final YogaNode root_child0_child2 = createNode(config); + root_child0_child2.setPositionType(YogaPositionType.ABSOLUTE); + root_child0_child2.setWidth(25f); + root_child0_child2.setHeight(50f); + root_child0.addChildAt(root_child0_child2, 2); + root.setDirection(YogaDirection.LTR); + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + + assertEquals(0f, root.getLayoutX(), 0.0f); + assertEquals(0f, root.getLayoutY(), 0.0f); + assertEquals(400f, root.getLayoutWidth(), 0.0f); + assertEquals(400f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(400f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(400f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, 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(40f, root_child0_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0_child1.getLayoutX(), 0.0f); + assertEquals(200f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0_child1.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child1_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child1_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0_child1_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child1_child0.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0_child1_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child1_child1.getLayoutY(), 0.0f); + assertEquals(200f, root_child0_child1_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child1_child1.getLayoutHeight(), 0.0f); + + assertEquals(100f, root_child0_child2.getLayoutX(), 0.0f); + assertEquals(100f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(25f, root_child0_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child2.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(400f, root.getLayoutWidth(), 0.0f); + assertEquals(400f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(400f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(400f, root_child0.getLayoutHeight(), 0.0f); + + assertEquals(200f, root_child0_child0.getLayoutX(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(60f, root_child0_child0_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f); + assertEquals(40f, root_child0_child0_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child0_child0.getLayoutHeight(), 0.0f); + + assertEquals(200f, root_child0_child1.getLayoutX(), 0.0f); + assertEquals(200f, root_child0_child1.getLayoutY(), 0.0f); + assertEquals(100f, root_child0_child1.getLayoutWidth(), 0.0f); + assertEquals(100f, root_child0_child1.getLayoutHeight(), 0.0f); + + assertEquals(-100f, root_child0_child1_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child1_child0.getLayoutY(), 0.0f); + assertEquals(200f, root_child0_child1_child0.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child1_child0.getLayoutHeight(), 0.0f); + + assertEquals(-100f, root_child0_child1_child1.getLayoutX(), 0.0f); + assertEquals(0f, root_child0_child1_child1.getLayoutY(), 0.0f); + assertEquals(200f, root_child0_child1_child1.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child1_child1.getLayoutHeight(), 0.0f); + + assertEquals(275f, root_child0_child2.getLayoutX(), 0.0f); + assertEquals(100f, root_child0_child2.getLayoutY(), 0.0f); + assertEquals(25f, root_child0_child2.getLayoutWidth(), 0.0f); + assertEquals(50f, root_child0_child2.getLayoutHeight(), 0.0f); + } + private YogaNode createNode(YogaConfig config) { return mNodeFactory.create(config); } diff --git a/javascript/tests/generated/YGStaticPositionTest.test.ts b/javascript/tests/generated/YGStaticPositionTest.test.ts index 1a688d7993..3c1e48512a 100644 --- a/javascript/tests/generated/YGStaticPositionTest.test.ts +++ b/javascript/tests/generated/YGStaticPositionTest.test.ts @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGStaticPositionTest.html */ @@ -6192,3 +6192,146 @@ test('static_position_static_root', () => { config.free(); } }); +test('static_position_absolute_child_multiple', () => { + const config = Yoga.Config.create(); + let root; + + try { + root = Yoga.Node.create(config); + root.setPositionType(PositionType.Absolute); + + const root_child0 = Yoga.Node.create(config); + root_child0.setPadding(Edge.Left, 100); + root_child0.setPadding(Edge.Top, 100); + root_child0.setPadding(Edge.Right, 100); + root_child0.setPadding(Edge.Bottom, 100); + root_child0.setWidth(400); + root_child0.setHeight(400); + root.insertChild(root_child0, 0); + + const root_child0_child0 = Yoga.Node.create(config); + root_child0_child0.setPositionType(PositionType.Static); + root_child0_child0.setWidth(100); + root_child0_child0.setHeight(100); + root_child0.insertChild(root_child0_child0, 0); + + const root_child0_child0_child0 = Yoga.Node.create(config); + root_child0_child0_child0.setPositionType(PositionType.Absolute); + root_child0_child0_child0.setWidth("10%"); + root_child0_child0_child0.setHeight(50); + root_child0_child0.insertChild(root_child0_child0_child0, 0); + + const root_child0_child1 = Yoga.Node.create(config); + root_child0_child1.setPositionType(PositionType.Static); + root_child0_child1.setWidth(100); + root_child0_child1.setHeight(100); + root_child0.insertChild(root_child0_child1, 1); + + const root_child0_child1_child0 = Yoga.Node.create(config); + root_child0_child1_child0.setPositionType(PositionType.Absolute); + root_child0_child1_child0.setWidth("50%"); + root_child0_child1_child0.setHeight(50); + root_child0_child1.insertChild(root_child0_child1_child0, 0); + + const root_child0_child1_child1 = Yoga.Node.create(config); + root_child0_child1_child1.setPositionType(PositionType.Absolute); + root_child0_child1_child1.setWidth("50%"); + root_child0_child1_child1.setHeight(50); + root_child0_child1.insertChild(root_child0_child1_child1, 1); + + const root_child0_child2 = Yoga.Node.create(config); + root_child0_child2.setPositionType(PositionType.Absolute); + root_child0_child2.setWidth(25); + root_child0_child2.setHeight(50); + root_child0.insertChild(root_child0_child2, 2); + root.calculateLayout(undefined, undefined, Direction.LTR); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(400); + expect(root.getComputedHeight()).toBe(400); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(400); + expect(root_child0.getComputedHeight()).toBe(400); + + expect(root_child0_child0.getComputedLeft()).toBe(100); + expect(root_child0_child0.getComputedTop()).toBe(100); + expect(root_child0_child0.getComputedWidth()).toBe(100); + expect(root_child0_child0.getComputedHeight()).toBe(100); + + expect(root_child0_child0_child0.getComputedLeft()).toBe(0); + expect(root_child0_child0_child0.getComputedTop()).toBe(0); + expect(root_child0_child0_child0.getComputedWidth()).toBe(40); + expect(root_child0_child0_child0.getComputedHeight()).toBe(50); + + expect(root_child0_child1.getComputedLeft()).toBe(100); + expect(root_child0_child1.getComputedTop()).toBe(200); + expect(root_child0_child1.getComputedWidth()).toBe(100); + expect(root_child0_child1.getComputedHeight()).toBe(100); + + expect(root_child0_child1_child0.getComputedLeft()).toBe(0); + expect(root_child0_child1_child0.getComputedTop()).toBe(0); + expect(root_child0_child1_child0.getComputedWidth()).toBe(200); + expect(root_child0_child1_child0.getComputedHeight()).toBe(50); + + expect(root_child0_child1_child1.getComputedLeft()).toBe(0); + expect(root_child0_child1_child1.getComputedTop()).toBe(0); + expect(root_child0_child1_child1.getComputedWidth()).toBe(200); + expect(root_child0_child1_child1.getComputedHeight()).toBe(50); + + expect(root_child0_child2.getComputedLeft()).toBe(100); + expect(root_child0_child2.getComputedTop()).toBe(100); + expect(root_child0_child2.getComputedWidth()).toBe(25); + expect(root_child0_child2.getComputedHeight()).toBe(50); + + root.calculateLayout(undefined, undefined, Direction.RTL); + + expect(root.getComputedLeft()).toBe(0); + expect(root.getComputedTop()).toBe(0); + expect(root.getComputedWidth()).toBe(400); + expect(root.getComputedHeight()).toBe(400); + + expect(root_child0.getComputedLeft()).toBe(0); + expect(root_child0.getComputedTop()).toBe(0); + expect(root_child0.getComputedWidth()).toBe(400); + expect(root_child0.getComputedHeight()).toBe(400); + + expect(root_child0_child0.getComputedLeft()).toBe(200); + expect(root_child0_child0.getComputedTop()).toBe(100); + expect(root_child0_child0.getComputedWidth()).toBe(100); + expect(root_child0_child0.getComputedHeight()).toBe(100); + + expect(root_child0_child0_child0.getComputedLeft()).toBe(60); + expect(root_child0_child0_child0.getComputedTop()).toBe(0); + expect(root_child0_child0_child0.getComputedWidth()).toBe(40); + expect(root_child0_child0_child0.getComputedHeight()).toBe(50); + + expect(root_child0_child1.getComputedLeft()).toBe(200); + expect(root_child0_child1.getComputedTop()).toBe(200); + expect(root_child0_child1.getComputedWidth()).toBe(100); + expect(root_child0_child1.getComputedHeight()).toBe(100); + + expect(root_child0_child1_child0.getComputedLeft()).toBe(-100); + expect(root_child0_child1_child0.getComputedTop()).toBe(0); + expect(root_child0_child1_child0.getComputedWidth()).toBe(200); + expect(root_child0_child1_child0.getComputedHeight()).toBe(50); + + expect(root_child0_child1_child1.getComputedLeft()).toBe(-100); + expect(root_child0_child1_child1.getComputedTop()).toBe(0); + expect(root_child0_child1_child1.getComputedWidth()).toBe(200); + expect(root_child0_child1_child1.getComputedHeight()).toBe(50); + + expect(root_child0_child2.getComputedLeft()).toBe(275); + expect(root_child0_child2.getComputedTop()).toBe(100); + expect(root_child0_child2.getComputedWidth()).toBe(25); + expect(root_child0_child2.getComputedHeight()).toBe(50); + } finally { + if (typeof root !== 'undefined') { + root.freeRecursive(); + } + + config.free(); + } +}); diff --git a/tests/YGRelayoutTest.cpp b/tests/YGRelayoutTest.cpp index b470fc3656..c4c0adde23 100644 --- a/tests/YGRelayoutTest.cpp +++ b/tests/YGRelayoutTest.cpp @@ -219,11 +219,17 @@ TEST(YogaTest, has_new_layout_flag_set_static) { YGNodeStyleSetHeight(root_child0, 10); YGNodeInsertChild(root, root_child0, 0); + YGNodeRef root_child0_child1 = YGNodeNew(); + YGNodeStyleSetPositionType(root_child0_child1, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root_child0_child1, 5); + YGNodeStyleSetHeight(root_child0_child1, 5); + YGNodeInsertChild(root_child0, root_child0_child1, 0); + YGNodeRef root_child0_child0 = YGNodeNew(); YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeStatic); YGNodeStyleSetWidth(root_child0_child0, 5); YGNodeStyleSetHeight(root_child0_child0, 5); - YGNodeInsertChild(root_child0, root_child0_child0, 0); + YGNodeInsertChild(root_child0, root_child0_child0, 1); YGNodeRef root_child0_child0_child0 = YGNodeNew(); YGNodeStyleSetPositionType(root_child0_child0_child0, YGPositionTypeAbsolute); diff --git a/tests/generated/YGStaticPositionTest.cpp b/tests/generated/YGStaticPositionTest.cpp index edb544fd7a..d689f83fd8 100644 --- a/tests/generated/YGStaticPositionTest.cpp +++ b/tests/generated/YGStaticPositionTest.cpp @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * clang-format off - * @generated SignedSource<<03c511300b41c81c3592dd5df34bc2b9>> + * @generated SignedSource<<83ad08d246e0d406b525b1b1d5290b35>> * generated by gentest/gentest-driver.ts from gentest/fixtures/YGStaticPositionTest.html */ @@ -5933,3 +5933,142 @@ TEST(YogaTest, static_position_static_root) { YGConfigFree(config); } + +TEST(YogaTest, static_position_absolute_child_multiple) { + YGConfigRef config = YGConfigNew(); + + YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute); + + YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 100); + YGNodeStyleSetPadding(root_child0, YGEdgeTop, 100); + YGNodeStyleSetPadding(root_child0, YGEdgeRight, 100); + YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 100); + YGNodeStyleSetWidth(root_child0, 400); + YGNodeStyleSetHeight(root_child0, 400); + YGNodeInsertChild(root, root_child0, 0); + + YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0_child0, YGPositionTypeStatic); + YGNodeStyleSetWidth(root_child0_child0, 100); + YGNodeStyleSetHeight(root_child0_child0, 100); + YGNodeInsertChild(root_child0, root_child0_child0, 0); + + YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0_child0_child0, YGPositionTypeAbsolute); + YGNodeStyleSetWidthPercent(root_child0_child0_child0, 10); + YGNodeStyleSetHeight(root_child0_child0_child0, 50); + YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0); + + YGNodeRef root_child0_child1 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0_child1, YGPositionTypeStatic); + YGNodeStyleSetWidth(root_child0_child1, 100); + YGNodeStyleSetHeight(root_child0_child1, 100); + YGNodeInsertChild(root_child0, root_child0_child1, 1); + + YGNodeRef root_child0_child1_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0_child1_child0, YGPositionTypeAbsolute); + YGNodeStyleSetWidthPercent(root_child0_child1_child0, 50); + YGNodeStyleSetHeight(root_child0_child1_child0, 50); + YGNodeInsertChild(root_child0_child1, root_child0_child1_child0, 0); + + YGNodeRef root_child0_child1_child1 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0_child1_child1, YGPositionTypeAbsolute); + YGNodeStyleSetWidthPercent(root_child0_child1_child1, 50); + YGNodeStyleSetHeight(root_child0_child1_child1, 50); + YGNodeInsertChild(root_child0_child1, root_child0_child1_child1, 1); + + YGNodeRef root_child0_child2 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0_child2, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root_child0_child2, 25); + YGNodeStyleSetHeight(root_child0_child2, 50); + YGNodeInsertChild(root_child0, root_child0_child2, 2); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(400, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(400, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(100, 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(40, YGNodeLayoutGetWidth(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0_child0)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0_child1)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child0_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child1)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child0)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child1_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child1_child0)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child1_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child1)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child1_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child1_child1)); + + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0_child2)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child2)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(400, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(400, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetLeft(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0)); + + ASSERT_FLOAT_EQ(60, YGNodeLayoutGetLeft(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(40, YGNodeLayoutGetWidth(root_child0_child0_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child0_child0)); + + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetLeft(root_child0_child1)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetTop(root_child0_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child1)); + + ASSERT_FLOAT_EQ(-100, YGNodeLayoutGetLeft(root_child0_child1_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child0)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child1_child0)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child1_child0)); + + ASSERT_FLOAT_EQ(-100, YGNodeLayoutGetLeft(root_child0_child1_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child1_child1)); + ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root_child0_child1_child1)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child1_child1)); + + ASSERT_FLOAT_EQ(275, YGNodeLayoutGetLeft(root_child0_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0_child2)); + ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0_child2)); + ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0_child2)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/yoga/algorithm/AbsoluteLayout.cpp b/yoga/algorithm/AbsoluteLayout.cpp index d68b4fa91c..26603554ef 100644 --- a/yoga/algorithm/AbsoluteLayout.cpp +++ b/yoga/algorithm/AbsoluteLayout.cpp @@ -592,8 +592,7 @@ bool layoutAbsoluteDescendants( currentNodeTopOffsetFromContainingBlock + child->getLayout().position(PhysicalEdge::Top); - hasNewLayout = hasNewLayout || - layoutAbsoluteDescendants( + hasNewLayout = layoutAbsoluteDescendants( containingNode, child, widthSizingMode, @@ -604,7 +603,8 @@ bool layoutAbsoluteDescendants( childLeftOffsetFromContainingBlock, childTopOffsetFromContainingBlock, containingNodeAvailableInnerWidth, - containingNodeAvailableInnerHeight); + containingNodeAvailableInnerHeight) || + hasNewLayout; if (hasNewLayout) { child->setHasNewLayout(hasNewLayout);