You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

134 lines
4.3 KiB

  1. #import "AppDelegate.h"
  2. #import <React/RCTBridge.h>
  3. #import <React/RCTBundleURLProvider.h>
  4. #import <React/RCTRootView.h>
  5. #import <React/RCTAppSetupUtils.h>
  6. #if RCT_NEW_ARCH_ENABLED
  7. #import <React/CoreModulesPlugins.h>
  8. #import <React/RCTCxxBridgeDelegate.h>
  9. #import <React/RCTFabricSurfaceHostingProxyRootView.h>
  10. #import <React/RCTSurfacePresenter.h>
  11. #import <React/RCTSurfacePresenterBridgeAdapter.h>
  12. #import <ReactCommon/RCTTurboModuleManager.h>
  13. #import <react/config/ReactNativeConfig.h>
  14. static NSString *const kRNConcurrentRoot = @"concurrentRoot";
  15. @interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
  16. RCTTurboModuleManager *_turboModuleManager;
  17. RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
  18. std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
  19. facebook::react::ContextContainer::Shared _contextContainer;
  20. }
  21. @end
  22. #endif
  23. @implementation AppDelegate
  24. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  25. {
  26. RCTAppSetupPrepareApp(application);
  27. RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  28. #if RCT_NEW_ARCH_ENABLED
  29. _contextContainer = std::make_shared<facebook::react::ContextContainer const>();
  30. _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
  31. _contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
  32. _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
  33. bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
  34. #endif
  35. NSDictionary *initProps = [self prepareInitialProps];
  36. UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"LessPass", initProps);
  37. if (@available(iOS 13.0, *)) {
  38. rootView.backgroundColor = [UIColor systemBackgroundColor];
  39. } else {
  40. rootView.backgroundColor = [UIColor whiteColor];
  41. }
  42. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  43. UIViewController *rootViewController = [UIViewController new];
  44. rootViewController.view = rootView;
  45. self.window.rootViewController = rootViewController;
  46. [self.window makeKeyAndVisible];
  47. return YES;
  48. }
  49. /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
  50. ///
  51. /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
  52. /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
  53. /// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`.
  54. - (BOOL)concurrentRootEnabled
  55. {
  56. // Switch this bool to turn on and off the concurrent root
  57. return true;
  58. }
  59. - (NSDictionary *)prepareInitialProps
  60. {
  61. NSMutableDictionary *initProps = [NSMutableDictionary new];
  62. #ifdef RCT_NEW_ARCH_ENABLED
  63. initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);
  64. #endif
  65. return initProps;
  66. }
  67. - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
  68. {
  69. #if DEBUG
  70. return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
  71. #else
  72. return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  73. #endif
  74. }
  75. #if RCT_NEW_ARCH_ENABLED
  76. #pragma mark - RCTCxxBridgeDelegate
  77. - (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
  78. {
  79. _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
  80. delegate:self
  81. jsInvoker:bridge.jsCallInvoker];
  82. return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
  83. }
  84. #pragma mark RCTTurboModuleManagerDelegate
  85. - (Class)getModuleClassFromName:(const char *)name
  86. {
  87. return RCTCoreModulesClassProvider(name);
  88. }
  89. - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
  90. jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
  91. {
  92. return nullptr;
  93. }
  94. - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
  95. initParams:
  96. (const facebook::react::ObjCTurboModule::InitParams &)params
  97. {
  98. return nullptr;
  99. }
  100. - (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
  101. {
  102. return RCTAppSetupDefaultModuleFromClass(moduleClass);
  103. }
  104. #endif
  105. @end