From 774213f558aefe063b6be8adab931314e17ce5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Thu, 4 Jul 2024 15:32:28 +0200 Subject: [PATCH 01/15] Update cloning --- .../Common/cpp/Fabric/PropsRegistry.cpp | 4 +- .../Common/cpp/Fabric/PropsRegistry.h | 2 +- .../cpp/Fabric/ReanimatedCommitHook.cpp | 18 ++-- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 95 +++++++++---------- .../Common/cpp/Fabric/ShadowTreeCloner.h | 7 +- .../NativeModules/NativeReanimatedModule.cpp | 44 ++++----- 6 files changed, 75 insertions(+), 95 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.cpp index bf501aac28d..79a84573d81 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.cpp @@ -25,10 +25,10 @@ void PropsRegistry::update( } void PropsRegistry::for_each(std::function callback) const { for (const auto &[_, value] : map_) { - callback(value.first->getFamily(), value.second); + callback(value.first, value.second); } } diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.h b/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.h index 2cbaab35086..091141d1b74 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.h @@ -20,7 +20,7 @@ class PropsRegistry { void update(const ShadowNode::Shared &shadowNode, folly::dynamic &&props); void for_each(std::function callback) const; void remove(const Tag tag); diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index dc809e00e6b..095d104e77e 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -38,22 +38,16 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // ShadowTree not commited by Reanimated, apply updates from PropsRegistry auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{}); + std::vector nodes; + std::unordered_map>> propsMap; { auto lock = propsRegistry_->createLock(); propsRegistry_->for_each( - [&](const ShadowNodeFamily &family, const folly::dynamic &props) { - auto newRootNode = - cloneShadowTreeWithNewProps(rootNode, family, RawProps(props)); - - if (newRootNode == nullptr) { - // this happens when React removed the component but Reanimated - // still tries to animate it, let's skip update for this specific - // component - return; - } - rootNode = newRootNode; + [&](const ShadowNode::Shared &shadowNode, const folly::dynamic &props) { + propsMap[&shadowNode->getFamily()].push_back(std::make_shared(props)); + nodes.push_back(shadowNode); }); } @@ -63,7 +57,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // applied in ReanimatedCommitHook by iterating over PropsRegistry. propsRegistry_->pleaseSkipReanimatedCommit(); - return std::static_pointer_cast(rootNode); + return std::static_pointer_cast(cloneShadowTreeWithNewProps(rootNode, nodes, propsMap)); } } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index 96ad97e5e94..6224d9e9b24 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -6,60 +6,57 @@ namespace reanimated { -ShadowNode::Unshared cloneShadowTreeWithNewProps( - const ShadowNode::Shared &oldRootNode, - const ShadowNodeFamily &family, - RawProps &&rawProps) { - // adapted from ShadowNode::cloneTree - - auto ancestors = family.getAncestors(*oldRootNode); - - if (ancestors.empty()) { - return ShadowNode::Unshared{nullptr}; +ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(std::unordered_map> &childrenMap, const ShadowNode::Shared &shadowNode, std::unordered_map>> &propsMap){ + auto family = &shadowNode->getFamily(); + auto children = shadowNode->getChildren(); + auto& childrenSet = childrenMap[family]; + + for (auto& index: childrenSet){ + children[index] = cloneShadowTreeWithNewPropsRecursive(childrenMap, children[index], propsMap); } - - auto &parent = ancestors.back(); - auto &source = parent.first.get().getChildren().at(parent.second); - - PropsParserContext propsParserContext{ - source->getSurfaceId(), *source->getContextContainer()}; - const auto props = source->getComponentDescriptor().cloneProps( - propsParserContext, source->getProps(), std::move(rawProps)); - - auto newChildNode = source->clone( - {/* .props = */ props, - ShadowNodeFragment::childrenPlaceholder(), - source->getState()}); - - for (auto it = ancestors.rbegin(); it != ancestors.rend(); ++it) { - auto &parentNode = it->first.get(); - auto childIndex = it->second; - - auto children = parentNode.getChildren(); - const auto &oldChildNode = *children.at(childIndex); - react_native_assert(ShadowNode::sameFamily(oldChildNode, *newChildNode)); - - if (!parentNode.getSealed()) { - // Optimization: if a ShadowNode is unsealed, we can directly update its - // children instead of cloning the whole path to the root node. - auto &parentNodeNonConst = const_cast(parentNode); - parentNodeNonConst.replaceChild(oldChildNode, newChildNode, childIndex); - // Unfortunately, `replaceChild` does not update Yoga nodes, so we need to - // update them manually here. - static_cast(&parentNodeNonConst) - ->updateYogaChildren(); - return std::const_pointer_cast(oldRootNode); + + Props::Shared newProps = nullptr; + + if (propsMap.contains(family)){ + PropsParserContext propsParserContext{shadowNode->getSurfaceId(), *shadowNode->getContextContainer()}; + newProps = shadowNode->getProps(); + for (auto& props: propsMap[family]){ + newProps = shadowNode->getComponentDescriptor().cloneProps(propsParserContext, newProps, std::move(*props)); } + } + + auto result = shadowNode->clone( + {newProps ? newProps : ShadowNodeFragment::propsPlaceholder(), + std::make_shared(children), + shadowNode->getState()}); + + return result; +} - children[childIndex] = newChildNode; - - newChildNode = parentNode.clone( - {ShadowNodeFragment::propsPlaceholder(), - std::make_shared(children), - parentNode.getState()}); +ShadowNode::Unshared cloneShadowTreeWithNewProps( + const ShadowNode::Shared &oldRootNode, + std::vector nodes, + std::unordered_map>> &propsMap) { + std::unordered_map> childrenMap; + + for (auto &node: nodes){ + auto ancestors = node->getFamily().getAncestors(*oldRootNode); + + for (auto it = ancestors.rbegin(); it != ancestors.rend(); ++it) { + auto& parentNode = it->first.get(); + auto index = it->second; + auto family = &parentNode.getFamily(); + auto& childrenSet = childrenMap[family]; + + childrenSet.insert(index); + + if (childrenSet.size() > 1){ + break; + } + } } - return std::const_pointer_cast(newChildNode); + return cloneShadowTreeWithNewPropsRecursive(childrenMap, oldRootNode, propsMap); } } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index f759d3517f9..7368b067cc8 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -5,7 +5,8 @@ #include #include -#include +#include +#include using namespace facebook; using namespace react; @@ -14,8 +15,8 @@ namespace reanimated { ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - const ShadowNodeFamily &family, - RawProps &&rawProps); + std::vector nodes, + std::unordered_map>> &propsMap); } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index b7fd7160fe5..f31b1d1a549 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -720,38 +720,26 @@ void NativeReanimatedModule::performOperations() { shadowTree.commit( [&](RootShadowNode const &oldRootShadowNode) -> RootShadowNode::Unshared { + std::vector nodes; + std::unordered_map>> propsMap; auto rootNode = oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); - - for (const auto &[shadowNode, props] : copiedOperationsQueue) { - const ShadowNodeFamily &family = shadowNode->getFamily(); - react_native_assert(family.getSurfaceId() == surfaceId_); - + for (const auto &[shadowNode, props] : copiedOperationsQueue) { + auto family = &shadowNode->getFamily(); + propsMap[family].push_back(std::make_shared(rt, *props)); + #if REACT_NATIVE_MINOR_VERSION >= 73 - // Fix for catching nullptr returned from commit hook was - // introduced in 0.72.4 but we have only check for minor version - // of React Native so enable that optimization in React Native >= - // 0.73 - if (propsRegistry_->shouldReanimatedSkipCommit()) { - return nullptr; - } + // Fix for catching nullptr returned from commit hook was + // introduced in 0.72.4 but we have only check for minor version + // of React Native so enable that optimization in React Native >= + // 0.73 + if (propsRegistry_->shouldReanimatedSkipCommit()) { + return nullptr; + } #endif - - auto newRootNode = cloneShadowTreeWithNewProps( - rootNode, family, RawProps(rt, *props)); - - if (newRootNode == nullptr) { - // this happens when React removed the component but Reanimated - // still tries to animate it, let's skip update for this - // specific component - continue; - } - rootNode = newRootNode; - } - - auto newRoot = std::static_pointer_cast(rootNode); - - return newRoot; + nodes.push_back(shadowNode); + } + return std::static_pointer_cast(cloneShadowTreeWithNewProps(rootNode, nodes, propsMap)); }, { /* .enableStateReconciliation = */ false, From ecfd0a2c1c1f70fb09292754b403b8d2cffff248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Thu, 4 Jul 2024 16:46:33 +0200 Subject: [PATCH 02/15] Change indices set to vector --- .../Common/cpp/Fabric/PropsRegistry.cpp | 4 ++-- .../Common/cpp/Fabric/PropsRegistry.h | 2 +- .../cpp/Fabric/ReanimatedCommitHook.cpp | 10 ++++----- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 21 +++++++++---------- .../Common/cpp/Fabric/ShadowTreeCloner.h | 1 - .../NativeModules/NativeReanimatedModule.cpp | 4 +--- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.cpp index 79a84573d81..bf501aac28d 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.cpp @@ -25,10 +25,10 @@ void PropsRegistry::update( } void PropsRegistry::for_each(std::function callback) const { for (const auto &[_, value] : map_) { - callback(value.first, value.second); + callback(value.first->getFamily(), value.second); } } diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.h b/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.h index 091141d1b74..2cbaab35086 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/PropsRegistry.h @@ -20,7 +20,7 @@ class PropsRegistry { void update(const ShadowNode::Shared &shadowNode, folly::dynamic &&props); void for_each(std::function callback) const; void remove(const Tag tag); diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index 095d104e77e..61b5e0e0b20 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -38,17 +38,17 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // ShadowTree not commited by Reanimated, apply updates from PropsRegistry auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{}); - std::vector nodes; std::unordered_map>> propsMap; { auto lock = propsRegistry_->createLock(); propsRegistry_->for_each( - [&](const ShadowNode::Shared &shadowNode, const folly::dynamic &props) { - propsMap[&shadowNode->getFamily()].push_back(std::make_shared(props)); - nodes.push_back(shadowNode); + [&](const ShadowNodeFamily &family, const folly::dynamic &props) { + propsMap[&family].push_back(std::make_shared(props)); }); + + rootNode = std::static_pointer_cast(cloneShadowTreeWithNewProps(rootNode, propsMap)); } // If the commit comes from React Native then skip one commit from Reanimated @@ -57,7 +57,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // applied in ReanimatedCommitHook by iterating over PropsRegistry. propsRegistry_->pleaseSkipReanimatedCommit(); - return std::static_pointer_cast(cloneShadowTreeWithNewProps(rootNode, nodes, propsMap)); + return std::static_pointer_cast(rootNode); } } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index 6224d9e9b24..443d574288c 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -6,12 +6,12 @@ namespace reanimated { -ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(std::unordered_map> &childrenMap, const ShadowNode::Shared &shadowNode, std::unordered_map>> &propsMap){ +ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(std::unordered_map> &childrenMap, const ShadowNode::Shared &shadowNode, std::unordered_map>> &propsMap){ auto family = &shadowNode->getFamily(); auto children = shadowNode->getChildren(); - auto& childrenSet = childrenMap[family]; + auto& affectedChildren = childrenMap[family]; - for (auto& index: childrenSet){ + for (auto& index: affectedChildren){ children[index] = cloneShadowTreeWithNewPropsRecursive(childrenMap, children[index], propsMap); } @@ -35,22 +35,21 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(std::unordered_map nodes, std::unordered_map>> &propsMap) { - std::unordered_map> childrenMap; + std::unordered_map> childrenMap; - for (auto &node: nodes){ - auto ancestors = node->getFamily().getAncestors(*oldRootNode); + for (auto &[family, _]: propsMap){ + auto ancestors = family->getAncestors(*oldRootNode); for (auto it = ancestors.rbegin(); it != ancestors.rend(); ++it) { auto& parentNode = it->first.get(); auto index = it->second; - auto family = &parentNode.getFamily(); - auto& childrenSet = childrenMap[family]; + auto parentFamily = &parentNode.getFamily(); + auto& affectedChildren = childrenMap[parentFamily]; - childrenSet.insert(index); + affectedChildren.push_back(index); - if (childrenSet.size() > 1){ + if (affectedChildren.size() > 1){ break; } } diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index 7368b067cc8..454c2ebf8e4 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -15,7 +15,6 @@ namespace reanimated { ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - std::vector nodes, std::unordered_map>> &propsMap); } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index f31b1d1a549..bc193a7f328 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -720,7 +720,6 @@ void NativeReanimatedModule::performOperations() { shadowTree.commit( [&](RootShadowNode const &oldRootShadowNode) -> RootShadowNode::Unshared { - std::vector nodes; std::unordered_map>> propsMap; auto rootNode = oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); @@ -737,9 +736,8 @@ void NativeReanimatedModule::performOperations() { return nullptr; } #endif - nodes.push_back(shadowNode); } - return std::static_pointer_cast(cloneShadowTreeWithNewProps(rootNode, nodes, propsMap)); + return std::static_pointer_cast(cloneShadowTreeWithNewProps(rootNode, propsMap)); }, { /* .enableStateReconciliation = */ false, From 71c93acb9266c79234da4d63f103051e0cba674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Thu, 4 Jul 2024 17:59:57 +0200 Subject: [PATCH 03/15] Run formatting --- .../cpp/Fabric/ReanimatedCommitHook.cpp | 12 +++- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 61 +++++++++++-------- .../Common/cpp/Fabric/ShadowTreeCloner.h | 6 +- .../NativeModules/NativeReanimatedModule.cpp | 32 +++++----- 4 files changed, 67 insertions(+), 44 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index 61b5e0e0b20..1fa1b749fd2 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -1,6 +1,8 @@ #ifdef RCT_NEW_ARCH_ENABLED #include +#include +#include #include "ReanimatedCommitHook.h" #include "ReanimatedCommitMarker.h" @@ -38,7 +40,10 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // ShadowTree not commited by Reanimated, apply updates from PropsRegistry auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{}); - std::unordered_map>> propsMap; + std::unordered_map< + const ShadowNodeFamily *, + std::vector>> + propsMap; { auto lock = propsRegistry_->createLock(); @@ -47,8 +52,9 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( [&](const ShadowNodeFamily &family, const folly::dynamic &props) { propsMap[&family].push_back(std::make_shared(props)); }); - - rootNode = std::static_pointer_cast(cloneShadowTreeWithNewProps(rootNode, propsMap)); + + rootNode = std::static_pointer_cast( + cloneShadowTreeWithNewProps(rootNode, propsMap)); } // If the commit comes from React Native then skip one commit from Reanimated diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index 443d574288c..7ce8995e8a5 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -6,56 +6,67 @@ namespace reanimated { -ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(std::unordered_map> &childrenMap, const ShadowNode::Shared &shadowNode, std::unordered_map>> &propsMap){ +ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( + std::unordered_map> &childrenMap, + const ShadowNode::Shared &shadowNode, + std::unordered_map< + const ShadowNodeFamily *, + std::vector>> &propsMap) { auto family = &shadowNode->getFamily(); auto children = shadowNode->getChildren(); - auto& affectedChildren = childrenMap[family]; - - for (auto& index: affectedChildren){ - children[index] = cloneShadowTreeWithNewPropsRecursive(childrenMap, children[index], propsMap); + auto &affectedChildren = childrenMap[family]; + + for (auto index : affectedChildren) { + children[index] = cloneShadowTreeWithNewPropsRecursive( + childrenMap, children[index], propsMap); } - + Props::Shared newProps = nullptr; - - if (propsMap.contains(family)){ - PropsParserContext propsParserContext{shadowNode->getSurfaceId(), *shadowNode->getContextContainer()}; + + if (propsMap.contains(family)) { + PropsParserContext propsParserContext{ + shadowNode->getSurfaceId(), *shadowNode->getContextContainer()}; newProps = shadowNode->getProps(); - for (auto& props: propsMap[family]){ - newProps = shadowNode->getComponentDescriptor().cloneProps(propsParserContext, newProps, std::move(*props)); + for (auto &props : propsMap[family]) { + newProps = shadowNode->getComponentDescriptor().cloneProps( + propsParserContext, newProps, std::move(*props)); } } - + auto result = shadowNode->clone( {newProps ? newProps : ShadowNodeFragment::propsPlaceholder(), std::make_shared(children), - shadowNode->getState()}); - + shadowNode->getState()}); + return result; } ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - std::unordered_map>> &propsMap) { - std::unordered_map> childrenMap; - - for (auto &[family, _]: propsMap){ + std::unordered_map< + const ShadowNodeFamily *, + std::vector>> &propsMap) { + std::unordered_map> childrenMap; + + for (auto &[family, _] : propsMap) { auto ancestors = family->getAncestors(*oldRootNode); - + for (auto it = ancestors.rbegin(); it != ancestors.rend(); ++it) { - auto& parentNode = it->first.get(); + auto &parentNode = it->first.get(); auto index = it->second; auto parentFamily = &parentNode.getFamily(); - auto& affectedChildren = childrenMap[parentFamily]; - + auto &affectedChildren = childrenMap[parentFamily]; + affectedChildren.push_back(index); - - if (affectedChildren.size() > 1){ + + if (affectedChildren.size() > 1) { break; } } } - return cloneShadowTreeWithNewPropsRecursive(childrenMap, oldRootNode, propsMap); + return cloneShadowTreeWithNewPropsRecursive( + childrenMap, oldRootNode, propsMap); } } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index 454c2ebf8e4..ae335f255b0 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -5,8 +5,8 @@ #include #include -#include #include +#include using namespace facebook; using namespace react; @@ -15,7 +15,9 @@ namespace reanimated { ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - std::unordered_map>> &propsMap); + std::unordered_map< + const ShadowNodeFamily *, + std::vector>> &propsMap); } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index bc193a7f328..b791e415cbf 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -720,24 +720,28 @@ void NativeReanimatedModule::performOperations() { shadowTree.commit( [&](RootShadowNode const &oldRootShadowNode) -> RootShadowNode::Unshared { - std::unordered_map>> propsMap; + std::unordered_map< + const ShadowNodeFamily *, + std::vector>> + propsMap; auto rootNode = oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); - for (const auto &[shadowNode, props] : copiedOperationsQueue) { - auto family = &shadowNode->getFamily(); - propsMap[family].push_back(std::make_shared(rt, *props)); - + for (const auto &[shadowNode, props] : copiedOperationsQueue) { + auto family = &shadowNode->getFamily(); + propsMap[family].push_back(std::make_shared(rt, *props)); + #if REACT_NATIVE_MINOR_VERSION >= 73 - // Fix for catching nullptr returned from commit hook was - // introduced in 0.72.4 but we have only check for minor version - // of React Native so enable that optimization in React Native >= - // 0.73 - if (propsRegistry_->shouldReanimatedSkipCommit()) { - return nullptr; - } + // Fix for catching nullptr returned from commit hook was + // introduced in 0.72.4 but we have only check for minor version + // of React Native so enable that optimization in React Native >= + // 0.73 + if (propsRegistry_->shouldReanimatedSkipCommit()) { + return nullptr; + } #endif - } - return std::static_pointer_cast(cloneShadowTreeWithNewProps(rootNode, propsMap)); + } + return std::static_pointer_cast( + cloneShadowTreeWithNewProps(rootNode, propsMap)); }, { /* .enableStateReconciliation = */ false, From 7c4b19425ea48e3927156e968547226563149700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Fri, 5 Jul 2024 16:19:42 +0200 Subject: [PATCH 04/15] Use using --- .../Common/cpp/Fabric/ReanimatedCommitHook.cpp | 5 +---- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 12 ++++-------- .../Common/cpp/Fabric/ShadowTreeCloner.h | 7 ++++--- .../cpp/NativeModules/NativeReanimatedModule.cpp | 5 +---- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index 1fa1b749fd2..f0de416f6c6 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -40,10 +40,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // ShadowTree not commited by Reanimated, apply updates from PropsRegistry auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{}); - std::unordered_map< - const ShadowNodeFamily *, - std::vector>> - propsMap; + PropsMap propsMap; { auto lock = propsRegistry_->createLock(); diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index 7ce8995e8a5..ded9a3af485 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -7,11 +7,9 @@ namespace reanimated { ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( - std::unordered_map> &childrenMap, + ChildrenMap &childrenMap, const ShadowNode::Shared &shadowNode, - std::unordered_map< - const ShadowNodeFamily *, - std::vector>> &propsMap) { + PropsMap &propsMap) { auto family = &shadowNode->getFamily(); auto children = shadowNode->getChildren(); auto &affectedChildren = childrenMap[family]; @@ -43,10 +41,8 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - std::unordered_map< - const ShadowNodeFamily *, - std::vector>> &propsMap) { - std::unordered_map> childrenMap; + PropsMap &propsMap) { + ChildrenMap childrenMap; for (auto &[family, _] : propsMap) { auto ancestors = family->getAncestors(*oldRootNode); diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index ae335f255b0..1ed3bf1d41b 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -13,11 +13,12 @@ using namespace react; namespace reanimated { +using PropsMap = std::unordered_map>>; +using ChildrenMap = std::unordered_map>; + ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - std::unordered_map< - const ShadowNodeFamily *, - std::vector>> &propsMap); + PropsMap &propsMap); } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index b791e415cbf..639bff84751 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -720,10 +720,7 @@ void NativeReanimatedModule::performOperations() { shadowTree.commit( [&](RootShadowNode const &oldRootShadowNode) -> RootShadowNode::Unshared { - std::unordered_map< - const ShadowNodeFamily *, - std::vector>> - propsMap; + PropsMap propsMap; auto rootNode = oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); for (const auto &[shadowNode, props] : copiedOperationsQueue) { From 4439da8e8c84246e352bafec630ec15224976f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Fri, 5 Jul 2024 16:54:47 +0200 Subject: [PATCH 05/15] Use unique_ptr --- .../Common/cpp/Fabric/ReanimatedCommitHook.cpp | 2 +- .../Common/cpp/Fabric/ShadowTreeCloner.h | 2 +- .../Common/cpp/NativeModules/NativeReanimatedModule.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index f0de416f6c6..fd4063cf4f1 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -47,7 +47,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( propsRegistry_->for_each( [&](const ShadowNodeFamily &family, const folly::dynamic &props) { - propsMap[&family].push_back(std::make_shared(props)); + propsMap[&family].emplace_back(std::make_unique(props)); }); rootNode = std::static_pointer_cast( diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index 1ed3bf1d41b..25871774dc5 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -13,7 +13,7 @@ using namespace react; namespace reanimated { -using PropsMap = std::unordered_map>>; +using PropsMap = std::unordered_map>>; using ChildrenMap = std::unordered_map>; ShadowNode::Unshared cloneShadowTreeWithNewProps( diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 639bff84751..9fb69e6a2e9 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -725,7 +725,7 @@ void NativeReanimatedModule::performOperations() { oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); for (const auto &[shadowNode, props] : copiedOperationsQueue) { auto family = &shadowNode->getFamily(); - propsMap[family].push_back(std::make_shared(rt, *props)); + propsMap[family].emplace_back(std::make_unique(rt, *props)); #if REACT_NATIVE_MINOR_VERSION >= 73 // Fix for catching nullptr returned from commit hook was From 94babdd6ac23d1ebac67d655d3753194532f2f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Mon, 8 Jul 2024 11:23:24 +0200 Subject: [PATCH 06/15] Use const wherever possible --- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 32 ++++++++++--------- .../Common/cpp/Fabric/ShadowTreeCloner.h | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index ded9a3af485..193ae909629 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -7,31 +7,33 @@ namespace reanimated { ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( - ChildrenMap &childrenMap, + const ChildrenMap &childrenMap, const ShadowNode::Shared &shadowNode, - PropsMap &propsMap) { - auto family = &shadowNode->getFamily(); + const PropsMap &propsMap) { + const auto family = &shadowNode->getFamily(); + const auto affectedChildrenIt = childrenMap.find(family); + const auto propsIt = propsMap.find(family); auto children = shadowNode->getChildren(); - auto &affectedChildren = childrenMap[family]; - for (auto index : affectedChildren) { - children[index] = cloneShadowTreeWithNewPropsRecursive( - childrenMap, children[index], propsMap); + if (affectedChildrenIt != childrenMap.end()){ + for (const auto index : affectedChildrenIt->second) { + children[index] = cloneShadowTreeWithNewPropsRecursive(childrenMap, children[index], propsMap); + } } Props::Shared newProps = nullptr; - if (propsMap.contains(family)) { + if (propsIt != propsMap.end()) { PropsParserContext propsParserContext{ shadowNode->getSurfaceId(), *shadowNode->getContextContainer()}; newProps = shadowNode->getProps(); - for (auto &props : propsMap[family]) { + for (const auto &props : propsIt->second) { newProps = shadowNode->getComponentDescriptor().cloneProps( propsParserContext, newProps, std::move(*props)); } } - auto result = shadowNode->clone( + const auto result = shadowNode->clone( {newProps ? newProps : ShadowNodeFragment::propsPlaceholder(), std::make_shared(children), shadowNode->getState()}); @@ -41,16 +43,16 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - PropsMap &propsMap) { + const PropsMap &propsMap) { ChildrenMap childrenMap; for (auto &[family, _] : propsMap) { - auto ancestors = family->getAncestors(*oldRootNode); + const auto ancestors = family->getAncestors(*oldRootNode); for (auto it = ancestors.rbegin(); it != ancestors.rend(); ++it) { - auto &parentNode = it->first.get(); - auto index = it->second; - auto parentFamily = &parentNode.getFamily(); + const auto &parentNode = it->first.get(); + const auto index = it->second; + const auto parentFamily = &parentNode.getFamily(); auto &affectedChildren = childrenMap[parentFamily]; affectedChildren.push_back(index); diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index 25871774dc5..fe8c11a8a46 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -18,7 +18,7 @@ using ChildrenMap = std::unordered_map Date: Mon, 8 Jul 2024 11:44:55 +0200 Subject: [PATCH 07/15] Run format --- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index 193ae909629..ac67fa1c974 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -15,9 +15,10 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( const auto propsIt = propsMap.find(family); auto children = shadowNode->getChildren(); - if (affectedChildrenIt != childrenMap.end()){ + if (affectedChildrenIt != childrenMap.end()) { for (const auto index : affectedChildrenIt->second) { - children[index] = cloneShadowTreeWithNewPropsRecursive(childrenMap, children[index], propsMap); + children[index] = cloneShadowTreeWithNewPropsRecursive( + childrenMap, children[index], propsMap); } } From 59145d8468ea1f68e66dcff5e8e5bc23f26ea70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Wed, 17 Jul 2024 19:08:29 +0200 Subject: [PATCH 08/15] Add PropsWrapper --- .../Common/cpp/Fabric/PropsWrapper.h | 38 +++++++++++++++++++ .../cpp/Fabric/ReanimatedCommitHook.cpp | 2 +- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 2 +- .../Common/cpp/Fabric/ShadowTreeCloner.h | 4 +- .../NativeModules/NativeReanimatedModule.cpp | 6 +-- 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h b/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h new file mode 100644 index 00000000000..63093052189 --- /dev/null +++ b/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h @@ -0,0 +1,38 @@ +#pragma once +#ifdef RCT_NEW_ARCH_ENABLED + +#include + +using namespace facebook; +using namespace react; + +namespace reanimated { + +class PropsWrapper { +public: + virtual inline RawProps getRawProps() = 0; + virtual ~PropsWrapper() = default; +}; + +class JsiValuePropsWrapper : public PropsWrapper { + jsi::Runtime& runtime; + std::unique_ptr value; +public: + JsiValuePropsWrapper(jsi::Runtime& runtime, std::unique_ptr&& value): runtime(runtime), value(std::move(value)){} + inline RawProps getRawProps() override { + return RawProps(runtime, *value); + } +}; + +struct FollyDynamicPropsWrapper : public PropsWrapper { + const folly::dynamic& value; +public: + FollyDynamicPropsWrapper(const folly::dynamic& value): value(value){} + inline RawProps getRawProps() override { + return RawProps(value); + } +}; + +} + +#endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index fd4063cf4f1..6b18a7a5953 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -47,7 +47,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( propsRegistry_->for_each( [&](const ShadowNodeFamily &family, const folly::dynamic &props) { - propsMap[&family].emplace_back(std::make_unique(props)); + propsMap[&family].emplace_back(std::make_unique(props)); }); rootNode = std::static_pointer_cast( diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index ac67fa1c974..3a26fe42ef7 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -30,7 +30,7 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( newProps = shadowNode->getProps(); for (const auto &props : propsIt->second) { newProps = shadowNode->getComponentDescriptor().cloneProps( - propsParserContext, newProps, std::move(*props)); + propsParserContext, newProps, props->getRawProps()); } } diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index fe8c11a8a46..3e8f40ef99f 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -8,12 +8,14 @@ #include #include +#include "PropsWrapper.h" + using namespace facebook; using namespace react; namespace reanimated { -using PropsMap = std::unordered_map>>; +using PropsMap = std::unordered_map>>; using ChildrenMap = std::unordered_map>; ShadowNode::Unshared cloneShadowTreeWithNewProps( diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 9fb69e6a2e9..602dff9170c 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -723,9 +723,9 @@ void NativeReanimatedModule::performOperations() { PropsMap propsMap; auto rootNode = oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); - for (const auto &[shadowNode, props] : copiedOperationsQueue) { - auto family = &shadowNode->getFamily(); - propsMap[family].emplace_back(std::make_unique(rt, *props)); + for (auto &[shadowNode, props] : copiedOperationsQueue) { + auto family = &shadowNode->getFamily(); + propsMap[family].emplace_back(std::make_unique(rt, std::move(props))); #if REACT_NATIVE_MINOR_VERSION >= 73 // Fix for catching nullptr returned from commit hook was From f09a4b317de9eb6beec572bc52ebddeed427d2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Wed, 17 Jul 2024 19:12:05 +0200 Subject: [PATCH 09/15] Format --- .../Common/cpp/Fabric/PropsWrapper.h | 23 ++++++++++++------- .../NativeModules/NativeReanimatedModule.cpp | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h b/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h index 63093052189..71e4aaa0622 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h @@ -2,6 +2,8 @@ #ifdef RCT_NEW_ARCH_ENABLED #include +#include +#include using namespace facebook; using namespace react; @@ -9,30 +11,35 @@ using namespace react; namespace reanimated { class PropsWrapper { -public: + public: virtual inline RawProps getRawProps() = 0; virtual ~PropsWrapper() = default; }; class JsiValuePropsWrapper : public PropsWrapper { - jsi::Runtime& runtime; + jsi::Runtime &runtime; std::unique_ptr value; -public: - JsiValuePropsWrapper(jsi::Runtime& runtime, std::unique_ptr&& value): runtime(runtime), value(std::move(value)){} + + public: + JsiValuePropsWrapper( + jsi::Runtime &runtime, + std::unique_ptr &&value) + : runtime(runtime), value(std::move(value)) {} inline RawProps getRawProps() override { return RawProps(runtime, *value); } }; struct FollyDynamicPropsWrapper : public PropsWrapper { - const folly::dynamic& value; -public: - FollyDynamicPropsWrapper(const folly::dynamic& value): value(value){} + const folly::dynamic &value; + + public: + explicit FollyDynamicPropsWrapper(const folly::dynamic &value) : value(value) {} inline RawProps getRawProps() override { return RawProps(value); } }; -} +} // namespace reanimated #endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 602dff9170c..4dd6d90a473 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -724,7 +724,7 @@ void NativeReanimatedModule::performOperations() { auto rootNode = oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); for (auto &[shadowNode, props] : copiedOperationsQueue) { - auto family = &shadowNode->getFamily(); + auto family = &shadowNode->getFamily(); propsMap[family].emplace_back(std::make_unique(rt, std::move(props))); #if REACT_NATIVE_MINOR_VERSION >= 73 From 416a6200b0cb772499c77fb78712c4e906684faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Thu, 18 Jul 2024 10:39:01 +0200 Subject: [PATCH 10/15] Use template --- .../Common/cpp/Fabric/ReanimatedCommitHook.cpp | 2 +- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 14 ++++++++++++-- .../Common/cpp/Fabric/ShadowTreeCloner.h | 11 +++++++++-- .../cpp/NativeModules/NativeReanimatedModule.cpp | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index 6b18a7a5953..cce644bc5b6 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -40,7 +40,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // ShadowTree not commited by Reanimated, apply updates from PropsRegistry auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{}); - PropsMap propsMap; + PropsMap propsMap; { auto lock = propsRegistry_->createLock(); diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index 3a26fe42ef7..33cb3fce2c8 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -6,10 +6,11 @@ namespace reanimated { +template ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( const ChildrenMap &childrenMap, const ShadowNode::Shared &shadowNode, - const PropsMap &propsMap) { + const PropsMap &propsMap) { const auto family = &shadowNode->getFamily(); const auto affectedChildrenIt = childrenMap.find(family); const auto propsIt = propsMap.find(family); @@ -42,9 +43,10 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( return result; } +template ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - const PropsMap &propsMap) { + const PropsMap &propsMap) { ChildrenMap childrenMap; for (auto &[family, _] : propsMap) { @@ -68,6 +70,14 @@ ShadowNode::Unshared cloneShadowTreeWithNewProps( childrenMap, oldRootNode, propsMap); } +template ShadowNode::Unshared cloneShadowTreeWithNewProps( + const ShadowNode::Shared &oldRootNode, + const PropsMap &propsMap); + +template ShadowNode::Unshared cloneShadowTreeWithNewProps( + const ShadowNode::Shared &oldRootNode, + const PropsMap &propsMap); + } // namespace reanimated #endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index 3e8f40ef99f..ac8341e3e6b 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -15,12 +16,18 @@ using namespace react; namespace reanimated { -using PropsMap = std::unordered_map>>; +template +concept Derived = std::is_base_of_v; + +template +using PropsMap = std::unordered_map>>; + using ChildrenMap = std::unordered_map>; +template ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - const PropsMap &propsMap); + const PropsMap &propsMap); } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 4dd6d90a473..bca88ef41e1 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -720,7 +720,7 @@ void NativeReanimatedModule::performOperations() { shadowTree.commit( [&](RootShadowNode const &oldRootShadowNode) -> RootShadowNode::Unshared { - PropsMap propsMap; + PropsMap propsMap; auto rootNode = oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); for (auto &[shadowNode, props] : copiedOperationsQueue) { From 16048894523f276ca0a93c4b33c609c4b2d06b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Thu, 18 Jul 2024 13:11:23 +0200 Subject: [PATCH 11/15] Undo template and fix RawProps reusing --- .../cpp/Fabric/ReanimatedCommitHook.cpp | 4 +-- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 31 ++++++------------- .../Common/cpp/Fabric/ShadowTreeCloner.h | 12 ++----- .../NativeModules/NativeReanimatedModule.cpp | 4 +-- 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index cce644bc5b6..db77ea409bc 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -40,14 +40,14 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // ShadowTree not commited by Reanimated, apply updates from PropsRegistry auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{}); - PropsMap propsMap; + PropsMap propsMap; { auto lock = propsRegistry_->createLock(); propsRegistry_->for_each( [&](const ShadowNodeFamily &family, const folly::dynamic &props) { - propsMap[&family].emplace_back(std::make_unique(props)); + propsMap[&family].emplace_back(props); }); rootNode = std::static_pointer_cast( diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index 33cb3fce2c8..5daedf21c4d 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -1,16 +1,16 @@ #ifdef RCT_NEW_ARCH_ENABLED +#include #include #include "ShadowTreeCloner.h" namespace reanimated { -template ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( const ChildrenMap &childrenMap, const ShadowNode::Shared &shadowNode, - const PropsMap &propsMap) { + const PropsMap &propsMap) { const auto family = &shadowNode->getFamily(); const auto affectedChildrenIt = childrenMap.find(family); const auto propsIt = propsMap.find(family); @@ -31,7 +31,7 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( newProps = shadowNode->getProps(); for (const auto &props : propsIt->second) { newProps = shadowNode->getComponentDescriptor().cloneProps( - propsParserContext, newProps, props->getRawProps()); + propsParserContext, newProps, RawProps(props)); } } @@ -43,26 +43,23 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( return result; } -template ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - const PropsMap &propsMap) { + const PropsMap &propsMap) { ChildrenMap childrenMap; for (auto &[family, _] : propsMap) { const auto ancestors = family->getAncestors(*oldRootNode); - for (auto it = ancestors.rbegin(); it != ancestors.rend(); ++it) { - const auto &parentNode = it->first.get(); - const auto index = it->second; - const auto parentFamily = &parentNode.getFamily(); + for (const auto & [parentNode, index] : std::ranges::reverse_view(ancestors)) { + const auto parentFamily = &parentNode.get().getFamily(); auto &affectedChildren = childrenMap[parentFamily]; - affectedChildren.push_back(index); - - if (affectedChildren.size() > 1) { - break; + if (affectedChildren.contains(index)){ + continue; } + + affectedChildren.insert(index); } } @@ -70,14 +67,6 @@ ShadowNode::Unshared cloneShadowTreeWithNewProps( childrenMap, oldRootNode, propsMap); } -template ShadowNode::Unshared cloneShadowTreeWithNewProps( - const ShadowNode::Shared &oldRootNode, - const PropsMap &propsMap); - -template ShadowNode::Unshared cloneShadowTreeWithNewProps( - const ShadowNode::Shared &oldRootNode, - const PropsMap &propsMap); - } // namespace reanimated #endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index ac8341e3e6b..3c88f89536a 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -16,18 +16,12 @@ using namespace react; namespace reanimated { -template -concept Derived = std::is_base_of_v; +using PropsMap = std::unordered_map>; +using ChildrenMap = std::unordered_map>; -template -using PropsMap = std::unordered_map>>; - -using ChildrenMap = std::unordered_map>; - -template ShadowNode::Unshared cloneShadowTreeWithNewProps( const ShadowNode::Shared &oldRootNode, - const PropsMap &propsMap); + const PropsMap &propsMap); } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index bca88ef41e1..14a66ae5b2c 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -720,12 +720,12 @@ void NativeReanimatedModule::performOperations() { shadowTree.commit( [&](RootShadowNode const &oldRootShadowNode) -> RootShadowNode::Unshared { - PropsMap propsMap; + PropsMap propsMap; auto rootNode = oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); for (auto &[shadowNode, props] : copiedOperationsQueue) { auto family = &shadowNode->getFamily(); - propsMap[family].emplace_back(std::make_unique(rt, std::move(props))); + propsMap[family].emplace_back(rt, std::move(*props)); #if REACT_NATIVE_MINOR_VERSION >= 73 // Fix for catching nullptr returned from commit hook was From 272782b5f99556fe8d28f95cc8ac3a8f5e766ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Thu, 18 Jul 2024 13:14:07 +0200 Subject: [PATCH 12/15] Format --- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 7 ++++--- .../Common/cpp/Fabric/ShadowTreeCloner.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index 5daedf21c4d..dc017c368d5 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -51,14 +51,15 @@ ShadowNode::Unshared cloneShadowTreeWithNewProps( for (auto &[family, _] : propsMap) { const auto ancestors = family->getAncestors(*oldRootNode); - for (const auto & [parentNode, index] : std::ranges::reverse_view(ancestors)) { + for (const auto &[parentNode, index] : + std::ranges::reverse_view(ancestors)) { const auto parentFamily = &parentNode.get().getFamily(); auto &affectedChildren = childrenMap[parentFamily]; - if (affectedChildren.contains(index)){ + if (affectedChildren.contains(index)) { continue; } - + affectedChildren.insert(index); } } diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index 3c88f89536a..bdd62bcde47 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "PropsWrapper.h" From d58ddfcb63ca020f6da5a2ba72cfc0d74e73f750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Mon, 22 Jul 2024 11:56:50 +0200 Subject: [PATCH 13/15] Remove PropsWrapper.h --- .../Common/cpp/Fabric/PropsWrapper.h | 45 ------------------- .../Common/cpp/Fabric/ShadowTreeCloner.h | 2 - 2 files changed, 47 deletions(-) delete mode 100644 packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h b/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h deleted file mode 100644 index 71e4aaa0622..00000000000 --- a/packages/react-native-reanimated/Common/cpp/Fabric/PropsWrapper.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#ifdef RCT_NEW_ARCH_ENABLED - -#include -#include -#include - -using namespace facebook; -using namespace react; - -namespace reanimated { - -class PropsWrapper { - public: - virtual inline RawProps getRawProps() = 0; - virtual ~PropsWrapper() = default; -}; - -class JsiValuePropsWrapper : public PropsWrapper { - jsi::Runtime &runtime; - std::unique_ptr value; - - public: - JsiValuePropsWrapper( - jsi::Runtime &runtime, - std::unique_ptr &&value) - : runtime(runtime), value(std::move(value)) {} - inline RawProps getRawProps() override { - return RawProps(runtime, *value); - } -}; - -struct FollyDynamicPropsWrapper : public PropsWrapper { - const folly::dynamic &value; - - public: - explicit FollyDynamicPropsWrapper(const folly::dynamic &value) : value(value) {} - inline RawProps getRawProps() override { - return RawProps(value); - } -}; - -} // namespace reanimated - -#endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index bdd62bcde47..74e107127fb 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -10,8 +10,6 @@ #include #include -#include "PropsWrapper.h" - using namespace facebook; using namespace react; From a8e7ff004b23c942d7f4c023bc8190564bf4b353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Mon, 22 Jul 2024 14:02:06 +0200 Subject: [PATCH 14/15] Restore surfaceId assert --- .../Common/cpp/NativeModules/NativeReanimatedModule.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 14a66ae5b2c..5d068326395 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -725,6 +725,7 @@ void NativeReanimatedModule::performOperations() { oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); for (auto &[shadowNode, props] : copiedOperationsQueue) { auto family = &shadowNode->getFamily(); + react_native_assert(family->getSurfaceId() == surfaceId_); propsMap[family].emplace_back(rt, std::move(*props)); #if REACT_NATIVE_MINOR_VERSION >= 73 From f6ee24d7e83238d24e067ff403b69db4f5228e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20B=C5=82oniarz?= Date: Mon, 22 Jul 2024 14:39:09 +0200 Subject: [PATCH 15/15] Reformat ShadowTreeCloner --- .../cpp/Fabric/ReanimatedCommitHook.cpp | 7 ++--- .../Common/cpp/Fabric/ShadowTreeCloner.cpp | 30 ++++++++++--------- .../Common/cpp/Fabric/ShadowTreeCloner.h | 4 +-- .../NativeModules/NativeReanimatedModule.cpp | 5 +--- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp index db77ea409bc..b26b695d787 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ReanimatedCommitHook.cpp @@ -39,7 +39,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // ShadowTree not commited by Reanimated, apply updates from PropsRegistry - auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{}); + RootShadowNode::Unshared rootNode = newRootShadowNode; PropsMap propsMap; { @@ -50,8 +50,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( propsMap[&family].emplace_back(props); }); - rootNode = std::static_pointer_cast( - cloneShadowTreeWithNewProps(rootNode, propsMap)); + rootNode = cloneShadowTreeWithNewProps(*rootNode, propsMap); } // If the commit comes from React Native then skip one commit from Reanimated @@ -60,7 +59,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit( // applied in ReanimatedCommitHook by iterating over PropsRegistry. propsRegistry_->pleaseSkipReanimatedCommit(); - return std::static_pointer_cast(rootNode); + return rootNode; } } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp index dc017c368d5..787e13a57f8 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.cpp @@ -8,18 +8,18 @@ namespace reanimated { ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( + const ShadowNode &shadowNode, const ChildrenMap &childrenMap, - const ShadowNode::Shared &shadowNode, const PropsMap &propsMap) { - const auto family = &shadowNode->getFamily(); + const auto family = &shadowNode.getFamily(); const auto affectedChildrenIt = childrenMap.find(family); const auto propsIt = propsMap.find(family); - auto children = shadowNode->getChildren(); + auto children = shadowNode.getChildren(); if (affectedChildrenIt != childrenMap.end()) { for (const auto index : affectedChildrenIt->second) { children[index] = cloneShadowTreeWithNewPropsRecursive( - childrenMap, children[index], propsMap); + *children[index], childrenMap, propsMap); } } @@ -27,29 +27,29 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive( if (propsIt != propsMap.end()) { PropsParserContext propsParserContext{ - shadowNode->getSurfaceId(), *shadowNode->getContextContainer()}; - newProps = shadowNode->getProps(); + shadowNode.getSurfaceId(), *shadowNode.getContextContainer()}; + newProps = shadowNode.getProps(); for (const auto &props : propsIt->second) { - newProps = shadowNode->getComponentDescriptor().cloneProps( + newProps = shadowNode.getComponentDescriptor().cloneProps( propsParserContext, newProps, RawProps(props)); } } - const auto result = shadowNode->clone( + const auto result = shadowNode.clone( {newProps ? newProps : ShadowNodeFragment::propsPlaceholder(), std::make_shared(children), - shadowNode->getState()}); + shadowNode.getState()}); return result; } -ShadowNode::Unshared cloneShadowTreeWithNewProps( - const ShadowNode::Shared &oldRootNode, +RootShadowNode::Unshared cloneShadowTreeWithNewProps( + const RootShadowNode &oldRootNode, const PropsMap &propsMap) { ChildrenMap childrenMap; for (auto &[family, _] : propsMap) { - const auto ancestors = family->getAncestors(*oldRootNode); + const auto ancestors = family->getAncestors(oldRootNode); for (const auto &[parentNode, index] : std::ranges::reverse_view(ancestors)) { @@ -64,8 +64,10 @@ ShadowNode::Unshared cloneShadowTreeWithNewProps( } } - return cloneShadowTreeWithNewPropsRecursive( - childrenMap, oldRootNode, propsMap); + // This cast is safe, because this function returns a clone + // of the oldRootNode, which is an instance of RootShadowNode + return std::static_pointer_cast( + cloneShadowTreeWithNewPropsRecursive(oldRootNode, childrenMap, propsMap)); } } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h index 74e107127fb..efa186252f9 100644 --- a/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/Fabric/ShadowTreeCloner.h @@ -18,8 +18,8 @@ namespace reanimated { using PropsMap = std::unordered_map>; using ChildrenMap = std::unordered_map>; -ShadowNode::Unshared cloneShadowTreeWithNewProps( - const ShadowNode::Shared &oldRootNode, +RootShadowNode::Unshared cloneShadowTreeWithNewProps( + const RootShadowNode &oldRootNode, const PropsMap &propsMap); } // namespace reanimated diff --git a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 5d068326395..1b311b90c2a 100644 --- a/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -721,8 +721,6 @@ void NativeReanimatedModule::performOperations() { [&](RootShadowNode const &oldRootShadowNode) -> RootShadowNode::Unshared { PropsMap propsMap; - auto rootNode = - oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{}); for (auto &[shadowNode, props] : copiedOperationsQueue) { auto family = &shadowNode->getFamily(); react_native_assert(family->getSurfaceId() == surfaceId_); @@ -738,8 +736,7 @@ void NativeReanimatedModule::performOperations() { } #endif } - return std::static_pointer_cast( - cloneShadowTreeWithNewProps(rootNode, propsMap)); + return cloneShadowTreeWithNewProps(oldRootShadowNode, propsMap); }, { /* .enableStateReconciliation = */ false,