Move AnimationBackend initialization from Animated (#55103)

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

This diff decouples AnimationBackend from Animated. Now the backend is intialized in the Scheduler, from where it's passed to UIManager. Animation frontends (such as Animated) can then obtain a reference to the backend, and use it to schedule animation frame updates.

# Changelog
[General] [Changed] - Moved AnimationBackend initiailzation to `Scheduler`
[General] [Added] - `AnimationChoreographer` interface with an implementation for fantom tests

Reviewed By: zeyap

Differential Revision: D89663251

fbshipit-source-id: 428a83d78ef92a89095989fe3121c578cf8d3983
This commit is contained in:
Bartlomiej Bloniarz authored and meta-codesync[bot] committed 2026-01-20 02:28:23 -08:00
1 parent 5a70daa80d
commit f8564b47fd
24 files changed
+244 -101

No files matched your search

@@ -0,0 +1,27 @@
/*
* 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.
*/
#include "TesterAnimationChoreographer.h"
#include <react/renderer/core/ReactPrimitives.h>
#include <react/runtime/ReactInstanceConfig.h>
namespace facebook::react {
void TesterAnimationChoreographer::resume() {
isPaused_ = false;
}
void TesterAnimationChoreographer::pause() {
isPaused_ = true;
}
void TesterAnimationChoreographer::runUITick(float timestamp) {
if (!isPaused_) {
onAnimationFrame(timestamp);
}
}
} // namespace facebook::react
@@ -0,0 +1,26 @@
/*
* 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 <react/renderer/animationbackend/AnimationChoreographer.h>
#include <react/renderer/core/ReactPrimitives.h>
#include <react/runtime/ReactInstanceConfig.h>
namespace facebook::react {
class TesterAnimationChoreographer : public AnimationChoreographer {
public:
void resume() override;
void pause() override;
void runUITick(float timestamp);
private:
bool isPaused_{false};
};
} // namespace facebook::react
@@ -18,6 +18,7 @@
#include <folly/json.h>
#include <glog/logging.h>
#include <logger/react_native_log.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/io/ImageLoaderModule.h>
#include <react/logging/DefaultOnJsErrorHandler.h>
#include <react/nativemodule/cputime/NativeCPUTime.h>
@@ -109,11 +110,19 @@ TesterAppDelegate::TesterAppDelegate(
g_setNativeAnimatedNowTimestampFunction(StubClock::now);
auto provider = std::make_shared<NativeAnimatedNodesManagerProvider>(
[this](std::function<void()>&& onRender, bool /*isAsync*/) {
onAnimationRender_ = std::move(onRender);
},
[this](bool /*isAsync*/) { onAnimationRender_ = nullptr; });
std::shared_ptr<NativeAnimatedNodesManagerProvider> provider;
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
provider = std::make_shared<NativeAnimatedNodesManagerProvider>();
} else {
provider = std::make_shared<NativeAnimatedNodesManagerProvider>(
[this](std::function<void()>&& onRender, bool /*isAsync*/) {
onAnimationRender_ = std::move(onRender);
},
[this](bool /*isAsync*/) { onAnimationRender_ = nullptr; });
}
animationChoreographer_ = std::make_shared<TesterAnimationChoreographer>();
reactHost_ = std::make_unique<ReactHost>(
reactInstanceConfig,
@@ -125,7 +134,9 @@ TesterAppDelegate::TesterAppDelegate(
nullptr,
turboModuleProviders,
nullptr,
std::move(provider));
std::move(provider),
nullptr,
animationChoreographer_);
// Ensure that the ReactHost initialisation is completed.
// This will call `setupJSNativeFantom`.
@@ -253,7 +264,12 @@ void TesterAppDelegate::produceFramesForDuration(double milliseconds) {
}
void TesterAppDelegate::runUITick() {
if (onAnimationRender_) {
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(
StubClock::now().time_since_epoch())
.count();
animationChoreographer_->runUITick(static_cast<float>(microseconds) / 1000);
} else if (onAnimationRender_) {
onAnimationRender_();
}
}
@@ -13,6 +13,7 @@
#include <string>
#include <vector>
#include "TesterAnimationChoreographer.h"
#include "TesterMountingManager.h"
namespace facebook::jsi {
@@ -72,6 +73,8 @@ class TesterAppDelegate {
std::shared_ptr<TesterMountingManager> mountingManager_;
std::shared_ptr<TesterAnimationChoreographer> animationChoreographer_;
private:
void runUITick();