Fix crash when a non-leaf node becomes a leaf node
Summary: When a non-leaf node becomes a leaf node, `YGAttachNodesFromViewHierachy` calls `YGNodeSetMeasureFunc` before `YGRemoveAllChildren`, which causes a crash because that node has children. Fixed by swapping the order of the calls and have a unit-test to make sure it works. Closes https://github.com/facebook/yoga/pull/320 Differential Revision: D4383905 Pulled By: dshahidehpour fbshipit-source-id: 4872b1e819f178adaaa66b1f1c233390d3ec3be9
This commit is contained in:
committed by
Facebook Github Bot
parent
bf6602ebff
commit
1877a97898
@@ -343,4 +343,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testThatANonLeafNodeCanBecomeALeafNode
|
||||
{
|
||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
||||
[container yg_setUsesYoga:YES];
|
||||
|
||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview1 yg_setUsesYoga:YES];
|
||||
[container addSubview:subview1];
|
||||
|
||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview2 yg_setUsesYoga:YES];
|
||||
[subview1 addSubview:subview2];
|
||||
|
||||
[container yg_applyLayout];
|
||||
[subview2 removeFromSuperview];
|
||||
[container yg_applyLayout];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -316,8 +316,8 @@ static void YGAttachNodesFromViewHierachy(UIView *const view)
|
||||
|
||||
// Only leaf nodes should have a measure function
|
||||
if (view.yg_isLeaf) {
|
||||
YGNodeSetMeasureFunc(node, YGMeasureView);
|
||||
YGRemoveAllChildren(node);
|
||||
YGNodeSetMeasureFunc(node, YGMeasureView);
|
||||
} else {
|
||||
YGNodeSetMeasureFunc(node, NULL);
|
||||
|
||||
|
Reference in New Issue
Block a user