diff --git a/gentest/fixtures/YGAlignItemsTest.html b/gentest/fixtures/YGAlignItemsTest.html
index 6b50772a80..157d95e8d1 100644
--- a/gentest/fixtures/YGAlignItemsTest.html
+++ b/gentest/fixtures/YGAlignItemsTest.html
@@ -26,6 +26,14 @@
+
diff --git a/java/tests/generated/com/facebook/yoga/YGAlignItemsTest.java b/java/tests/generated/com/facebook/yoga/YGAlignItemsTest.java
index 0c5449cdde..feb94f0dec 100644
--- a/java/tests/generated/com/facebook/yoga/YGAlignItemsTest.java
+++ b/java/tests/generated/com/facebook/yoga/YGAlignItemsTest.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<<309d24a29d92477022ee155afc4ade82>>
+ * @generated SignedSource<<23e73bf55eb3aab67d7036acb0c9e2e7>>
* generated by gentest/src/GentestDriver.ts from gentest/fixtures/YGAlignItemsTest.html
*/
@@ -318,6 +318,75 @@ public void test_align_baseline_child() {
assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
}
+ @Test
+ public void test_align_baseline_parent_child() {
+ YogaConfig config = YogaConfigFactory.create();
+
+ final YogaNode root = createNode(config);
+ root.setPositionType(YogaPositionType.ABSOLUTE);
+
+ final YogaNode root_child0 = createNode(config);
+ root_child0.setWidth(100f);
+ root_child0.setFlexDirection(YogaFlexDirection.ROW);
+ root_child0.setAlignItems(YogaAlign.BASELINE);
+ root.addChildAt(root_child0, 0);
+
+ final YogaNode root_child0_child0 = createNode(config);
+ root_child0_child0.setWidth(50f);
+ root_child0_child0.setHeight(50f);
+ root_child0.addChildAt(root_child0_child0, 0);
+
+ final YogaNode root_child0_child0_child0 = createNode(config);
+ root_child0_child0_child0.setWidth(50f);
+ root_child0_child0_child0.setHeight(10f);
+ 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(100f, root.getLayoutWidth(), 0.0f);
+ assertEquals(50f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(50f, 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(50f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, 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(100f, root.getLayoutWidth(), 0.0f);
+ assertEquals(50f, root.getLayoutHeight(), 0.0f);
+
+ assertEquals(0f, root_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0.getLayoutY(), 0.0f);
+ assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
+ assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
+
+ assertEquals(50f, root_child0_child0.getLayoutX(), 0.0f);
+ assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
+ assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(50f, 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(50f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
+ assertEquals(10f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
+ }
+
@Test
public void test_align_baseline_child_multiline() {
YogaConfig config = YogaConfigFactory.create();
diff --git a/javascript/tests/generated/YGAlignItemsTest.test.ts b/javascript/tests/generated/YGAlignItemsTest.test.ts
index 426f19036b..dd2e0f724d 100644
--- a/javascript/tests/generated/YGAlignItemsTest.test.ts
+++ b/javascript/tests/generated/YGAlignItemsTest.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<<376f04b67eef25ff67e586d26bfb7ef6>>
+ * @generated SignedSource<<92bbf7d2be24ece27e81b721827c39c9>>
* generated by gentest/src/GentestDriver.ts from gentest/fixtures/YGAlignItemsTest.html
*/
@@ -295,6 +295,71 @@ test('align_baseline_child', () => {
expect(root_child1_child0.getComputedWidth()).toBe(50);
expect(root_child1_child0.getComputedHeight()).toBe(10);
});
+test('align_baseline_parent_child', () => {
+ const config = Yoga.Config.create();
+
+ const root = Yoga.Node.create(config);
+ root.setPositionType(PositionType.Absolute);
+
+ const root_child0 = Yoga.Node.create(config);
+ root_child0.setWidth(100);
+ root_child0.setFlexDirection(FlexDirection.Row);
+ root_child0.setAlignItems(Align.Baseline);
+ root.insertChild(root_child0, 0);
+
+ const root_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0.setWidth(50);
+ root_child0_child0.setHeight(50);
+ root_child0.insertChild(root_child0_child0, 0);
+
+ const root_child0_child0_child0 = Yoga.Node.create(config);
+ root_child0_child0_child0.setWidth(50);
+ root_child0_child0_child0.setHeight(10);
+ root_child0_child0.insertChild(root_child0_child0_child0, 0);
+ root.calculateLayout(undefined, undefined, Direction.LTR);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(100);
+ expect(root.getComputedHeight()).toBe(50);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(100);
+ expect(root_child0.getComputedHeight()).toBe(50);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(50);
+
+ expect(root_child0_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0_child0.getComputedHeight()).toBe(10);
+
+ root.calculateLayout(undefined, undefined, Direction.RTL);
+
+ expect(root.getComputedLeft()).toBe(0);
+ expect(root.getComputedTop()).toBe(0);
+ expect(root.getComputedWidth()).toBe(100);
+ expect(root.getComputedHeight()).toBe(50);
+
+ expect(root_child0.getComputedLeft()).toBe(0);
+ expect(root_child0.getComputedTop()).toBe(0);
+ expect(root_child0.getComputedWidth()).toBe(100);
+ expect(root_child0.getComputedHeight()).toBe(50);
+
+ expect(root_child0_child0.getComputedLeft()).toBe(50);
+ expect(root_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0.getComputedHeight()).toBe(50);
+
+ expect(root_child0_child0_child0.getComputedLeft()).toBe(0);
+ expect(root_child0_child0_child0.getComputedTop()).toBe(0);
+ expect(root_child0_child0_child0.getComputedWidth()).toBe(50);
+ expect(root_child0_child0_child0.getComputedHeight()).toBe(10);
+});
test('align_baseline_child_multiline', () => {
const config = Yoga.Config.create();
diff --git a/tests/generated/YGAlignItemsTest.cpp b/tests/generated/YGAlignItemsTest.cpp
index d9d16eef85..1334fbeae6 100644
--- a/tests/generated/YGAlignItemsTest.cpp
+++ b/tests/generated/YGAlignItemsTest.cpp
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* clang-format off
- * @generated SignedSource<<40cc61a8728b4532578e77a95e67d785>>
+ * @generated SignedSource<
>
* generated by gentest/src/GentestDriver.ts from gentest/fixtures/YGAlignItemsTest.html
*/
@@ -310,6 +310,76 @@ TEST(YogaTest, align_baseline_child) {
YGConfigFree(config);
}
+TEST(YogaTest, align_baseline_parent_child) {
+ YGConfigRef config = YGConfigNew();
+
+ YGNodeRef root = YGNodeNewWithConfig(config);
+ YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
+
+ YGNodeRef root_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetWidth(root_child0, 100);
+ YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
+ YGNodeStyleSetAlignItems(root_child0, YGAlignBaseline);
+ YGNodeInsertChild(root, root_child0, 0);
+
+ YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetWidth(root_child0_child0, 50);
+ YGNodeStyleSetHeight(root_child0_child0, 50);
+ YGNodeInsertChild(root_child0, root_child0_child0, 0);
+
+ YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config);
+ YGNodeStyleSetWidth(root_child0_child0_child0, 50);
+ YGNodeStyleSetHeight(root_child0_child0_child0, 10);
+ 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(100, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, 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(50, YGNodeLayoutGetWidth(root_child0_child0_child0));
+ ASSERT_FLOAT_EQ(10, 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(100, YGNodeLayoutGetWidth(root));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
+
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
+ ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
+
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0_child0));
+ ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
+ ASSERT_FLOAT_EQ(50, 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(50, YGNodeLayoutGetWidth(root_child0_child0_child0));
+ ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0));
+
+ YGNodeFreeRecursive(root);
+
+ YGConfigFree(config);
+}
+
TEST(YogaTest, align_baseline_child_multiline) {
YGConfigRef config = YGConfigNew();
diff --git a/yoga/algorithm/Baseline.cpp b/yoga/algorithm/Baseline.cpp
index b3002012bc..340c8e4acf 100644
--- a/yoga/algorithm/Baseline.cpp
+++ b/yoga/algorithm/Baseline.cpp
@@ -39,6 +39,15 @@ float calculateBaseline(const yoga::Node* node) {
if (child->style().positionType() == PositionType::Absolute) {
continue;
}
+
+ // Skip children that haven't been measured yet (#1932)
+ const float childHeight =
+ child->getLayout().measuredDimension(Dimension::Height);
+ if (yoga::isUndefined(childHeight)) {
+ // Expect baselineChild not return NaN
+ continue;
+ }
+
if (resolveChildAlignment(node, child) == Align::Baseline ||
child->isReferenceBaseline()) {
baselineChild = child;