Skip to content

Commit 471c612

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
Construct the shared animation backend after the UIManager has a delegate (#57817)
Summary: Pull Request resolved: #57817 ## Changelog: [Internal] - Construct the shared animation backend after the UIManager has a delegate `AnimationBackend`'s constructor calls `UIManager::addOnSurfaceStartCallback` so that `AnimatedPropsRegistry::initializeSurface` runs for each surface as it starts. That call is a no-op unless the `UIManager` already has a delegate: ``` void UIManager::addOnSurfaceStartCallback( UIManagerDelegate::OnSurfaceStartCallback&& callback) { if (delegate_ != nullptr) { delegate_->uiManagerShouldAddOnSurfaceStartCallback(std::move(callback)); } } ``` `Scheduler`'s constructor was building the backend immediately after constructing the `UIManager` and roughly seventy lines before `uiManager->setDelegate(this)`, so the callback was dropped every time and `Scheduler::onSurfaceStartCallbacks_` never received it. `AnimatedPropsRegistry::update` skips surfaces missing from `surfaceContexts_`, so correctness was left resting on `getMap()` default-constructing the entry via `operator[]` — that is, on a commit hook happening to run before the first animated update on a freshly started surface. When that ordering does not hold, early animated updates on a new surface are dropped. Move the backend construction to just after `setDelegate`, and add a comment recording the ordering constraint. This is still well before any surface can start, so the registry is populated for every surface from the first frame. The neighbouring `getShadowTreeRegistry().enumerate(...)` in the same constructor is also dead today — the `UIManager` is two lines old and its registry is necessarily empty — but it is left in place deliberately. It mirrors the enumerate-then-register pattern in `NativeAnimatedNodesManagerProvider` and `ViewTransitionModule`, both of which are constructed lazily and do need it, and it keeps `AnimationBackend`'s constructor correct if it is ever moved to a lazy call site. Reviewed By: christophpurrer Differential Revision: D114759538 fbshipit-source-id: f3eeab96d2ca1ada4feaf85d49a3f0ac169f3115
1 parent f7a8360 commit 471c612

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

  • packages/react-native/ReactCommon/react/renderer/scheduler

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,6 @@ Scheduler::Scheduler(
5959
auto uiManager =
6060
std::make_shared<UIManager>(runtimeExecutor_, contextContainer_);
6161

62-
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
63-
auto animationBackend = std::make_shared<AnimationBackend>(
64-
schedulerToolbox.animationChoreographer, uiManager);
65-
66-
schedulerToolbox.animationChoreographer->setAnimationBackend(
67-
animationBackend);
68-
69-
uiManager->unstable_setAnimationBackend(animationBackend);
70-
}
71-
7262
auto eventOwnerBox = std::make_shared<EventBeat::OwnerBox>();
7363
eventOwnerBox->owner = eventDispatcher_;
7464

@@ -131,6 +121,19 @@ Scheduler::Scheduler(
131121
uiManager->setDelegate(this);
132122
uiManager->setComponentDescriptorRegistry(componentDescriptorRegistry_);
133123

124+
// Must come after `setDelegate`: the backend's constructor registers a
125+
// surface-start callback, and `UIManager` silently drops those while it has
126+
// no delegate.
127+
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
128+
auto animationBackend = std::make_shared<AnimationBackend>(
129+
schedulerToolbox.animationChoreographer, uiManager);
130+
131+
schedulerToolbox.animationChoreographer->setAnimationBackend(
132+
animationBackend);
133+
134+
uiManager->unstable_setAnimationBackend(animationBackend);
135+
}
136+
134137
auto bindingsExecutor =
135138
schedulerToolbox.bridgelessBindingsExecutor.has_value()
136139
? schedulerToolbox.bridgelessBindingsExecutor.value()

0 commit comments

Comments
 (0)