1#import <EXDevMenu/DevClientAppDelegate.h> 2 3#import <React/RCTBundleURLProvider.h> 4#import <React/RCTCxxBridgeDelegate.h> 5#if __has_include(<React_RCTAppDelegate/RCTAppSetupUtils.h>) 6// for importing the header from framework, the dash will be transformed to underscore 7#import <React_RCTAppDelegate/RCTAppSetupUtils.h> 8#else 9#import <React-RCTAppDelegate/RCTAppSetupUtils.h> 10#endif 11 12#ifdef RCT_NEW_ARCH_ENABLED 13#import <memory> 14 15#import <React/CoreModulesPlugins.h> 16#import <React/RCTFabricSurfaceHostingProxyRootView.h> 17#import <React/RCTSurfacePresenter.h> 18#import <React/RCTSurfacePresenterBridgeAdapter.h> 19#import <ReactCommon/RCTTurboModuleManager.h> 20#import <react/config/ReactNativeConfig.h> 21 22#import <react/renderer/runtimescheduler/RuntimeScheduler.h> 23#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h> 24 25@interface DevClientAppDelegate () < 26 RCTTurboModuleManagerDelegate, 27 RCTCxxBridgeDelegate, 28 RCTComponentViewFactoryComponentProvider, 29 RCTContextContainerHandling> { 30 std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig; 31 facebook::react::ContextContainer::Shared _contextContainer; 32 std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler; 33} 34@end 35 36#endif 37 38@interface RCTAppDelegate (DevClientAppDelegate) 39 40- (void)unstable_registerLegacyComponents; 41 42@end 43 44@implementation DevClientAppDelegate { 45#if RCT_NEW_ARCH_ENABLED 46 RCTHost *_reactHost; 47#endif // RCT_NEW_ARCH_ENABLED 48} 49 50#if RCT_NEW_ARCH_ENABLED 51- (instancetype)init 52{ 53 if (self = [super init]) { 54 _contextContainer = std::make_shared<facebook::react::ContextContainer const>(); 55 _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>(); 56 _contextContainer->insert("ReactNativeConfig", _reactNativeConfig); 57 } 58 return self; 59} 60#endif 61 62- (RCTBridge *)createBridgeAndSetAdapterWithLaunchOptions:(NSDictionary * _Nullable)launchOptions { 63 self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions]; 64 65#ifdef RCT_NEW_ARCH_ENABLED 66 // bridgeless mode is not yet supported in expo-dev-client 67 assert(!self.bridgelessEnabled); 68 69 self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge 70 contextContainer:_contextContainer]; 71 self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter; 72 73 [self unstable_registerLegacyComponents]; 74 [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; 75#endif 76 77 return self.bridge; 78} 79 80#pragma mark - RCTCxxBridgeDelegate 81 82#if RCT_NEW_ARCH_ENABLED 83- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge 84{ 85 _runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge)); 86 std::shared_ptr<facebook::react::CallInvoker> callInvoker = 87 std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler); 88 RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge 89 delegate:self 90 jsInvoker:callInvoker]; 91 _contextContainer->erase("RuntimeScheduler"); 92 _contextContainer->insert("RuntimeScheduler", _runtimeScheduler); 93 return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler); 94} 95#endif // RCT_NEW_ARCH_ENABLED 96 97@end 98