Skip to content

Commit c43bd7a

Browse files
sammy-SCRiccardo Cipolleschi
authored andcommitted
Do not use setNativeState in RuntimeScheduler::Task
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
1 parent dc6a2c3 commit c43bd7a

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
*/
9595
- (UIViewController *)createRootViewController;
9696

97+
/// This method controls whether the App will use RuntimeScheduler. Only applicable in the legacy architecture.
98+
///
99+
/// @return: `YES` to use RuntimeScheduler, `NO` to use JavaScript scheduler. The default value is `YES`.
100+
- (BOOL)runtimeSchedulerEnabled;
101+
97102
#if RCT_NEW_ARCH_ENABLED
98103

99104
/// The TurboModule manager

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,26 @@ - (UIViewController *)createRootViewController
134134
return [UIViewController new];
135135
}
136136

137+
- (BOOL)runtimeSchedulerEnabled
138+
{
139+
return YES;
140+
}
141+
137142
#pragma mark - RCTCxxBridgeDelegate
138143
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
139144
{
140-
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
141145
#if RCT_NEW_ARCH_ENABLED
146+
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
142147
std::shared_ptr<facebook::react::CallInvoker> callInvoker =
143148
std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
144149
self.turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge delegate:self jsInvoker:callInvoker];
145150
_contextContainer->erase("RuntimeScheduler");
146151
_contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
147152
return RCTAppSetupDefaultJsExecutorFactory(bridge, self.turboModuleManager, _runtimeScheduler);
148153
#else
154+
if (self.runtimeSchedulerEnabled) {
155+
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
156+
}
149157
return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
150158
#endif
151159
}

packages/react-native/ReactCommon/react/renderer/runtimescheduler/primitives.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ struct TaskWrapper : public jsi::HostObject {
1919
std::shared_ptr<Task> task;
2020
};
2121

22+
struct TaskWrapper : public jsi::HostObject {
23+
TaskWrapper(std::shared_ptr<Task> const &task) : task(task) {}
24+
25+
std::shared_ptr<Task> task;
26+
};
27+
2228
inline static jsi::Value valueFromTask(
2329
jsi::Runtime &runtime,
2430
std::shared_ptr<Task> task) {
2531
return jsi::Object::createFromHostObject(
26-
runtime, std::make_shared<TaskWrapper>(task));
32+
runtime, std::make_shared<TaskWrapper>(task));
2733
}
2834

2935
inline static std::shared_ptr<Task> taskFromValue(

0 commit comments

Comments
 (0)