Fix crash when you layout multiple absolute nodes in the same static subtree (#1686)
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5009f5c1ac
commit
ae8ede9b53
@@ -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<<fd288594fce8fa8e2399df5f5d303440>>
|
||||
* @generated SignedSource<<ce99ac91b3467951bb539796415198ee>>
|
||||
* 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();
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user