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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,10 @@ public void doFrameGuarded(long frameTimeNanos) {
schedule();
}

if (ReactNativeFeatureFlags.useSharedAnimatedBackend() && mBinding != null) {
mBinding.driveAnimationBackend(frameTimeNanos);
}

mSynchronousEvents.clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,12 @@ internal class FabricUIManagerBinding : HybridClassBase() {

external fun driveCxxAnimations()

external fun driveAnimationBackend(frameTimeMs: Double)
external fun driveAnimationBackend(frameTimeNanos: Long)

external fun drainPreallocateViewsQueue()

external fun reportMount(surfaceId: Int)

external fun setAnimationBackendChoreographer(
animationBackendChoreographer: AnimationBackendChoreographer
)

external fun mergeReactRevision(surfaceId: Int)

fun register(
Expand All @@ -97,13 +93,8 @@ internal class FabricUIManagerBinding : HybridClassBase() {
fabricUIManager: FabricUIManager,
eventBeatManager: EventBeatManager,
componentFactory: ComponentFactory,
animationBackendChoreographer: AnimationBackendChoreographer,
) {
fabricUIManager.setBinding(this)
animationBackendChoreographer.frameCallback = AnimationFrameCallback { frameTimeMs: Double ->
driveAnimationBackend(frameTimeMs)
}
setAnimationBackendChoreographer(animationBackendChoreographer)

installFabricUIManager(
runtimeExecutor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,13 @@ public class FabricUIManagerProviderImpl(
val runtimeExecutor = catalystInstance?.runtimeExecutor
val runtimeScheduler = catalystInstance?.runtimeScheduler

val animationBackendChoreographer = AnimationBackendChoreographer(context)

if (runtimeExecutor != null && runtimeScheduler != null) {
binding.register(
runtimeExecutor,
runtimeScheduler,
fabricUIManager,
eventBeatManager,
componentFactory,
animationBackendChoreographer,
)
} else {
throw IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.devsupport.InspectorFlags.getIsProfilingBuild
import com.facebook.react.devsupport.StackTraceHelper
import com.facebook.react.devsupport.interfaces.DevSupportManager
import com.facebook.react.fabric.AnimationBackendChoreographer
import com.facebook.react.fabric.ComponentFactory
import com.facebook.react.fabric.FabricUIManager
import com.facebook.react.fabric.FabricUIManagerBinding
Expand Down Expand Up @@ -259,16 +258,13 @@ internal class ReactInstance(
// Misc initialization that needs to be done before Fabric init
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(context)

val animationBackendChoreographer = AnimationBackendChoreographer(context)

val binding = FabricUIManagerBinding()
binding.register(
getBufferedRuntimeExecutor(),
getRuntimeScheduler(),
fabricUIManager,
eventBeatManager,
componentFactory,
animationBackendChoreographer,
)

// Initialize the FabricUIManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@

#pragma once

#include <fbjni/fbjni.h>
#include <react/renderer/animationbackend/AnimationChoreographer.h>

#include "JAnimationBackendChoreographer.h"
#include <atomic>

namespace facebook::react {

class AndroidAnimationChoreographer : public AnimationChoreographer {
public:
explicit AndroidAnimationChoreographer(jni::alias_ref<JAnimationBackendChoreographer> jChoreographer)
: jChoreographer_(jni::make_global(jChoreographer))
void resume() override
{
active_.store(true);
}

void resume() override
void pause() override
{
jChoreographer_->resume();
active_.store(false);
}

void pause() override
void onAnimationFrameIfActive(AnimationTimestamp timestamp) const
{
jChoreographer_->pause();
if (active_.load()) {
onAnimationFrame(timestamp);
}
}

private:
jni::global_ref<JAnimationBackendChoreographer> jChoreographer_;
std::atomic_bool active_{false};
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ void FabricUIManagerBinding::driveCxxAnimations() {
scheduler->animationTick();
}

void FabricUIManagerBinding::driveAnimationBackend(jdouble frameTimeMs) {
animationChoreographer_->onAnimationFrame(AnimationTimestamp{frameTimeMs});
void FabricUIManagerBinding::driveAnimationBackend(jlong frameTimeNanos) {
if (!animationChoreographer_) {
LOG(ERROR)
<< "FabricUIManagerBinding::driveAnimationBackend: animation choreographer disappeared";
return;
}
auto frameTimeMs = static_cast<double>(frameTimeNanos) / 1000000.0;
animationChoreographer_->onAnimationFrameIfActive(
AnimationTimestamp{frameTimeMs});
}

void FabricUIManagerBinding::drainPreallocateViewsQueue() {
Expand Down Expand Up @@ -572,6 +579,8 @@ void FabricUIManagerBinding::installFabricUIManager(

contextContainer->insert("FabricUIManager", globalJavaUiManager);

animationChoreographer_ = std::make_shared<AndroidAnimationChoreographer>();

auto toolbox = SchedulerToolbox{};
toolbox.contextContainer = contextContainer;
toolbox.componentRegistryFactory = componentsRegistry->buildRegistryFunction;
Expand All @@ -583,9 +592,6 @@ void FabricUIManagerBinding::installFabricUIManager(

toolbox.eventBeatFactory = eventBeatFactory;

react_native_assert(
animationChoreographer_ != nullptr &&
"AnimationChoreographer is nullptr");
toolbox.animationChoreographer = animationChoreographer_;

animationDriver_ = std::make_shared<LayoutAnimationDriver>(
Expand All @@ -604,6 +610,7 @@ void FabricUIManagerBinding::uninstallFabricUIManager() {
std::unique_lock lock(installMutex_);
animationDriver_ = nullptr;
scheduler_ = nullptr;
animationChoreographer_ = nullptr;
mountingManager_ = nullptr;
}

Expand Down Expand Up @@ -875,19 +882,9 @@ void FabricUIManagerBinding::registerNatives() {
makeNativeMethod(
"getRelativeAncestorList",
FabricUIManagerBinding::getRelativeAncestorList),
makeNativeMethod(
"setAnimationBackendChoreographer",
FabricUIManagerBinding::setAnimationBackendChoreographer),
makeNativeMethod(
"mergeReactRevision", FabricUIManagerBinding::mergeReactRevision),
});
}

void FabricUIManagerBinding::setAnimationBackendChoreographer(
jni::alias_ref<JAnimationBackendChoreographer::javaobject>
animationBackendChoreographer) {
animationChoreographer_ = std::make_shared<AndroidAnimationChoreographer>(
animationBackendChoreographer);
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class FabricUIManagerBinding : public jni::HybridClass<FabricUIManagerBinding>,

void driveCxxAnimations();

void driveAnimationBackend(jdouble frameTimeMs);
void driveAnimationBackend(jlong frameTimeNanos);

void drainPreallocateViewsQueue();

Expand Down Expand Up @@ -168,8 +168,6 @@ class FabricUIManagerBinding : public jni::HybridClass<FabricUIManagerBinding>,
bool enableFabricLogs_{false};

std::shared_ptr<AndroidAnimationChoreographer> animationChoreographer_;

void setAnimationBackendChoreographer(jni::alias_ref<JAnimationBackendChoreographer::javaobject> animationBackend);
};

} // namespace facebook::react

This file was deleted.

This file was deleted.

8 changes: 1 addition & 7 deletions scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -1245,9 +1245,9 @@ class facebook::react::AdditionAnimatedNode : public facebook::react::OperatorAn
}

class facebook::react::AndroidAnimationChoreographer : public facebook::react::AnimationChoreographer {
public AndroidAnimationChoreographer(jni::alias_ref<facebook::react::JAnimationBackendChoreographer> jChoreographer);
public virtual void pause() override;
public virtual void resume() override;
public void onAnimationFrameIfActive(facebook::react::AnimationTimestamp timestamp) const;
}

class facebook::react::AndroidDrawerLayoutEventEmitter : public facebook::react::BaseViewEventEmitter {
Expand Down Expand Up @@ -2780,12 +2780,6 @@ class facebook::react::IntersectionObserverState {
public static facebook::react::IntersectionObserverState NotIntersecting();
}

class facebook::react::JAnimationBackendChoreographer : public facebook::jni::JavaClass<facebook::react::JAnimationBackendChoreographer> {
public static constexpr auto kJavaDescriptor;
public void pause() const;
public void resume() const;
}

class facebook::react::JBindingsInstaller : public jni::HybridClass<facebook::react::JBindingsInstaller>, public facebook::react::BindingsInstaller {
public static constexpr auto kJavaDescriptor;
public ~JBindingsInstaller();
Expand Down
Loading
Loading