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