From 5c94283be3076bc5f67c99c88dcd44a7dd795ade Mon Sep 17 00:00:00 2001 From: Bartlomiej Bloniarz Date: Tue, 7 Oct 2025 23:43:09 -0700 Subject: [PATCH] Split families by surfaceId Differential Revision: D84055753 --- .../animationbackend/AnimationBackend.cpp | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp index 449a2fa0242..c726a1212fe 100644 --- a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp +++ b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp @@ -137,26 +137,36 @@ void AnimationBackend::stop() { void AnimationBackend::commitUpdatesWithFamilies( const std::unordered_set& families, std::unordered_map& updates) { - uiManager_->getShadowTreeRegistry().enumerate( - [families, &updates](const ShadowTree& shadowTree, bool& /*stop*/) { - shadowTree.commit( - [families, &updates](const RootShadowNode& oldRootShadowNode) { - return std::static_pointer_cast( - oldRootShadowNode.cloneMultiple( - families, - [families, &updates]( - const ShadowNode& shadowNode, - const ShadowNodeFragment& fragment) { - auto& animatedProps = updates.at(shadowNode.getTag()); - auto newProps = cloneProps(animatedProps, shadowNode); - return shadowNode.clone( - {newProps, - fragment.children, - shadowNode.getState()}); - })); - }, - {.mountSynchronously = true}); - }); + std::unordered_map> + surfaceToFamilies; + for (auto& family : families) { + surfaceToFamilies[family->getSurfaceId()].insert(family); + } + for (const auto& [surfaceId, surfaceFamilies] : surfaceToFamilies) { + uiManager_->getShadowTreeRegistry().visit( + surfaceId, + [surfaceFamilies = std::move(surfaceFamilies), + &updates](const ShadowTree& shadowTree) { + shadowTree.commit( + [surfaceFamilies = std::move(surfaceFamilies), + &updates](const RootShadowNode& oldRootShadowNode) { + return std::static_pointer_cast( + oldRootShadowNode.cloneMultiple( + surfaceFamilies, + [&updates]( + const ShadowNode& shadowNode, + const ShadowNodeFragment& fragment) { + auto& animatedProps = updates.at(shadowNode.getTag()); + auto newProps = cloneProps(animatedProps, shadowNode); + return shadowNode.clone( + {newProps, + fragment.children, + shadowNode.getState()}); + })); + }, + {.mountSynchronously = true}); + }); + } } void AnimationBackend::synchronouslyUpdateProps(