[YogaKit] when we want to insert a child node, we should remove child node from owner if the node has one owner

This commit is contained in:
henry
2022-04-29 09:42:40 +08:00
parent 595fa45996
commit 9d6eaa473d

View File

@@ -430,7 +430,13 @@ static void YGAttachNodesFromViewHierachy(UIView* const view) {
if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) { if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) {
YGRemoveAllChildren(node); YGRemoveAllChildren(node);
for (int i = 0; i < subviewsToInclude.count; i++) { for (int i = 0; i < subviewsToInclude.count; i++) {
YGNodeInsertChild(node, subviewsToInclude[i].yoga.node, i); // should remove from owner if node has one owner
const YGNodeRef child = subviewsToInclude[i].yoga.node;
YGNodeRef owner = YGNodeGetOwner(child);
if (owner) {
YGNodeRemoveChild(owner, child);
}
YGNodeInsertChild(node, child, i);
} }
} }