Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synchronise dispatching of view commands through RuntimeScheduler #47604

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ Scheduler::Scheduler(
weakRuntimeScheduler.has_value() &&
"Unexpected state: RuntimeScheduler was not provided.");

auto runtimeScheduler = weakRuntimeScheduler.value().lock();
runtimeScheduler_ = weakRuntimeScheduler.value().lock().get();

if (ReactNativeFeatureFlags::enableUIConsistency()) {
runtimeScheduler->setShadowTreeRevisionConsistencyManager(
runtimeScheduler_->setShadowTreeRevisionConsistencyManager(
uiManager->getShadowTreeRevisionConsistencyManager());
}

if (ReactNativeFeatureFlags::enableReportEventPaintTime()) {
runtimeScheduler->setEventTimingDelegate(eventPerformanceLogger_.get());
runtimeScheduler_->setEventTimingDelegate(eventPerformanceLogger_.get());
}

auto eventPipe = [uiManager, runtimeScheduler = runtimeScheduler.get()](
auto eventPipe = [uiManager](
jsi::Runtime& runtime,
const EventTarget* eventTarget,
const std::string& type,
Expand All @@ -79,12 +79,10 @@ Scheduler::Scheduler(
runtime);
};

auto eventPipeConclusion =
[runtimeScheduler = runtimeScheduler.get()](jsi::Runtime& runtime) {
if (runtimeScheduler != nullptr) {
runtimeScheduler->callExpiredTasks(runtime);
}
};
auto eventPipeConclusion = [runtimeScheduler =
runtimeScheduler_](jsi::Runtime& runtime) {
runtimeScheduler->callExpiredTasks(runtime);
};

auto statePipe = [uiManager](const StateUpdate& stateUpdate) {
uiManager->updateState(stateUpdate);
Expand Down Expand Up @@ -289,16 +287,10 @@ void Scheduler::uiManagerDidFinishTransaction(
// observe each transaction to be able to mount correctly.
delegate_->schedulerDidFinishTransaction(mountingCoordinator);

auto weakRuntimeScheduler =
contextContainer_->find<std::weak_ptr<RuntimeScheduler>>(
"RuntimeScheduler");
auto runtimeScheduler = weakRuntimeScheduler.has_value()
? weakRuntimeScheduler.value().lock()
: nullptr;
if (runtimeScheduler && !mountSynchronously) {
if (!mountSynchronously) {
auto surfaceId = mountingCoordinator->getSurfaceId();

runtimeScheduler->scheduleRenderingUpdate(
runtimeScheduler_->scheduleRenderingUpdate(
surfaceId,
[delegate = delegate_,
mountingCoordinator = std::move(mountingCoordinator)]() {
Expand All @@ -324,7 +316,15 @@ void Scheduler::uiManagerDidDispatchCommand(

if (delegate_ != nullptr) {
auto shadowView = ShadowView(*shadowNode);
delegate_->schedulerDidDispatchCommand(shadowView, commandName, args);

runtimeScheduler_->scheduleRenderingUpdate(
shadowNode->getSurfaceId(),
[delegate = delegate_,
shadowView = std::move(shadowView),
commandName,
args]() {
delegate->schedulerDidDispatchCommand(shadowView, commandName, args);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class Scheduler final : public UIManagerDelegate {
* Must not be nullptr.
*/
ContextContainer::Shared contextContainer_;

RuntimeScheduler* runtimeScheduler_{nullptr};
};

} // namespace facebook::react
Loading