Initialise RuntimeScheduler before bundle is executed

Summary:
Changelog: [internal]

RuntimeScheduler can be accessed before any Fabric surface is rendered. Therefore, it needs to be created and installed in the runtime at the start up of the runtime.

Reviewed By: JoshuaGross

Differential Revision: D29091848

fbshipit-source-id: ff75ef8c4882550795e5d4a258355b651cb0e637
This commit is contained in:
Samuel Susla
2021-06-14 10:52:09 -07:00
committed by Facebook GitHub Bot
parent 8ca8f0cbe3
commit d540f88df8
3 changed files with 14 additions and 10 deletions
+10 -8
View File
@@ -282,14 +282,16 @@ static BackgroundExecutor RCTGetBackgroundExecutor()
toolbox.contextContainer = _contextContainer;
toolbox.componentRegistryFactory = componentRegistryFactory;
if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:enable_runtimescheduler_ios")) {
auto runtimeScheduler = std::make_shared<RuntimeScheduler>(_runtimeExecutor);
runtimeScheduler->setEnableYielding(
reactNativeConfig->getBool("react_native_new_architecture:runtimescheduler_enable_yielding_ios"));
toolbox.runtimeScheduler = runtimeScheduler;
runtimeExecutor = [runtimeScheduler](std::function<void(jsi::Runtime & runtime)> &&callback) {
runtimeScheduler->scheduleWork(std::move(callback));
};
auto runtimeScheduler = _contextContainer->find<std::weak_ptr<RuntimeScheduler>>("RuntimeScheduler");
if (runtimeScheduler.hasValue()) {
auto lockedRuntimeScheduler = runtimeScheduler.value().lock();
if (lockedRuntimeScheduler) {
lockedRuntimeScheduler->setEnableYielding(
reactNativeConfig->getBool("react_native_new_architecture:runtimescheduler_enable_yielding_ios"));
runtimeExecutor = [lockedRuntimeScheduler](std::function<void(jsi::Runtime & runtime)> &&callback) {
lockedRuntimeScheduler->scheduleWork(std::move(callback));
};
}
}
toolbox.runtimeExecutor = runtimeExecutor;
@@ -6,8 +6,8 @@
*/
#import <Foundation/Foundation.h>
#import <ReactCommon/RuntimeExecutor.h>
#import <UIKit/UIKit.h>
#import <react/utils/ContextContainer.h>
NS_ASSUME_NONNULL_BEGIN
@@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
@class RCTSurfacePresenter;
@class RCTBridge;
facebook::react::RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge);
/*
* Controls a life-cycle of a Surface Presenter based on Bridge's life-cycle.
* We are moving away from using Bridge.
@@ -41,7 +41,7 @@ static ContextContainer::Shared RCTContextContainerFromBridge(RCTBridge *bridge)
return contextContainer;
}
static RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
{
RCTAssert(bridge, @"RCTRuntimeExecutorFromBridge: Bridge must not be nil.");