mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34384 This Diff aims to create a RCTAppDelegate library to offer a subclass which automates some operations required to set up the new architecture. ## Changelog [iOS][Added] - Added the RCTAppDelegate library Reviewed By: cortinico Differential Revision: D38580424 fbshipit-source-id: 38f6c4b8ff2790a2ce9e23d385b36307701cffb7
130 lines
4.0 KiB
Plaintext
130 lines
4.0 KiB
Plaintext
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTAppDelegate.h"
|
|
#import <React/RCTAppSetupUtils.h>
|
|
#import <React/RCTRootView.h>
|
|
|
|
#if RCT_NEW_ARCH_ENABLED
|
|
#import <React/CoreModulesPlugins.h>
|
|
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
|
|
#import <React/RCTSurfacePresenter.h>
|
|
#import <react/config/ReactNativeConfig.h>
|
|
|
|
static NSString *const kRNConcurrentRoot = @"concurrentRoot";
|
|
|
|
@interface RCTAppDelegate () {
|
|
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
|
|
facebook::react::ContextContainer::Shared _contextContainer;
|
|
}
|
|
@end
|
|
|
|
#endif
|
|
|
|
@implementation RCTAppDelegate
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
{
|
|
RCTAppSetupPrepareApp(application);
|
|
|
|
if (!self.bridge) {
|
|
self.bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
|
|
}
|
|
#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);
|
|
self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge contextContainer:_contextContainer];
|
|
self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;
|
|
#endif
|
|
|
|
NSDictionary *initProps = [self prepareInitialProps];
|
|
UIView *rootView = RCTAppSetupDefaultRootView(self.bridge, self.moduleName, initProps);
|
|
|
|
if (@available(iOS 13.0, *)) {
|
|
rootView.backgroundColor = [UIColor systemBackgroundColor];
|
|
} else {
|
|
rootView.backgroundColor = [UIColor whiteColor];
|
|
}
|
|
|
|
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
UIViewController *rootViewController = [UIViewController new];
|
|
rootViewController.view = rootView;
|
|
self.window.rootViewController = rootViewController;
|
|
[self.window makeKeyAndVisible];
|
|
return YES;
|
|
}
|
|
|
|
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
|
{
|
|
[NSException
|
|
raise:@"RCTBridgeDelegate::sourceURLForBridge not implemented"
|
|
format:@"Subclasses must implement a valid sourceURLForBridge method"
|
|
];
|
|
return nil;
|
|
}
|
|
|
|
- (BOOL)concurrentRootEnabled
|
|
{
|
|
[NSException
|
|
raise:@"concurrentRootEnabled not implemented"
|
|
format:@"Subclasses must implement a valid concurrentRootEnabled method"
|
|
];
|
|
return true;
|
|
}
|
|
|
|
- (NSDictionary *)prepareInitialProps
|
|
{
|
|
NSMutableDictionary *initProps = [NSMutableDictionary new];
|
|
|
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);
|
|
#endif
|
|
|
|
return initProps;
|
|
}
|
|
|
|
#if RCT_NEW_ARCH_ENABLED
|
|
#pragma mark - RCTCxxBridgeDelegate
|
|
|
|
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
|
|
{
|
|
self.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
|
|
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
|
initParams:
|
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
|
|
{
|
|
return RCTAppSetupDefaultModuleFromClass(moduleClass);
|
|
}
|
|
|
|
#endif
|
|
|
|
@end
|