Skip to content

Commit

Permalink
Do not use setNativeState in RuntimeScheduler::Task
Browse files Browse the repository at this point in the history
Summary:
changelog: [internal]

`setNativeState` is not implemented in JSC. Let's stick to host objects for now.

Reviewed By: cipolleschi

Differential Revision: D46193786

fbshipit-source-id: 9d36801bb9faa5c144a461bcbe623762bf6947b1
  • Loading branch information
sammy-SC authored and Riccardo Cipolleschi committed May 26, 2023
1 parent dc6a2c3 commit c43bd7a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h
Expand Up @@ -94,6 +94,11 @@
*/
- (UIViewController *)createRootViewController;

/// This method controls whether the App will use RuntimeScheduler. Only applicable in the legacy architecture.
///
/// @return: `YES` to use RuntimeScheduler, `NO` to use JavaScript scheduler. The default value is `YES`.
- (BOOL)runtimeSchedulerEnabled;

#if RCT_NEW_ARCH_ENABLED

/// The TurboModule manager
Expand Down
10 changes: 9 additions & 1 deletion packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Expand Up @@ -134,18 +134,26 @@ - (UIViewController *)createRootViewController
return [UIViewController new];
}

- (BOOL)runtimeSchedulerEnabled
{
return YES;
}

#pragma mark - RCTCxxBridgeDelegate
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
#if RCT_NEW_ARCH_ENABLED
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
std::shared_ptr<facebook::react::CallInvoker> callInvoker =
std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
self.turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge delegate:self jsInvoker:callInvoker];
_contextContainer->erase("RuntimeScheduler");
_contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
return RCTAppSetupDefaultJsExecutorFactory(bridge, self.turboModuleManager, _runtimeScheduler);
#else
if (self.runtimeSchedulerEnabled) {
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
}
return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
#endif
}
Expand Down
Expand Up @@ -19,11 +19,17 @@ struct TaskWrapper : public jsi::HostObject {
std::shared_ptr<Task> task;
};

struct TaskWrapper : public jsi::HostObject {
TaskWrapper(std::shared_ptr<Task> const &task) : task(task) {}

std::shared_ptr<Task> task;
};

inline static jsi::Value valueFromTask(
jsi::Runtime &runtime,
std::shared_ptr<Task> task) {
return jsi::Object::createFromHostObject(
runtime, std::make_shared<TaskWrapper>(task));
runtime, std::make_shared<TaskWrapper>(task));
}

inline static std::shared_ptr<Task> taskFromValue(
Expand Down

0 comments on commit c43bd7a

Please sign in to comment.