diff --git a/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp b/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp index 349d2c60f5e8ff..19052d7e4dc5e7 100644 --- a/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include namespace facebook::react { diff --git a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h index e8991c5ad6afa0..b4eea2d64c3368 100644 --- a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h +++ b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include "AnimatedProps.h" @@ -24,16 +25,17 @@ struct AnimationMutation { }; using AnimationMutations = std::vector; -using Callback = std::function; -using StartOnRenderCallback = std::function&&)>; -using StopOnRenderCallback = std::function; -using DirectManipulationCallback = - std::function; -using FabricCommitCallback = - std::function&)>; - -class AnimationBackend { + +class AnimationBackend : public UIManagerAnimationBackend { public: + using Callback = std::function; + using StartOnRenderCallback = std::function&&)>; + using StopOnRenderCallback = std::function; + using DirectManipulationCallback = + std::function; + using FabricCommitCallback = + std::function&)>; + std::vector callbacks; const StartOnRenderCallback startOnRenderCallback_; const StopOnRenderCallback stopOnRenderCallback_; @@ -53,8 +55,8 @@ class AnimationBackend { void synchronouslyUpdateProps( const std::unordered_map& updates); - void onAnimationFrame(double timestamp); + void onAnimationFrame(double timestamp) override; void start(const Callback& callback); - void stop(); + void stop() override; }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp index 22eec48f8edb31..02586f16e89ca1 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp @@ -679,11 +679,12 @@ void UIManager::setNativeAnimatedDelegate( } void UIManager::unstable_setAnimationBackend( - std::weak_ptr animationBackend) { + std::weak_ptr animationBackend) { animationBackend_ = animationBackend; } -std::weak_ptr UIManager::unstable_getAnimationBackend() { +std::weak_ptr +UIManager::unstable_getAnimationBackend() { return animationBackend_; } diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h index af6a32b8081c62..ebdc1d260f7b11 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,6 @@ namespace facebook::react { class UIManagerBinding; class UIManagerCommitHook; class UIManagerMountHook; -class AnimationBackend; class UIManager final : public ShadowTreeDelegate { public: @@ -63,9 +63,13 @@ class UIManager final : public ShadowTreeDelegate { * the pointer before being destroyed. */ void setAnimationDelegate(UIManagerAnimationDelegate* delegate); + + /** + * Sets and gets UIManager's AnimationBackend reference. + */ void unstable_setAnimationBackend( - std::weak_ptr animationBackend); - std::weak_ptr unstable_getAnimationBackend(); + std::weak_ptr animationBackend); + std::weak_ptr unstable_getAnimationBackend(); /** * Execute stopSurface on any UIMAnagerAnimationDelegate. @@ -263,7 +267,7 @@ class UIManager final : public ShadowTreeDelegate { std::unique_ptr lazyShadowTreeRevisionConsistencyManager_; - std::weak_ptr animationBackend_; + std::weak_ptr animationBackend_; }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationBackend.h b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationBackend.h new file mode 100644 index 00000000000000..66fe349529c4d2 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationBackend.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook::react { + +class UIManagerAnimationBackend { + public: + virtual ~UIManagerAnimationBackend() = default; + + virtual void onAnimationFrame(double timestamp) = 0; + // TODO: T240293839 Move over start() function and mutation types + virtual void stop() = 0; +}; + +} // namespace facebook::react