From ffe928ce508950d91f6a5ac5fde782402f2c5b6a Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Mon, 16 Jun 2025 04:50:47 -0700 Subject: [PATCH] pass config in C++ Animated with std::move (#52039) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52039 changelog: [internal] config can be passed with std::move to avoid copy. Reviewed By: rshest, javache Differential Revision: D76628921 fbshipit-source-id: 82a90ce604d2a82a388eb4fa63f22deda6ec92ed --- .../react/renderer/animated/AnimatedModule.cpp | 5 ++++- .../renderer/animated/NativeAnimatedNodesManager.cpp | 8 ++++---- .../react/renderer/animated/NativeAnimatedNodesManager.h | 2 +- .../renderer/animated/drivers/DecayAnimationDriver.cpp | 6 +++--- .../renderer/animated/drivers/DecayAnimationDriver.h | 2 +- .../renderer/animated/drivers/FrameAnimationDriver.cpp | 4 ++-- .../renderer/animated/drivers/FrameAnimationDriver.h | 2 +- .../renderer/animated/drivers/SpringAnimationDriver.cpp | 4 ++-- .../renderer/animated/drivers/SpringAnimationDriver.h | 2 +- 9 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/AnimatedModule.cpp b/packages/react-native/ReactCxxPlatform/react/renderer/animated/AnimatedModule.cpp index ebdc9a943cc..75f8cfa7fdc 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/AnimatedModule.cpp +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/AnimatedModule.cpp @@ -241,7 +241,10 @@ void AnimatedModule::executeOperation(const Operation& operation) { nodesManager_->disconnectAnimatedNodes(op.parentTag, op.childTag); } else if constexpr (std::is_same_v) { nodesManager_->startAnimatingNode( - op.animationId, op.nodeTag, op.config, std::move(op.endCallback)); + op.animationId, + op.nodeTag, + std::move(op.config), + std::move(op.endCallback)); } else if constexpr (std::is_same_v) { nodesManager_->stopAnimation(op.animationId, false); } else if constexpr (std::is_same_v) { diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp b/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp index cc65a9e6bc3..846c63b35f8 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp @@ -273,7 +273,7 @@ void NativeAnimatedNodesManager::stopAnimationsForNode(Tag nodeTag) { void NativeAnimatedNodesManager::startAnimatingNode( int animationId, Tag animatedNodeTag, - const folly::dynamic& config, + folly::dynamic config, std::optional endCallback) noexcept { if (auto iter = activeAnimations_.find(animationId); iter != activeAnimations_.end()) { @@ -291,7 +291,7 @@ void NativeAnimatedNodesManager::startAnimatingNode( animationId, animatedNodeTag, std::move(endCallback), - config, + std::move(config), this); } break; case AnimationDriverType::Spring: { @@ -299,7 +299,7 @@ void NativeAnimatedNodesManager::startAnimatingNode( animationId, animatedNodeTag, std::move(endCallback), - config, + std::move(config), this); } break; case AnimationDriverType::Decay: { @@ -307,7 +307,7 @@ void NativeAnimatedNodesManager::startAnimatingNode( animationId, animatedNodeTag, std::move(endCallback), - config, + std::move(config), this); } break; } diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.h b/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.h index 883b70c8e71..1734b627502 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.h +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.h @@ -103,7 +103,7 @@ class NativeAnimatedNodesManager { void startAnimatingNode( int animationId, Tag animatedNodeTag, - const folly::dynamic& config, + folly::dynamic config, std::optional endCallback) noexcept; void stopAnimation( diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/DecayAnimationDriver.cpp b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/DecayAnimationDriver.cpp index 04a5d0d8df5..48ba5f159c8 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/DecayAnimationDriver.cpp +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/DecayAnimationDriver.cpp @@ -18,15 +18,15 @@ DecayAnimationDriver::DecayAnimationDriver( int id, Tag animatedValueTag, std::optional endCallback, - const folly::dynamic& config, + folly::dynamic config, NativeAnimatedNodesManager* manager) : AnimationDriver( id, animatedValueTag, std::move(endCallback), - config, + std::move(config), manager), - velocity_(config["velocity"].asDouble()), + velocity_(config_["velocity"].asDouble()), deceleration_(config_["deceleration"].asDouble()) { react_native_assert(deceleration_ > 0); } diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/DecayAnimationDriver.h b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/DecayAnimationDriver.h index 913ca4c309e..df94855f587 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/DecayAnimationDriver.h +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/DecayAnimationDriver.h @@ -21,7 +21,7 @@ class DecayAnimationDriver : public AnimationDriver { int id, Tag animatedValueTag, std::optional endCallback, - const folly::dynamic& config, + folly::dynamic config, NativeAnimatedNodesManager* manager); protected: diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/FrameAnimationDriver.cpp b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/FrameAnimationDriver.cpp index 5398648ea13..03f82a77652 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/FrameAnimationDriver.cpp +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/FrameAnimationDriver.cpp @@ -24,13 +24,13 @@ FrameAnimationDriver::FrameAnimationDriver( int id, Tag animatedValueTag, std::optional endCallback, - const folly::dynamic& config, + folly::dynamic config, NativeAnimatedNodesManager* manager) : AnimationDriver( id, animatedValueTag, std::move(endCallback), - config, + std::move(config), manager) { onConfigChanged(); } diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/FrameAnimationDriver.h b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/FrameAnimationDriver.h index 50e6271f409..c11c926948d 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/FrameAnimationDriver.h +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/FrameAnimationDriver.h @@ -21,7 +21,7 @@ class FrameAnimationDriver : public AnimationDriver { int id, Tag animatedValueTag, std::optional endCallback, - const folly::dynamic& config, + folly::dynamic config, NativeAnimatedNodesManager* manager); protected: diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/SpringAnimationDriver.cpp b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/SpringAnimationDriver.cpp index 8c19b641bf3..a759e999272 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/SpringAnimationDriver.cpp +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/SpringAnimationDriver.cpp @@ -21,13 +21,13 @@ SpringAnimationDriver::SpringAnimationDriver( int id, Tag animatedValueTag, std::optional endCallback, - const folly::dynamic& config, + folly::dynamic config, NativeAnimatedNodesManager* manager) : AnimationDriver( id, animatedValueTag, std::move(endCallback), - config, + std::move(config), manager), springStiffness_(config_["stiffness"].asDouble()), springDamping_(config_["damping"].asDouble()), diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/SpringAnimationDriver.h b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/SpringAnimationDriver.h index e87d222d778..87fe1e056a5 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/SpringAnimationDriver.h +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/drivers/SpringAnimationDriver.h @@ -21,7 +21,7 @@ class SpringAnimationDriver : public AnimationDriver { int id, Tag animatedValueTag, std::optional endCallback, - const folly::dynamic& config, + folly::dynamic config, NativeAnimatedNodesManager* manager); protected: