1313#include < glog/logging.h>
1414#include < jserrorhandler/JsErrorHandler.h>
1515#include < jsinspector-modern/InspectorFlags.h>
16- #include < react/coremodules/AppStateModule.h>
17- #include < react/coremodules/DeviceInfoModule.h>
18- #include < react/coremodules/PlatformConstantsModule.h>
1916#include < react/debug/react_native_assert.h>
20- #include < react/devsupport/DevLoadingViewModule.h>
2117#include < react/devsupport/DevServerHelper.h>
22- #include < react/devsupport/DevSettingsModule.h>
2318#include < react/devsupport/IDevUIDelegate.h>
24- #include < react/devsupport/LogBoxModule.h>
2519#include < react/devsupport/PackagerConnection.h>
26- #include < react/devsupport/SourceCodeModule.h>
2720#include < react/devsupport/inspector/Inspector.h>
2821#include < react/http/IHttpClient.h>
2922#include < react/http/IWebSocketClient.h>
30- #include < react/io/ImageLoaderModule.h>
31- #include < react/io/NetworkingModule.h>
3223#include < react/io/ResourceLoader.h>
33- #include < react/io/WebSocketModule.h>
3424#include < react/logging/LogOnce.h>
35- #include < react/logging/NativeExceptionsManager.h>
36- #include < react/nativemodule/defaults/DefaultTurboModules.h>
37- #include < react/nativemodule/intersectionobserver/NativeIntersectionObserver.h>
38- #include < react/nativemodule/mutationobserver/NativeMutationObserver.h>
39- #include < react/nativemodule/webperformance/NativePerformance.h>
40- #include < react/renderer/animated/AnimatedModule.h>
4125#include < react/renderer/componentregistry/native/NativeComponentRegistryBinding.h>
4226#include < react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
4327#include < react/renderer/scheduler/SchedulerDelegate.h>
5034#include < react/runtime/hermes/HermesInstance.h>
5135#include < react/threading/MessageQueueThreadImpl.h>
5236
37+ #include " TurboModuleManager.h"
38+
5339namespace facebook ::react {
5440
5541struct ReactInstanceData {
@@ -257,6 +243,18 @@ void ReactHost::createReactInstance() {
257243 }
258244
259245 auto liveReloadCallback = [this ]() { reloadReactInstance (); };
246+ TurboModuleManager turboModuleManager (
247+ reactInstanceData_->turboModuleProviders ,
248+ jsInvoker,
249+ reactInstanceData_->onJsError ,
250+ reactInstanceData_->animatedNodesManagerProvider ,
251+ reactInstanceConfig_.enableDevMode ? devServerHelper_ : nullptr ,
252+ reactInstanceData_->devUIDelegate ,
253+ reactInstanceData_->logBoxSurfaceDelegate ,
254+ httpClientFactory,
255+ webSocketClientFactory,
256+ std::move (liveReloadCallback));
257+
260258 reactInstance_->initializeRuntime (
261259 {
262260#if defined(WITH_PERFETTO) || defined(RNCXX_WITH_PROFILING_PROVIDER)
@@ -268,20 +266,9 @@ void ReactHost::createReactInstance() {
268266 [weakMountingManager =
269267 std::weak_ptr<IMountingManager>(reactInstanceData_->mountingManager ),
270268 logger = reactInstanceData_->logger ,
271- devUIDelegate = reactInstanceData_->devUIDelegate ,
272- turboModuleProviders = reactInstanceData_->turboModuleProviders ,
273- jsInvoker = std::move (jsInvoker),
274- logBoxSurfaceDelegate = reactInstanceData_->logBoxSurfaceDelegate ,
275- devServerHelper =
276- reactInstanceConfig_.enableDevMode ? devServerHelper_ : nullptr ,
277- animatedNodesManagerProvider =
278- reactInstanceData_->animatedNodesManagerProvider ,
279- onJsError = reactInstanceData_->onJsError ,
280269 bindingsInstallFunc = reactInstanceData_->bindingsInstallFunc ,
281- httpClientFactory = std::move (httpClientFactory),
282- webSocketClientFactory = std::move (webSocketClientFactory),
283- liveReloadCallback =
284- std::move (liveReloadCallback)](jsi::Runtime& runtime) {
270+ turboModuleManager =
271+ std::move (turboModuleManager)](jsi::Runtime& runtime) mutable {
285272 if (logger) {
286273 bindNativeLogger (runtime, logger);
287274 }
@@ -295,85 +282,9 @@ void ReactHost::createReactInstance() {
295282 return false ;
296283 });
297284
298- auto turboModuleProvider =
299- [turboModuleProviders,
300- jsInvoker,
301- logBoxSurfaceDelegate,
302- devServerHelper,
303- devUIDelegate,
304- animatedNodesManagerProvider,
305- onJsError,
306- httpClientFactory = httpClientFactory,
307- webSocketClientFactory = webSocketClientFactory,
308- liveReloadCallback = liveReloadCallback](
309- const std::string& name) -> std::shared_ptr<TurboModule> {
310- react_native_assert (
311- !name.empty () && " TurboModule name must not be empty" );
312-
313- for (const auto & turboModuleProvider : turboModuleProviders) {
314- if (turboModuleProvider) {
315- if (auto turboModule = turboModuleProvider (name, jsInvoker)) {
316- return turboModule;
317- }
318- }
319- }
320-
321- if (auto turboModule =
322- DefaultTurboModules::getTurboModule (name, jsInvoker)) {
323- return turboModule;
324- }
325-
326- if (name == AnimatedModule::kModuleName ) {
327- return std::make_shared<AnimatedModule>(
328- jsInvoker, animatedNodesManagerProvider);
329- } else if (name == AppStateModule::kModuleName ) {
330- return std::make_shared<AppStateModule>(jsInvoker);
331- } else if (name == DeviceInfoModule::kModuleName ) {
332- return std::make_shared<DeviceInfoModule>(jsInvoker);
333- } else if (
334- devUIDelegate != nullptr &&
335- name == DevLoadingViewModule::kModuleName ) {
336- return std::make_shared<DevLoadingViewModule>(
337- jsInvoker, devUIDelegate);
338- } else if (
339- devServerHelper && name == DevSettingsModule::kModuleName ) {
340- return std::make_shared<DevSettingsModule>(
341- jsInvoker, devServerHelper, liveReloadCallback);
342- } else if (name == PlatformConstantsModule::kModuleName ) {
343- return std::make_shared<PlatformConstantsModule>(jsInvoker);
344- } else if (name == ImageLoaderModule::kModuleName ) {
345- return std::make_shared<ImageLoaderModule>(jsInvoker);
346- } else if (name == SourceCodeModule::kModuleName ) {
347- return std::make_shared<SourceCodeModule>(
348- jsInvoker, devServerHelper);
349- } else if (name == WebSocketModule::kModuleName ) {
350- return std::make_shared<WebSocketModule>(
351- jsInvoker, webSocketClientFactory);
352- } else if (name == NativeExceptionsManager::kModuleName ) {
353- return std::make_shared<NativeExceptionsManager>(
354- onJsError, jsInvoker);
355- } else if (name == NativePerformance::kModuleName ) {
356- return std::make_shared<NativePerformance>(jsInvoker);
357- } else if (name == NativeIntersectionObserver::kModuleName ) {
358- return std::make_shared<NativeIntersectionObserver>(jsInvoker);
359- } else if (name == NativeMutationObserver::kModuleName ) {
360- return std::make_shared<NativeMutationObserver>(jsInvoker);
361- } else if (name == NetworkingModule::kModuleName ) {
362- return std::make_shared<NetworkingModule>(
363- jsInvoker, httpClientFactory);
364- } else if (name == LogBoxModule::kModuleName ) {
365- if (logBoxSurfaceDelegate) {
366- return std::make_shared<LogBoxModule>(
367- jsInvoker, logBoxSurfaceDelegate);
368- }
369- }
370-
371- LOG_WARNING_ONCE << " Failed to load TurboModule: " << name;
372- return nullptr ;
373- };
374-
375285 // Set up TurboModules
376- TurboModuleBinding::install (runtime, turboModuleProvider);
286+ TurboModuleBinding::install (runtime, std::move (turboModuleManager));
287+
377288 if (bindingsInstallFunc) {
378289 bindingsInstallFunc (runtime);
379290 }
0 commit comments