Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ NativeAnimatedNodesManager::NativeAnimatedNodesManager(
StartOnRenderCallback&& startOnRenderCallback,
StopOnRenderCallback&& stopOnRenderCallback,
FrameRateListenerCallback&& frameRateListenerCallback) noexcept
: directManipulationCallback_(std::move(directManipulationCallback)),
: useSharedAnimatedBackend_(false),
directManipulationCallback_(std::move(directManipulationCallback)),
fabricCommitCallback_(std::move(fabricCommitCallback)),
resolvePlatformColor_(std::move(resolvePlatformColor)),
startOnRenderCallback_(std::move(startOnRenderCallback)),
Expand All @@ -97,7 +98,7 @@ NativeAnimatedNodesManager::NativeAnimatedNodesManager(

NativeAnimatedNodesManager::NativeAnimatedNodesManager(
std::shared_ptr<UIManagerAnimationBackend> animationBackend) noexcept
: animationBackend_(animationBackend) {}
: animationBackend_(animationBackend), useSharedAnimatedBackend_(true) {}

NativeAnimatedNodesManager::~NativeAnimatedNodesManager() noexcept {
stopRenderCallbackIfNeeded(true);
Expand Down Expand Up @@ -256,7 +257,7 @@ void NativeAnimatedNodesManager::disconnectAnimatedNodeFromView(
auto node = getAnimatedNode<PropsAnimatedNode>(propsNodeTag);
if (node != nullptr) {
node->disconnectFromView(viewTag);
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (useSharedAnimatedBackend_) {
node->disconnectFromShadowNodeFamily();
}
{
Expand Down Expand Up @@ -521,7 +522,7 @@ void NativeAnimatedNodesManager::handleAnimatedEvent(
// That's why, in case this is called from the UI thread, we need to
// proactivelly trigger the animation loop to avoid showing stale
// frames.
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (useSharedAnimatedBackend_) {
if (auto animationBackend = animationBackend_.lock()) {
animationBackend->pushAnimationMutations(
[this](AnimationTimestamp timestamp) -> AnimationMutations {
Expand Down Expand Up @@ -561,7 +562,7 @@ void NativeAnimatedNodesManager::startRenderCallbackIfNeeded(bool isAsync) {
return;
}

if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (useSharedAnimatedBackend_) {
if (auto animationBackend = animationBackend_.lock()) {
auto weak = weak_from_this();
animationBackendCallbackId_ = animationBackend->start(
Expand Down Expand Up @@ -589,7 +590,7 @@ void NativeAnimatedNodesManager::stopRenderCallbackIfNeeded(
// stopRenderCallbackIfNeeded is always called from the UI thread.
auto isRenderCallbackStarted = isRenderCallbackStarted_.exchange(false);

if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (useSharedAnimatedBackend_) {
if (isRenderCallbackStarted) {
if (auto animationBackend = animationBackend_.lock()) {
animationBackend->stop(animationBackendCallbackId_);
Expand Down Expand Up @@ -922,7 +923,7 @@ void NativeAnimatedNodesManager::schedulePropsCommit(
bool layoutStyleUpdated,
bool forceFabricCommit,
ShadowNodeFamily::Weak shadowNodeFamily) noexcept {
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (useSharedAnimatedBackend_) {
if (forceFabricCommit) {
shouldRequestAsyncFlush_.insert(viewTag);
}
Expand Down Expand Up @@ -1029,7 +1030,7 @@ AnimationMutations NativeAnimatedNodesManager::onAnimationFrameForBackend(

AnimationMutations NativeAnimatedNodesManager::pullAnimationMutations(
AnimationTimestamp timestamp) {
if (!ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (!useSharedAnimatedBackend_) {
return {};
}
TraceSection s(
Expand Down Expand Up @@ -1119,7 +1120,7 @@ void NativeAnimatedNodesManager::flushAnimatedNodesCreatedAsync() noexcept {
}

void NativeAnimatedNodesManager::onRender() {
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (useSharedAnimatedBackend_) {
return;
}
TraceSection s(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ class NativeAnimatedNodesManager : public std::enable_shared_from_this<NativeAni
NativeAnimatedNodesManager(NativeAnimatedNodesManager &&) = delete;
NativeAnimatedNodesManager &operator=(NativeAnimatedNodesManager &&) = delete;

// Whether this instance was constructed to use the shared AnimationBackend.
// Latched at construction, so it is immune to later flips of the
// process-global useSharedAnimatedBackend() flag.
bool useSharedAnimatedBackend() const noexcept
{
return useSharedAnimatedBackend_;
}

template <typename T, typename = std::enable_if_t<std::is_base_of_v<AnimatedNode, T>>>
T *getAnimatedNode(Tag tag) const
requires(std::is_base_of_v<AnimatedNode, T>)
Expand Down Expand Up @@ -219,6 +227,12 @@ class NativeAnimatedNodesManager : public std::enable_shared_from_this<NativeAni

std::weak_ptr<UIManagerAnimationBackend> animationBackend_;

// Latched per-instance copy of which backend this manager uses, set from the
// constructor that ran (true for the shared-AnimationBackend ctor). Reads stay
// stable even when the global useSharedAnimatedBackend() flag is re-overridden
// on another RN runtime.
const bool useSharedAnimatedBackend_;

std::unique_ptr<AnimatedNode> animatedNode(Tag tag, const folly::dynamic &config) noexcept;

static thread_local bool isOnRenderThread_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "NativeAnimatedNodesManagerProvider.h"

#include <glog/logging.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/animated/MergedValueDispatcher.h>
#include <react/renderer/animated/internal/AnimatedMountingOverrideDelegate.h>
#include <react/renderer/animated/internal/primitives.h>
Expand Down Expand Up @@ -51,8 +50,9 @@ NativeAnimatedNodesManagerProvider::getOrCreate(

auto* uiManager = &UIManagerBinding::getBinding(runtime)->getUIManager();

if (!ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
// === PATH 1: Legacy Backend (useSharedAnimatedBackend = false) ===
auto animationBackend = uiManager->unstable_getAnimationBackend().lock();
if (animationBackend == nullptr) {
// === PATH 1: Legacy Backend (no shared AnimationBackend attached) ===
// Uses the architecture with MergedValueDispatcher and
// AnimatedMountingOverrideDelegate

Expand Down Expand Up @@ -130,13 +130,10 @@ NativeAnimatedNodesManagerProvider::getOrCreate(

uiManager->setNativeAnimatedDelegate(nativeAnimatedDelegate_);
} else {
// === PATH 2: Shared AnimationBackend (useSharedAnimatedBackend = true) ===
// === PATH 2: Shared AnimationBackend ===
// Uses the shared AnimationBackend from UIManager. The backend handles all
// animation commits and platform integration internally.

auto animationBackend = uiManager->unstable_getAnimationBackend().lock();
react_native_assert(
animationBackend != nullptr && "animationBackend is nullptr");
// animation commits and platform integration internally. It is guaranteed
// non-null here because it was successfully locked above.
animationBackend->registerJSInvoker(jsInvoker);

nativeAnimatedNodesManager_ =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "PropsAnimatedNode.h"

#include <react/debug/react_native_assert.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/animated/NativeAnimatedNodesManager.h>
#include <react/renderer/animated/nodes/ColorAnimatedNode.h>
#include <react/renderer/animated/nodes/ObjectAnimatedNode.h>
Expand Down Expand Up @@ -84,7 +83,7 @@ void PropsAnimatedNode::disconnectFromView(Tag viewTag) {
void PropsAnimatedNode::restoreDefaultValues() {
// If node is already disconnected from View, we cannot restore default values
if (connectedViewTag_ != animated::undefinedAnimatedNodeIdentifier) {
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (manager_->useSharedAnimatedBackend()) {
manager_->schedulePropsCommit(
connectedViewTag_,
folly::dynamic::object(),
Expand Down Expand Up @@ -166,7 +165,7 @@ void PropsAnimatedNode::update(bool forceFabricCommit) {

layoutStyleUpdated_ = isLayoutStyleUpdated(getConfig()["props"], *manager_);

if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
if (manager_->useSharedAnimatedBackend()) {
manager_->schedulePropsCommit(
connectedViewTag_,
props_,
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -3491,6 +3491,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -3375,6 +3375,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -3488,6 +3488,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -5710,6 +5710,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -5622,6 +5622,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -5707,6 +5707,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
1 change: 1 addition & 0 deletions scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr
public bool commitProps();
public bool hasManagedProps() const noexcept;
public bool isOnRenderThread() const noexcept;
public bool useSharedAnimatedBackend() const noexcept;
public facebook::react::AnimationMutations onAnimationFrameForBackend(facebook::react::AnimatedPropsBuilder& propsBuilder, facebook::react::AnimationTimestamp timestamp);
public facebook::react::AnimationMutations pullAnimationMutations(facebook::react::AnimationTimestamp timestamp);
public facebook::react::NativeAnimatedNodesManager& operator=(const facebook::react::NativeAnimatedNodesManager&) = delete;
Expand Down
Loading