Skip to content

Instantly share code, notes, and snippets.

@janicduplessis
Created August 26, 2019 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janicduplessis/4686db5b0bdc3141911d0a3c1da45b66 to your computer and use it in GitHub Desktop.
Save janicduplessis/4686db5b0bdc3141911d0a3c1da45b66 to your computer and use it in GitHub Desktop.
#import "AppDelegate.h"
#import <React/CoreModulesPlugins.h>
#import <React/JSCExecutorFactory.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTJavaScriptLoader.h>
#import <React/RCTLinkingManager.h>
#import <React/RCTRootView.h>
#import <ReactCommon/RCTTurboModule.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <cxxreact/JSExecutor.h>
// To enable fabric add `-DRN_FABRIC_ENABLED=1` to other cpp flags.
#ifdef RN_FABRIC_ENABLED
#import <React/RCTSurfacePresenter.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#endif
@interface AppDelegate() <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate>
{
RCTTurboModuleManager *_turboModuleManager;
#ifdef RN_FABRIC_ENABLED
RCTSurfacePresenter *_surfacePresenter;
#endif
}
@end
@implementation AppDelegate
# pragma mark - UIApplicationDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTEnableTurboModule(YES);
_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
#ifdef RN_FABRIC_ENABLED
_surfacePresenter = [[RCTSurfacePresenter alloc] initWithBridge:_bridge
config:nil
imageLoader:[_bridge moduleForName:@"ImageLoader" lazilyLoadIfNecessary:YES]
runtimeExecutor:nullptr];
_bridge.surfacePresenter = _surfacePresenter;
UIView *rootView = [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:_bridge moduleName:@"th3rdwave" initialProperties:@{}];
#else
UIView *rootView = [[RCTRootView alloc] initWithBridge:_bridge
moduleName:@"th3rdwave"
initialProperties:nil];
#endif
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.tintColor = [UIColor colorWithRed:81.0 / 255.0 green:206.0 / 255.0 blue:191.0 / 255.0 alpha:1];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
# pragma mark - RCTCxxBridgeDelegate
- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"apps/app/index" fallbackResource:nil];
#else
return [CodePush bundleURL];
#endif
}
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge delegate:self];
__weak __typeof(self) weakSelf = self;
return std::make_unique<facebook::react::JSCExecutorFactory>([weakSelf, bridge](facebook::jsi::Runtime &runtime) {
if (!bridge) {
return;
}
__typeof(self) strongSelf = weakSelf;
if (strongSelf) {
[strongSelf->_turboModuleManager installJSBindingWithRuntime:&runtime];
}
});
}
- (Class)getModuleClassFromName:(const char *)name
{
return RCTCoreModulesClassProvider(name);
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(__unused const std::string &)name
jsInvoker:(__unused std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker
{
return nullptr;
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(__unused const std::string &)name
instance:(__unused id<RCTTurboModule>)instance
jsInvoker:(__unused std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker
{
return nullptr;
}
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
{
// No custom initializer here.
return [moduleClass new];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment