From 9d6eaa473d4b09a30e3397cd6fafc6bc0b4c1c9c Mon Sep 17 00:00:00 2001 From: henry <758981890@qq.com> Date: Fri, 29 Apr 2022 09:42:40 +0800 Subject: [PATCH] [YogaKit] when we want to insert a child node, we should remove child node from owner if the node has one owner --- YogaKit/Source/YGLayout.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 2989ffab..0ef52bc6 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -430,7 +430,13 @@ static void YGAttachNodesFromViewHierachy(UIView* const view) { if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) { YGRemoveAllChildren(node); 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); } }