Skip to content
Open
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
8 changes: 8 additions & 0 deletions gentest/fixtures/YGAlignItemsTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
</div>
</div>

<div id="align_baseline_parent_child" style="flex-direction: column;">
<div style="width: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 50px;">
<div style="width: 50px; height: 10px;"></div>
</div>
</div>
</div>

<div id="align_baseline_child_multiline"
style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 60px;"></div>
Expand Down
71 changes: 70 additions & 1 deletion java/tests/generated/com/facebook/yoga/YGAlignItemsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down Expand Up @@ -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();
Expand Down
67 changes: 66 additions & 1 deletion javascript/tests/generated/YGAlignItemsTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down Expand Up @@ -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();

Expand Down
72 changes: 71 additions & 1 deletion tests/generated/YGAlignItemsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* clang-format off
* @generated SignedSource<<40cc61a8728b4532578e77a95e67d785>>
* @generated SignedSource<<f6ad2d7a7d8e75a77f478994319a1ccc>>
* generated by gentest/src/GentestDriver.ts from gentest/fixtures/YGAlignItemsTest.html
*/

Expand Down Expand Up @@ -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();

Expand Down
9 changes: 9 additions & 0 deletions yoga/algorithm/Baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down