mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Simplify jsi::Function storage in UIManagerBinding::startViewTransition (#56403)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56403 Document the threading contract on UIManagerViewTransitionDelegate::startViewTransition and simplifying how we track the jsi::Function Changelog: [Internal] Reviewed By: zeyap Differential Revision: D98717252 fbshipit-source-id: 6e24728efa8f316fda0b4eb9e8f2291d5bcb8fda
This commit is contained in:
1 parent
abd6173590
commit
8dede75fe3
2 files changed
+26
-17
No files matched your search
@@ -1064,10 +1064,8 @@ jsi::Value UIManagerBinding::get(
|
||||
auto promiseConstructor =
|
||||
runtime.global().getPropertyAsFunction(runtime, "Promise");
|
||||
|
||||
auto readyResolveFunc =
|
||||
std::make_shared<std::shared_ptr<jsi::Function>>();
|
||||
auto finishedResolveFunc =
|
||||
std::make_shared<std::shared_ptr<jsi::Function>>();
|
||||
std::shared_ptr<jsi::Function> readyResolveFunc;
|
||||
std::shared_ptr<jsi::Function> finishedResolveFunc;
|
||||
|
||||
auto mutationFunc = std::make_shared<jsi::Function>(
|
||||
arguments[0].asObject(runtime).asFunction(runtime));
|
||||
@@ -1078,14 +1076,13 @@ jsi::Value UIManagerBinding::get(
|
||||
runtime,
|
||||
jsi::PropNameID::forAscii(runtime, "readyExecutor"),
|
||||
2,
|
||||
[readyResolveFunc](
|
||||
[&readyResolveFunc](
|
||||
jsi::Runtime& runtime,
|
||||
const jsi::Value& /*thisValue*/,
|
||||
const jsi::Value* args,
|
||||
size_t /*count*/) -> jsi::Value {
|
||||
auto onReadyFunc = std::make_shared<jsi::Function>(
|
||||
readyResolveFunc = std::make_shared<jsi::Function>(
|
||||
args[0].asObject(runtime).asFunction(runtime));
|
||||
*readyResolveFunc = onReadyFunc;
|
||||
return jsi::Value::undefined();
|
||||
}));
|
||||
|
||||
@@ -1095,19 +1092,21 @@ jsi::Value UIManagerBinding::get(
|
||||
runtime,
|
||||
jsi::PropNameID::forAscii(runtime, "finishedExecutor"),
|
||||
2,
|
||||
[finishedResolveFunc, viewTransitionDelegate](
|
||||
[&finishedResolveFunc, viewTransitionDelegate](
|
||||
jsi::Runtime& rt,
|
||||
const jsi::Value& /*thisValue*/,
|
||||
const jsi::Value* args,
|
||||
size_t /*count*/) -> jsi::Value {
|
||||
size_t /*count*/) mutable -> jsi::Value {
|
||||
auto onCompleteFunc = std::make_shared<jsi::Function>(
|
||||
args[0].asObject(rt).asFunction(rt));
|
||||
*finishedResolveFunc = std::make_shared<jsi::Function>(
|
||||
finishedResolveFunc = std::make_shared<jsi::Function>(
|
||||
jsi::Function::createFromHostFunction(
|
||||
rt,
|
||||
jsi::PropNameID::forAscii(rt, "finishedResolve"),
|
||||
0,
|
||||
[onCompleteFunc, viewTransitionDelegate](
|
||||
[onCompleteFunc = std::move(onCompleteFunc),
|
||||
viewTransitionDelegate =
|
||||
std::move(viewTransitionDelegate)](
|
||||
jsi::Runtime& runtime,
|
||||
const jsi::Value& /*thisValue*/,
|
||||
const jsi::Value* /*args*/,
|
||||
@@ -1125,20 +1124,25 @@ jsi::Value UIManagerBinding::get(
|
||||
|
||||
viewTransitionDelegate->startViewTransition(
|
||||
[&runtime, mutationFunc = std::move(mutationFunc)]() {
|
||||
// mutationCallback is called synchronously by the
|
||||
// delegate during startViewTransition, so &runtime is
|
||||
// valid (it comes from the enclosing host function).
|
||||
mutationFunc->call(runtime);
|
||||
},
|
||||
[readyResolveFunc = std::move(readyResolveFunc), &runtime]() {
|
||||
if (*readyResolveFunc) {
|
||||
(*readyResolveFunc)->call(runtime);
|
||||
// onReadyCallback is called synchronously on the JS
|
||||
// thread by the delegate, so &runtime is valid.
|
||||
if (readyResolveFunc) {
|
||||
readyResolveFunc->call(runtime);
|
||||
}
|
||||
},
|
||||
[finishedResolveFunc = std::move(finishedResolveFunc),
|
||||
uiManager]() {
|
||||
uiManager->runtimeExecutor_(
|
||||
runtimeExecutor = uiManager->runtimeExecutor_]() {
|
||||
runtimeExecutor(
|
||||
[finishedResolveFunc = std::move(finishedResolveFunc)](
|
||||
jsi::Runtime& rt) mutable {
|
||||
if (*finishedResolveFunc) {
|
||||
(*finishedResolveFunc)->call(rt);
|
||||
if (finishedResolveFunc) {
|
||||
finishedResolveFunc->call(rt);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+5
@@ -27,6 +27,11 @@ class UIManagerViewTransitionDelegate {
|
||||
|
||||
virtual void restoreViewTransitionName(const ShadowNode &shadowNode) {}
|
||||
|
||||
/*
|
||||
* Start a view transition. mutationCallback and onReadyCallback MUST be
|
||||
* called from a thread with access to the jsi::Runtime.
|
||||
* onCompleteCallback may be called from any thread.
|
||||
*/
|
||||
virtual void startViewTransition(
|
||||
std::function<void()> mutationCallback,
|
||||
std::function<void()> onReadyCallback,
|
||||
|
||||
Reference in new issue
Block a user