Skip to content

Commit

Permalink
Initialise RuntimeScheduler before bundle is executed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Jun 14, 2021
1 parent 8ca8f0c commit d540f88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
18 changes: 10 additions & 8 deletions React/Fabric/RCTSurfacePresenter.mm
Expand Up @@ -282,14 +282,16 @@ - (RCTScheduler *)_createScheduler
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;
Expand Down
4 changes: 3 additions & 1 deletion React/Fabric/RCTSurfacePresenterBridgeAdapter.h
Expand Up @@ -6,15 +6,17 @@
*/

#import <Foundation/Foundation.h>
#import <ReactCommon/RuntimeExecutor.h>
#import <UIKit/UIKit.h>

#import <react/utils/ContextContainer.h>

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.
Expand Down
2 changes: 1 addition & 1 deletion React/Fabric/RCTSurfacePresenterBridgeAdapter.mm
Expand Up @@ -41,7 +41,7 @@ - (void)invokeAsync:(std::function<void()> &&)func;
return contextContainer;
}

static RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
{
RCTAssert(bridge, @"RCTRuntimeExecutorFromBridge: Bridge must not be nil.");

Expand Down

0 comments on commit d540f88

Please sign in to comment.