/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #import "RCTAppSetupUtils.h" #import #import #import #if RCT_NEW_ARCH_ENABLED // Turbo Module #import #import #import #import #import #import #import #import // Fabric #import #import #import #endif #ifdef FB_SONARKIT_ENABLED #import #import #import #import #import #import static void InitializeFlipper(UIApplication *application) { FlipperClient *client = [FlipperClient sharedClient]; SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client addPlugin:[FlipperKitReactPlugin new]]; [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [client start]; } #endif void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled) { #ifdef FB_SONARKIT_ENABLED InitializeFlipper(application); #endif #if RCT_NEW_ARCH_ENABLED RCTEnableTurboModule(turboModuleEnabled); #endif } UIView * RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties, BOOL fabricEnabled) { #if RCT_NEW_ARCH_ENABLED if (fabricEnabled) { return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties]; } #endif return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties]; } #if RCT_NEW_ARCH_ENABLED id RCTAppSetupDefaultModuleFromClass(Class moduleClass) { // Set up the default RCTImageLoader and RCTNetworking modules. if (moduleClass == RCTImageLoader.class) { return [[moduleClass alloc] initWithRedirectDelegate:nil loadersProvider:^NSArray> *(RCTModuleRegistry *moduleRegistry) { return @[ [RCTLocalAssetImageLoader new] ]; } decodersProvider:^NSArray> *(RCTModuleRegistry *moduleRegistry) { return @[ [RCTGIFImageDecoder new] ]; }]; } else if (moduleClass == RCTNetworking.class) { return [[moduleClass alloc] initWithHandlersProvider:^NSArray> *(RCTModuleRegistry *moduleRegistry) { return @[ [RCTHTTPRequestHandler new], [RCTDataRequestHandler new], [RCTFileRequestHandler new], ]; }]; } // No custom initializer here. return [moduleClass new]; } std::unique_ptr RCTAppSetupDefaultJsExecutorFactory( RCTBridge *bridge, RCTTurboModuleManager *turboModuleManager, std::shared_ptr const &runtimeScheduler) { // Necessary to allow NativeModules to lookup TurboModules [bridge setRCTTurboModuleRegistry:turboModuleManager]; #if RCT_DEV if (!RCTTurboModuleEagerInitEnabled()) { /** * Instantiating DevMenu has the side-effect of registering * shortcuts for CMD + d, CMD + i, and CMD + n via RCTDevMenu. * Therefore, when TurboModules are enabled, we must manually create this * NativeModule. */ [turboModuleManager moduleForName:"RCTDevMenu"]; } #endif #if RCT_USE_HERMES return std::make_unique( #else return std::make_unique( #endif facebook::react::RCTJSIExecutorRuntimeInstaller( [turboModuleManager, bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) { if (!bridge || !turboModuleManager) { return; } if (runtimeScheduler) { facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler); } facebook::react::RuntimeExecutor syncRuntimeExecutor = [&](std::function &&callback) { callback(runtime); }; [turboModuleManager installJSBindingWithRuntimeExecutor:syncRuntimeExecutor]; })); } #else std::unique_ptr RCTAppSetupJsExecutorFactoryForOldArch( RCTBridge *bridge, std::shared_ptr const &runtimeScheduler) { #if RCT_USE_HERMES return std::make_unique( #else return std::make_unique( #endif facebook::react::RCTJSIExecutorRuntimeInstaller([bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) { if (!bridge) { return; } if (runtimeScheduler) { facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler); } })); } #endif