Expose the backend via UIManager (#53995)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53995

### Summary

Exposes the animation backend via UIManager by introducing two new methods: `unstable_setAnimationBackend` and `unstable_getAnimationBackend`. The `NativeAnimatedNodesManagerProvider` is updated to initialize the animation backend using the `useSharedAnimatedBackend` feature flag.

## Changelog:

[GENERAL] [ADDED] - unstable_setAnimationBackend, unstable_getAnimationBackend in UIManager
[GENRAL] [CHANGED] - call unstable_setAnimationBackend in NativeAnimatedNodesManager

Reviewed By: zeyap

Differential Revision: D81137954

fbshipit-source-id: b9a45b1d1e694e28865c27181bcbd578c1b7b9a0
This commit is contained in:
Bartlomiej Bloniarz authored and Facebook GitHub Bot committed 2025-10-01 04:15:11 -07:00
1 parent 3f396616d2
commit 7ec470d49a
3 files changed
+19

No files matched your search

@@ -66,6 +66,8 @@ NativeAnimatedNodesManagerProvider::getOrCreate(
};
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
// TODO: this should be initialized outside of animated, but for now it
// was convenient to do it here
animationBackend_ = std::make_shared<AnimationBackend>(
std::move(startOnRenderCallback_),
std::move(stopOnRenderCallback_),
@@ -73,6 +75,8 @@ NativeAnimatedNodesManagerProvider::getOrCreate(
nativeAnimatedNodesManager_ =
std::make_shared<NativeAnimatedNodesManager>(animationBackend_);
uiManager->unstable_setAnimationBackend(animationBackend_);
} else {
nativeAnimatedNodesManager_ =
std::make_shared<NativeAnimatedNodesManager>(
@@ -678,6 +678,15 @@ void UIManager::setNativeAnimatedDelegate(
nativeAnimatedDelegate_ = delegate;
}
void UIManager::unstable_setAnimationBackend(
std::weak_ptr<AnimationBackend> animationBackend) {
animationBackend_ = animationBackend;
}
std::weak_ptr<AnimationBackend> UIManager::unstable_getAnimationBackend() {
return animationBackend_;
}
void UIManager::animationTick() const {
if (animationDelegate_ != nullptr &&
animationDelegate_->shouldAnimateFrame()) {
@@ -36,6 +36,7 @@ namespace facebook::react {
class UIManagerBinding;
class UIManagerCommitHook;
class UIManagerMountHook;
class AnimationBackend;
class UIManager final : public ShadowTreeDelegate {
public:
@@ -62,6 +63,9 @@ class UIManager final : public ShadowTreeDelegate {
* the pointer before being destroyed.
*/
void setAnimationDelegate(UIManagerAnimationDelegate* delegate);
void unstable_setAnimationBackend(
std::weak_ptr<AnimationBackend> animationBackend);
std::weak_ptr<AnimationBackend> unstable_getAnimationBackend();
/**
* Execute stopSurface on any UIMAnagerAnimationDelegate.
@@ -258,6 +262,8 @@ class UIManager final : public ShadowTreeDelegate {
std::unique_ptr<LazyShadowTreeRevisionConsistencyManager>
lazyShadowTreeRevisionConsistencyManager_;
std::weak_ptr<AnimationBackend> animationBackend_;
};
} // namespace facebook::react