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
This commit is contained in:
Zeya Peng authored and meta-codesync[bot] committed 2026-04-16 08:53:31 -07:00
1 parent fd0bc698b0
commit 3cf40247d4
4 files changed
+29 -1

No files matched your search

@@ -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(
@@ -41,6 +41,8 @@ class UIManagerViewTransitionDelegate {
{
}
virtual void startViewTransitionReadyFinished() {}
virtual void startViewTransitionEnd() {}
struct ViewTransitionInstance {
@@ -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.
@@ -53,6 +53,8 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate,
std::function<void()> onReadyCallback,
std::function<void()> onCompleteCallback) override;
void startViewTransitionReadyFinished() override;
void startViewTransitionEnd() override;
std::optional<ViewTransitionInstance> 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};