diff --git a/ReactCommon/fabric/uimanager/Differentiator.cpp b/ReactCommon/fabric/uimanager/Differentiator.cpp index 87f92990450..a689d51d9db 100644 --- a/ReactCommon/fabric/uimanager/Differentiator.cpp +++ b/ReactCommon/fabric/uimanager/Differentiator.cpp @@ -5,7 +5,7 @@ namespace facebook { namespace react { -void calculateMutationInstructions( +static void calculateMutationInstructions( TreeMutationInstructionList &instructions, SharedShadowNode parentNode, SharedShadowNodeSharedList oldChildNodes, @@ -154,5 +154,33 @@ void calculateMutationInstructions( instructions.insert(instructions.end(), downwardInstructions.begin(), downwardInstructions.end()); } + +void calculateMutationInstructions( + TreeMutationInstructionList &instructions, + SharedShadowNode oldRootShadowNode, + SharedShadowNode newRootShadowNode +) { + // Root shadow nodes must have same tag. + assert(oldRootShadowNode->getTag() == newRootShadowNode->getTag()); + + if (*oldRootShadowNode != *newRootShadowNode) { + instructions.push_back( + TreeMutationInstruction::Replace( + nullptr, + oldRootShadowNode, + newRootShadowNode, + -1 + ) + ); + } + + calculateMutationInstructions( + instructions, + oldRootShadowNode, + oldRootShadowNode->getChildren(), + newRootShadowNode->getChildren() + ); +} + } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/uimanager/Differentiator.h b/ReactCommon/fabric/uimanager/Differentiator.h index 7eb9fa332ff..c1d7a8b1d4e 100644 --- a/ReactCommon/fabric/uimanager/Differentiator.h +++ b/ReactCommon/fabric/uimanager/Differentiator.h @@ -15,9 +15,8 @@ namespace react { */ void calculateMutationInstructions( TreeMutationInstructionList &instructions, - SharedShadowNode parentNode, - SharedShadowNodeSharedList oldChildNodes, - SharedShadowNodeSharedList newChildNodes + SharedShadowNode oldNode, + SharedShadowNode newNode ); } // namespace react diff --git a/ReactCommon/fabric/uimanager/ShadowTree.cpp b/ReactCommon/fabric/uimanager/ShadowTree.cpp index 32a7870d96a..30b24643864 100644 --- a/ReactCommon/fabric/uimanager/ShadowTree.cpp +++ b/ReactCommon/fabric/uimanager/ShadowTree.cpp @@ -69,8 +69,7 @@ void ShadowTree::complete(UnsharedRootShadowNode newRootShadowNode) { calculateMutationInstructions( instructions, oldRootShadowNode, - oldRootShadowNode->ShadowNode::getChildren(), - newRootShadowNode->ShadowNode::getChildren() + newRootShadowNode ); if (commit(newRootShadowNode)) { diff --git a/ReactCommon/fabric/uimanager/TreeMutationInstruction.cpp b/ReactCommon/fabric/uimanager/TreeMutationInstruction.cpp index 42882ee6cfc..fd728dd7a41 100644 --- a/ReactCommon/fabric/uimanager/TreeMutationInstruction.cpp +++ b/ReactCommon/fabric/uimanager/TreeMutationInstruction.cpp @@ -82,10 +82,8 @@ const TreeMutationInstruction TreeMutationInstruction::Replace( SharedShadowNode newChildNode, int index ) { - assert(parentNode); assert(oldChildNode); assert(newChildNode); - assert(index != -1); return TreeMutationInstruction( Replacement,