Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where leaf nodes do not bound innerWidth/Height before measure #1765

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
9 changes: 8 additions & 1 deletion gentest/fixtures/YGMinMaxDimensionTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
<div style="height: 50px;"></div>
</div>

<div id="flex_grow_in_at_most_container" style="width: 100px; height: 100px; background-color: white; flex-direction: row; align-items: flex-start;">
<div id="flex_grow_in_at_most_container"
style="width: 100px; height: 100px; background-color: white; flex-direction: row; align-items: flex-start;">
<div style="flex-direction: row;">
<div style="flex-grow: 1; flex-basis: 0px;"></div>
</div>
Expand Down Expand Up @@ -126,3 +127,9 @@
<div style="min-width: 10%; max-width: 10%; min-height: 10%; max-height: 10%;">
</div>
</div>

<div id="min_width_leaf_node_bigger_than_width" style="width: 200px;">
<div style="min-width: 10000px; width: 200px">
Lorem ipsum sdafhasdfkjlasdhlkajsfhasldkfhasdlkahsdflkjasdhflaksdfasdlkjhasdlfjahsdfljkasdhalsdfhas dolor sit amet
</div>
</div>
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<<19cdc4fc9425af726b656ef628bab8af>>
* @generated SignedSource<<399bb599fce869e5c09ea1d193c1e486>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGMinMaxDimensionTest.html
*/

Expand Down Expand Up @@ -1315,6 +1315,47 @@ public void test_min_max_percent_no_width_height() {
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
}

@Test
public void test_min_width_leaf_node_bigger_than_width() {
YogaConfig config = YogaConfigFactory.create();

final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(200f);

final YogaNode root_child0 = createNode(config);
root_child0.setWidth(200f);
root_child0.setMinWidth(10000f);
root.addChildAt(root_child0, 0);
root_child0.setData("Lorem ipsum sdafhasdfkjlasdhlkajsfhasldkfhasdlkahsdflkjasdhflaksdfasdlkjhasdlfjahsdfljkasdhalsdfhas dolor sit amet");
root_child0.setMeasureFunction(new TestUtils.intrinsicMeasureFunction());
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);

assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(200f, root.getLayoutWidth(), 0.0f);
assertEquals(10f, root.getLayoutHeight(), 0.0f);

assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(10000f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_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(200f, root.getLayoutWidth(), 0.0f);
assertEquals(10f, root.getLayoutHeight(), 0.0f);

assertEquals(-9800f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(10000f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
}

private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}
Expand Down
47 changes: 46 additions & 1 deletion javascript/tests/generated/YGMinMaxDimensionTest.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<<1bd782301afbab34ed3c9a296c3ecaa6>>
* @generated SignedSource<<d9428d2e524c7d665f61ccdad7697504>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGMinMaxDimensionTest.html
*/

Expand Down Expand Up @@ -1444,3 +1444,48 @@ test('min_max_percent_no_width_height', () => {
config.free();
}
});
test('min_width_leaf_node_bigger_than_width', () => {
const config = Yoga.Config.create();
let root;

try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
root.setWidth(200);

const root_child0 = Yoga.Node.create(config);
root_child0.setWidth(200);
root_child0.setMinWidth(10000);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum sdafhasdfkjlasdhlkajsfhasldkfhasdlkahsdflkjasdhflaksdfasdlkjhasdlfjahsdfljkasdhalsdfhas dolor sit amet"));
root.calculateLayout(undefined, undefined, Direction.LTR);

expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(200);
expect(root.getComputedHeight()).toBe(10);

expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(10000);
expect(root_child0.getComputedHeight()).toBe(10);

root.calculateLayout(undefined, undefined, Direction.RTL);

expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(200);
expect(root.getComputedHeight()).toBe(10);

expect(root_child0.getComputedLeft()).toBe(-9800);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(10000);
expect(root_child0.getComputedHeight()).toBe(10);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}

config.free();
}
});
44 changes: 43 additions & 1 deletion tests/generated/YGMinMaxDimensionTest.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<<0054f2d41727e7a0707701c6d7640cb6>>
* @generated SignedSource<<e8764dca183ff6afce78e27bb6ca1edf>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGMinMaxDimensionTest.html
*/

Expand Down Expand Up @@ -1328,3 +1328,45 @@ TEST(YogaTest, min_max_percent_no_width_height) {

YGConfigFree(config);
}

TEST(YogaTest, min_width_leaf_node_bigger_than_width) {
YGConfigRef config = YGConfigNew();

YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(root, 200);

YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0, 200);
YGNodeStyleSetMinWidth(root_child0, 10000);
YGNodeInsertChild(root, root_child0, 0);
YGNodeSetContext(root_child0, (void*)"Lorem ipsum sdafhasdfkjlasdhlkajsfhasldkfhasdlkahsdflkjasdhflaksdfasdlkjhasdlfjahsdfljkasdhalsdfhas dolor sit amet");
YGNodeSetMeasureFunc(root_child0, &facebook::yoga::test::IntrinsicSizeMeasure);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root));

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(10000, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);

ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root));

ASSERT_FLOAT_EQ(-9800, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(10000, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));

YGNodeFreeRecursive(root);

YGConfigFree(config);
}
18 changes: 16 additions & 2 deletions yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,23 @@ static void measureNodeWithMeasureFunc(

// Measure the text under the current constraints.
const YGSize measuredSize = node->measure(
innerWidth,
isUndefined(innerWidth) ? innerWidth
: boundAxis(
node,
FlexDirection::Row,
direction,
innerWidth,
ownerWidth,
ownerWidth),
measureMode(widthSizingMode),
innerHeight,
isUndefined(innerHeight) ? innerHeight
: boundAxis(
node,
FlexDirection::Column,
direction,
innerHeight,
ownerHeight,
ownerWidth),
measureMode(heightSizingMode));

layoutMarkerData.measureCallbacks += 1;
Expand Down
Loading