Skip to content

Commit 3cf4024

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
Add startViewTransitionReadyFinished callback (#56461)
Summary: Pull Request resolved: #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
1 parent fd0bc69 commit 3cf4024

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,24 @@ jsi::Value UIManagerBinding::get(
10921092
});
10931093
}
10941094

1095+
if (methodName == "startViewTransitionReadyFinished") {
1096+
return jsi::Function::createFromHostFunction(
1097+
runtime,
1098+
name,
1099+
0,
1100+
[uiManager](
1101+
jsi::Runtime& runtime,
1102+
const jsi::Value& /*thisValue*/,
1103+
const jsi::Value* /*arguments*/,
1104+
size_t /*count*/) -> jsi::Value {
1105+
auto* viewTransitionDelegate = uiManager->getViewTransitionDelegate();
1106+
if (viewTransitionDelegate != nullptr) {
1107+
viewTransitionDelegate->startViewTransitionReadyFinished();
1108+
}
1109+
return jsi::Value::undefined();
1110+
});
1111+
}
1112+
10951113
if (methodName == "startViewTransition") {
10961114
auto paramCount = 1;
10971115
return jsi::Function::createFromHostFunction(

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerViewTransitionDelegate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class UIManagerViewTransitionDelegate {
4141
{
4242
}
4343

44+
virtual void startViewTransitionReadyFinished() {}
45+
4446
virtual void startViewTransitionEnd() {}
4547

4648
struct ViewTransitionInstance {

packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void ViewTransitionModule::startViewTransition(
353353
}
354354

355355
applySnapshotsOnPseudoElementShadowNodes();
356-
356+
transitionReadyFinished_ = false;
357357
if (onReadyCallback) {
358358
onReadyCallback();
359359
}
@@ -366,6 +366,10 @@ void ViewTransitionModule::startViewTransition(
366366
}
367367
}
368368

369+
void ViewTransitionModule::startViewTransitionReadyFinished() {
370+
transitionReadyFinished_ = true;
371+
}
372+
369373
void ViewTransitionModule::suspendOnActiveViewTransition() {
370374
// Signal that the next transition should be suspended until the current
371375
// one finishes. The actual queueing happens in startViewTransition.

packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate,
5353
std::function<void()> onReadyCallback,
5454
std::function<void()> onCompleteCallback) override;
5555

56+
void startViewTransitionReadyFinished() override;
57+
5658
void startViewTransitionEnd() override;
5759

5860
std::optional<ViewTransitionInstance> getViewTransitionInstance(const std::string &name, const std::string &pseudo)
@@ -128,6 +130,8 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate,
128130

129131
bool transitionStarted_{false};
130132

133+
bool transitionReadyFinished_{false};
134+
131135
// When suspendNextTransition_ is true and a transition is active, the next
132136
// startViewTransition calls are queued instead of running immediately.
133137
bool suspendNextTransition_{false};

0 commit comments

Comments
 (0)