Fix case where absolute nodes would sometimes not be cloned (#1675)
Summary: X-link: https://github.com/facebook/react-native/pull/45240 Pull Request resolved: https://github.com/facebook/yoga/pull/1675 There was a bug where some crash would happen if a tree was cloned that had static/absolute parent/child pair inside it. This was because we were no longer calling `cloneChildrenIfNeeded` on the static parent, but would still layout the absolute child. So that child's owner would be stale and have new layout. In React Native this would lead to a failed assert which causes the crash. The fix here is to clone the children of static nodes during `layoutAbsoluteDescendants` so that we guarantee the node is either cloned if it is going to have new layout. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D59175629 fbshipit-source-id: 4d110a08ba5368704327d5ab69a8695b28e746f4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b9e335ebfd
commit
a1e9abb9b3
@@ -207,3 +207,43 @@ TEST(YogaTest, relayout_containing_block_size_changes) {
|
||||
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
TEST(YogaTest, has_new_layout_flag_set_static) {
|
||||
YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
YGNodeRef root_child0 = YGNodeNew();
|
||||
YGNodeStyleSetPositionType(root_child0, YGPositionTypeStatic);
|
||||
YGNodeStyleSetWidth(root_child0, 10);
|
||||
YGNodeStyleSetHeight(root_child0, 10);
|
||||
YGNodeInsertChild(root, root_child0, 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);
|
||||
|
||||
YGNodeRef root_child0_child0_child0 = YGNodeNew();
|
||||
YGNodeStyleSetPositionType(root_child0_child0_child0, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetWidthPercent(root_child0_child0_child0, 1);
|
||||
YGNodeStyleSetHeight(root_child0_child0_child0, 1);
|
||||
YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0);
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
YGNodeSetHasNewLayout(root, false);
|
||||
YGNodeSetHasNewLayout(root_child0, false);
|
||||
YGNodeSetHasNewLayout(root_child0_child0, false);
|
||||
YGNodeSetHasNewLayout(root_child0_child0_child0, false);
|
||||
|
||||
YGNodeStyleSetWidth(root, 110);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_TRUE(YGNodeGetHasNewLayout(root));
|
||||
ASSERT_TRUE(YGNodeGetHasNewLayout(root_child0));
|
||||
ASSERT_TRUE(YGNodeGetHasNewLayout(root_child0_child0));
|
||||
ASSERT_TRUE(YGNodeGetHasNewLayout(root_child0_child0_child0));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
Reference in New Issue
Block a user