Skip to content

Commit 7ec470d

Browse files
Bartlomiej Bloniarzfacebook-github-bot
authored andcommitted
Expose the backend via UIManager (#53995)
Summary: Pull Request resolved: #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
1 parent 3f39661 commit 7ec470d

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManagerProvider.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,17 @@ NativeAnimatedNodesManagerProvider::getOrCreate(
6666
};
6767

6868
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
69+
// TODO: this should be initialized outside of animated, but for now it
70+
// was convenient to do it here
6971
animationBackend_ = std::make_shared<AnimationBackend>(
7072
std::move(startOnRenderCallback_),
7173
std::move(stopOnRenderCallback_),
7274
std::move(directManipulationCallback));
7375

7476
nativeAnimatedNodesManager_ =
7577
std::make_shared<NativeAnimatedNodesManager>(animationBackend_);
78+
79+
uiManager->unstable_setAnimationBackend(animationBackend_);
7680
} else {
7781
nativeAnimatedNodesManager_ =
7882
std::make_shared<NativeAnimatedNodesManager>(

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,15 @@ void UIManager::setNativeAnimatedDelegate(
678678
nativeAnimatedDelegate_ = delegate;
679679
}
680680

681+
void UIManager::unstable_setAnimationBackend(
682+
std::weak_ptr<AnimationBackend> animationBackend) {
683+
animationBackend_ = animationBackend;
684+
}
685+
686+
std::weak_ptr<AnimationBackend> UIManager::unstable_getAnimationBackend() {
687+
return animationBackend_;
688+
}
689+
681690
void UIManager::animationTick() const {
682691
if (animationDelegate_ != nullptr &&
683692
animationDelegate_->shouldAnimateFrame()) {

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace facebook::react {
3636
class UIManagerBinding;
3737
class UIManagerCommitHook;
3838
class UIManagerMountHook;
39+
class AnimationBackend;
3940

4041
class UIManager final : public ShadowTreeDelegate {
4142
public:
@@ -62,6 +63,9 @@ class UIManager final : public ShadowTreeDelegate {
6263
* the pointer before being destroyed.
6364
*/
6465
void setAnimationDelegate(UIManagerAnimationDelegate* delegate);
66+
void unstable_setAnimationBackend(
67+
std::weak_ptr<AnimationBackend> animationBackend);
68+
std::weak_ptr<AnimationBackend> unstable_getAnimationBackend();
6569

6670
/**
6771
* Execute stopSurface on any UIMAnagerAnimationDelegate.
@@ -258,6 +262,8 @@ class UIManager final : public ShadowTreeDelegate {
258262

259263
std::unique_ptr<LazyShadowTreeRevisionConsistencyManager>
260264
lazyShadowTreeRevisionConsistencyManager_;
265+
266+
std::weak_ptr<AnimationBackend> animationBackend_;
261267
};
262268

263269
} // namespace facebook::react

0 commit comments

Comments
 (0)