From 3cf40247d45c6e462d8da68ba17eff97318ba0d3 Mon Sep 17 00:00:00 2001 From: Zeya Peng Date: Thu, 16 Apr 2026 08:53:31 -0700 Subject: [PATCH] Add startViewTransitionReadyFinished callback (#56461) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56461 ## Changelog: [Internal] [Added] - Add startViewTransitionReadyFinished callback Add `startViewTransitionReadyFinished()` to the view transition delegate so the reconciler can notify the native side when the ready callback's async work (e.g. spawned work from the `ready` promise `.then` - which includes invoking view transition event callbacks, starting animations from these callbacks) has completed. This was previously not capturable from the C++ side since `onReadyCallback` resolves the JS promise synchronously but the reconciler's follow-up work runs as a microtask. - Add `startViewTransitionReadyFinished` to `UIManagerViewTransitionDelegate` and `ViewTransitionModule` - Expose as a method on `nativeFabricUIManager` via `UIManagerBinding` - Track `transitionReadyFinished_` state, reset to `false` before `onReadyCallback` and set to `true` when the reconciler calls back Reviewed By: sammy-SC Differential Revision: D99443648 fbshipit-source-id: 042f288c90d7548789185f7f0e46be73a12dcab4 --- .../renderer/uimanager/UIManagerBinding.cpp | 18 ++++++++++++++++++ .../UIManagerViewTransitionDelegate.h | 2 ++ .../viewtransition/ViewTransitionModule.cpp | 6 +++++- .../viewtransition/ViewTransitionModule.h | 4 ++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index 3735852dc41..c79fc75df5b 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -1092,6 +1092,24 @@ jsi::Value UIManagerBinding::get( }); } + if (methodName == "startViewTransitionReadyFinished") { + return jsi::Function::createFromHostFunction( + runtime, + name, + 0, + [uiManager]( + jsi::Runtime& runtime, + const jsi::Value& /*thisValue*/, + const jsi::Value* /*arguments*/, + size_t /*count*/) -> jsi::Value { + auto* viewTransitionDelegate = uiManager->getViewTransitionDelegate(); + if (viewTransitionDelegate != nullptr) { + viewTransitionDelegate->startViewTransitionReadyFinished(); + } + return jsi::Value::undefined(); + }); + } + if (methodName == "startViewTransition") { auto paramCount = 1; return jsi::Function::createFromHostFunction( diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerViewTransitionDelegate.h b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerViewTransitionDelegate.h index a21cd4e3d00..e8210799212 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerViewTransitionDelegate.h +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerViewTransitionDelegate.h @@ -41,6 +41,8 @@ class UIManagerViewTransitionDelegate { { } + virtual void startViewTransitionReadyFinished() {} + virtual void startViewTransitionEnd() {} struct ViewTransitionInstance { diff --git a/packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.cpp b/packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.cpp index 2aa9e80f083..3cda3cdc4d5 100644 --- a/packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.cpp +++ b/packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.cpp @@ -353,7 +353,7 @@ void ViewTransitionModule::startViewTransition( } applySnapshotsOnPseudoElementShadowNodes(); - + transitionReadyFinished_ = false; if (onReadyCallback) { onReadyCallback(); } @@ -366,6 +366,10 @@ void ViewTransitionModule::startViewTransition( } } +void ViewTransitionModule::startViewTransitionReadyFinished() { + transitionReadyFinished_ = true; +} + void ViewTransitionModule::suspendOnActiveViewTransition() { // Signal that the next transition should be suspended until the current // one finishes. The actual queueing happens in startViewTransition. diff --git a/packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.h b/packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.h index 7e8a332ee24..33331ba3c4f 100644 --- a/packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.h +++ b/packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.h @@ -53,6 +53,8 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate, std::function onReadyCallback, std::function onCompleteCallback) override; + void startViewTransitionReadyFinished() override; + void startViewTransitionEnd() override; std::optional getViewTransitionInstance(const std::string &name, const std::string &pseudo) @@ -128,6 +130,8 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate, bool transitionStarted_{false}; + bool transitionReadyFinished_{false}; + // When suspendNextTransition_ is true and a transition is active, the next // startViewTransition calls are queued instead of running immediately. bool suspendNextTransition_{false};