diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp index 28998bd034baea..6569c24fae8e40 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -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, @@ -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); @@ -289,16 +287,10 @@ void Scheduler::uiManagerDidFinishTransaction( // observe each transaction to be able to mount correctly. delegate_->schedulerDidFinishTransaction(mountingCoordinator); - auto weakRuntimeScheduler = - contextContainer_->find>( - "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)]() { diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h index c75f98de523346..30ab071b92f53b 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h @@ -139,6 +139,8 @@ class Scheduler final : public UIManagerDelegate { * Must not be nullptr. */ ContextContainer::Shared contextContainer_; + + RuntimeScheduler* runtimeScheduler_{nullptr}; }; } // namespace facebook::react