diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp index 6b107dcf5d1..a5a5ea214ee 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp +++ b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef RCT_NEW_ARCH_ENABLED #include @@ -636,9 +637,6 @@ void NativeReanimatedModule::updateProps( const jsi::Value &updates = item.getProperty(rt, "updates"); operationsInBatch_.emplace_back( shadowNode, std::make_unique(rt, updates)); - - // TODO: support multiple surfaces - surfaceId_ = shadowNode->getSurfaceId(); } } @@ -696,6 +694,7 @@ void NativeReanimatedModule::performOperations() { } bool hasLayoutUpdates = false; + for (const auto &[shadowNode, props] : copiedOperationsQueue) { if (isThereAnyLayoutProp(rt, props->asObject(rt))) { hasLayoutUpdates = true; @@ -725,41 +724,45 @@ void NativeReanimatedModule::performOperations() { react_native_assert(uiManager_ != nullptr); const auto &shadowTreeRegistry = uiManager_->getShadowTreeRegistry(); - shadowTreeRegistry.visit(surfaceId_, [&](ShadowTree const &shadowTree) { - shadowTree.commit( - [&](RootShadowNode const &oldRootShadowNode) - -> RootShadowNode::Unshared { - PropsMap propsMap; - for (auto &[shadowNode, props] : copiedOperationsQueue) { - auto family = &shadowNode->getFamily(); - react_native_assert(family->getSurfaceId() == surfaceId_); - propsMap[family].emplace_back(rt, std::move(*props)); + std::unordered_map propsMapBySurface; + + for (auto const &[shadowNode, props] : copiedOperationsQueue) { + SurfaceId surfaceId = shadowNode->getSurfaceId(); + auto family = &shadowNode->getFamily(); + react_native_assert(family->getSurfaceId() == surfaceId); + propsMapBySurface[surfaceId][family].emplace_back(rt, std::move(*props)); + } + for (auto const &[surfaceId, propsMap] : propsMapBySurface) { + shadowTreeRegistry.visit(surfaceId, [&](ShadowTree const &shadowTree) { + shadowTree.commit( + [&](RootShadowNode const &oldRootShadowNode) + -> RootShadowNode::Unshared { if (propsRegistry_->shouldReanimatedSkipCommit()) { return nullptr; } - } - - auto rootNode = - cloneShadowTreeWithNewProps(oldRootShadowNode, propsMap); - - // Mark the commit as Reanimated commit so that we can distinguish it - // in ReanimatedCommitHook. - - auto reaShadowNode = - std::reinterpret_pointer_cast( - rootNode); - reaShadowNode->setReanimatedCommitTrait(); - - return rootNode; - }, - {/* .enableStateReconciliation = */ - false, - /* .mountSynchronously = */ true, - /* .shouldYield = */ [this]() { - return propsRegistry_->shouldReanimatedSkipCommit(); - }}); - }); + + auto rootNode = + cloneShadowTreeWithNewProps(oldRootShadowNode, propsMap); + + // Mark the commit as Reanimated commit so that we can distinguish + // it in ReanimatedCommitHook. + + auto reaShadowNode = + std::reinterpret_pointer_cast( + rootNode); + reaShadowNode->setReanimatedCommitTrait(); + + return rootNode; + }, + {/* .enableStateReconciliation = */ + false, + /* .mountSynchronously = */ true, + /* .shouldYield = */ [this]() { + return propsRegistry_->shouldReanimatedSkipCommit(); + }}); + }); + } } void NativeReanimatedModule::removeFromPropsRegistry( diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h index f44d6fff725..e816214b340 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/NativeModules/NativeReanimatedModule.h @@ -218,10 +218,6 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec { std::shared_ptr uiManager_; std::shared_ptr layoutAnimationsProxy_; - // After app reload, surfaceId on iOS is still 1 but on Android it's 11. - // We can store surfaceId of the most recent ShadowNode as a workaround. - SurfaceId surfaceId_ = -1; - std::vector>> operationsInBatch_; // TODO: refactor std::pair to custom struct