Files
notesnook/apps/mobile/native/ios/Notesnook/AppDelegate.mm

198 lines
6.7 KiB
Plaintext
Raw Normal View History

2019-11-15 01:17:59 +05:00
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
2022-04-29 20:27:37 +05:00
#import <RNBootSplash/RNBootSplash.h>
2022-04-20 02:09:54 +05:00
#import <React/RCTAppSetupUtils.h>
2022-04-29 20:27:37 +05:00
#import <React/RCTLinkingManager.h>
2022-04-20 02:09:54 +05:00
#if RCT_NEW_ARCH_ENABLED
#import <React/CoreModulesPlugins.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <react/config/ReactNativeConfig.h>
2022-06-30 09:45:28 +05:00
static NSString *const kRNConcurrentRoot = @"concurrentRoot";
2022-04-20 02:09:54 +05:00
@interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
RCTTurboModuleManager *_turboModuleManager;
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
facebook::react::ContextContainer::Shared _contextContainer;
}
@end
#endif
2020-04-09 13:02:37 +05:00
@implementation AppDelegate
2021-02-25 02:43:54 +05:00
UINavigationController *navController;
UIViewController *rootViewController;
UIViewController *shareViewController;
RCTBridge *bridge;
2019-11-15 01:17:59 +05:00
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
2022-04-20 02:09:54 +05:00
RCTAppSetupPrepareApp(application);
2021-02-25 02:43:54 +05:00
shareViewController = [UIViewController new];
2022-04-20 02:09:54 +05:00
bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
2022-04-29 20:27:37 +05:00
2022-04-20 02:09:54 +05:00
#if RCT_NEW_ARCH_ENABLED
_contextContainer = std::make_shared<facebook::react::ContextContainer const>();
_reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
#endif
2022-04-29 20:27:37 +05:00
NSURL *url = (NSURL *) [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
if (url != nil) {
2021-02-25 02:43:54 +05:00
navController = [[UINavigationController alloc] initWithRootViewController:shareViewController];
2021-04-07 10:49:42 +05:00
} else {
2021-02-25 02:43:54 +05:00
rootViewController = [UIViewController new];
navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
2021-04-07 10:49:42 +05:00
}
2021-02-25 02:43:54 +05:00
navController.navigationBarHidden = YES;
2022-04-29 20:27:37 +05:00
if (url != nil) {
2021-02-25 02:43:54 +05:00
RCTRootView *shareView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"QuickNoteIOS"
initialProperties:nil];
2022-04-29 20:27:37 +05:00
if (@available(iOS 13.0, *)) {
shareView.backgroundColor = [UIColor systemBackgroundColor];
} else {
shareView.backgroundColor = [UIColor whiteColor];
}
2021-02-25 02:43:54 +05:00
shareViewController.view = shareView;
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:shareView];
2021-02-25 02:43:54 +05:00
} else {
2022-06-30 09:45:28 +05:00
NSDictionary *initProps = [self prepareInitialProps];
UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"Notesnook" , initProps);
2022-04-29 20:27:37 +05:00
if (@available(iOS 13.0, *)) {
rootView.backgroundColor = [UIColor systemBackgroundColor];
} else {
rootView.backgroundColor = [UIColor whiteColor];
}
2021-02-25 02:43:54 +05:00
rootViewController.view = rootView;
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView];
2021-02-25 02:43:54 +05:00
}
2022-04-29 20:27:37 +05:00
2019-11-15 01:17:59 +05:00
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
2022-04-29 23:20:12 +05:00
self.window.rootViewController = navController;
2019-11-15 01:17:59 +05:00
[self.window makeKeyAndVisible];
return YES;
}
2022-06-30 09:45:28 +05:00
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
// Switch this bool to turn on and off the concurrent root
return false;
}
- (NSDictionary *)prepareInitialProps
{
NSMutableDictionary *initProps = [NSMutableDictionary new];
#ifdef RCT_NEW_ARCH_ENABLED
initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);
#endif
return initProps;
}
2019-11-15 01:17:59 +05:00
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
2022-04-20 02:09:54 +05:00
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
2019-11-15 01:17:59 +05:00
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
2020-11-07 13:15:58 +05:00
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
2021-02-25 02:43:54 +05:00
if ([url.absoluteString isEqual:@"ShareMedia://QuickNoteWidget"]) {
if (rootViewController != nil) {
RCTRootView *shareView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"QuickNoteIOS"
initialProperties:nil];
shareView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
shareViewController.view = shareView;
[navController pushViewController:shareViewController animated:false];
}
}
if ([url.absoluteString isEqual:@"ShareMedia://MainApp"]) {
if (rootViewController == nil) {
UIApplication *app = [UIApplication sharedApplication];
[app performSelector:@selector(suspend)];
[NSThread sleepForTimeInterval:1.0];
exit(0);
} else {
UIApplication *app = [UIApplication sharedApplication];
[app performSelector:@selector(suspend)];
[NSThread sleepForTimeInterval:0.5];
[navController popToRootViewControllerAnimated:false];
2022-04-29 20:27:37 +05:00
2021-02-25 02:43:54 +05:00
}
}
2020-11-07 13:15:58 +05:00
return [RCTLinkingManager application:application openURL:url options:options];
}
2022-04-20 02:09:54 +05:00
#if RCT_NEW_ARCH_ENABLED
#pragma mark - RCTCxxBridgeDelegate
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
delegate:self
jsInvoker:bridge.jsCallInvoker];
return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
}
#pragma mark RCTTurboModuleManagerDelegate
- (Class)getModuleClassFromName:(const char *)name
{
return RCTCoreModulesClassProvider(name);
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
2022-04-29 20:27:37 +05:00
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
2022-04-20 02:09:54 +05:00
{
return nullptr;
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
2022-04-29 20:27:37 +05:00
initParams:
(const facebook::react::ObjCTurboModule::InitParams &)params
2022-04-20 02:09:54 +05:00
{
return nullptr;
}
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
{
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}
#endif
2022-04-29 20:27:37 +05:00
@end