Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #import "AppDelegate.h"
  2. #import <React/RCTBridge.h>
  3. #import <React/RCTBundleURLProvider.h>
  4. #import <React/RCTRootView.h>
  5. #import <React/RCTLinkingManager.h>
  6. #import <React/RCTConvert.h>
  7. #import <React/RCTAppSetupUtils.h>
  8. #if RCT_NEW_ARCH_ENABLED
  9. #import <React/CoreModulesPlugins.h>
  10. #import <React/RCTCxxBridgeDelegate.h>
  11. #import <React/RCTFabricSurfaceHostingProxyRootView.h>
  12. #import <React/RCTSurfacePresenter.h>
  13. #import <React/RCTSurfacePresenterBridgeAdapter.h>
  14. #import <ReactCommon/RCTTurboModuleManager.h>
  15. #import <react/config/ReactNativeConfig.h>
  16. static NSString *const kRNConcurrentRoot = @"concurrentRoot";
  17. @interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
  18. RCTTurboModuleManager *_turboModuleManager;
  19. RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
  20. std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
  21. facebook::react::ContextContainer::Shared _contextContainer;
  22. }
  23. @end
  24. #endif
  25. @implementation AppDelegate
  26. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  27. {
  28. RCTAppSetupPrepareApp(application);
  29. RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions];
  30. #if RCT_NEW_ARCH_ENABLED
  31. _contextContainer = std::make_shared<facebook::react::ContextContainer const>();
  32. _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
  33. _contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
  34. _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
  35. bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
  36. #endif
  37. NSDictionary *initProps = [self prepareInitialProps];
  38. UIView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:initProps];
  39. rootView.backgroundColor = [UIColor whiteColor];
  40. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  41. UIViewController *rootViewController = [self.reactDelegate createRootViewController];
  42. rootViewController.view = rootView;
  43. self.window.rootViewController = rootViewController;
  44. [self.window makeKeyAndVisible];
  45. [super application:application didFinishLaunchingWithOptions:launchOptions];
  46. return YES;
  47. }
  48. - (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
  49. {
  50. // If you'd like to export some custom RCTBridgeModules, add them here!
  51. return @[];
  52. }
  53. /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
  54. ///
  55. /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
  56. /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
  57. /// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`.
  58. - (BOOL)concurrentRootEnabled
  59. {
  60. // Switch this bool to turn on and off the concurrent root
  61. return true;
  62. }
  63. - (NSDictionary *)prepareInitialProps
  64. {
  65. NSMutableDictionary *initProps = [NSMutableDictionary new];
  66. #if RCT_NEW_ARCH_ENABLED
  67. initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);
  68. #endif
  69. return initProps;
  70. }
  71. - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
  72. {
  73. #if DEBUG
  74. return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
  75. #else
  76. return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  77. #endif
  78. }
  79. // Linking API
  80. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  81. return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options];
  82. }
  83. // Universal Links
  84. - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
  85. BOOL result = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
  86. return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler] || result;
  87. }
  88. // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries
  89. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  90. {
  91. return [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
  92. }
  93. // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries
  94. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  95. {
  96. return [super application:application didFailToRegisterForRemoteNotificationsWithError:error];
  97. }
  98. // Explicitly define remote notification delegates to ensure compatibility with some third-party libraries
  99. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  100. {
  101. return [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
  102. }
  103. #if RCT_NEW_ARCH_ENABLED
  104. #pragma mark - RCTCxxBridgeDelegate
  105. - (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
  106. {
  107. _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
  108. delegate:self
  109. jsInvoker:bridge.jsCallInvoker];
  110. return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
  111. }
  112. #pragma mark RCTTurboModuleManagerDelegate
  113. - (Class)getModuleClassFromName:(const char *)name
  114. {
  115. return RCTCoreModulesClassProvider(name);
  116. }
  117. - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
  118. jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
  119. {
  120. return nullptr;
  121. }
  122. - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
  123. initParams:
  124. (const facebook::react::ObjCTurboModule::InitParams &)params
  125. {
  126. return nullptr;
  127. }
  128. - (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
  129. {
  130. return RCTAppSetupDefaultModuleFromClass(moduleClass);
  131. }
  132. #endif
  133. @end