Skip to content

Commit

Permalink
Simplify EXDevLauncherBridgeDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel committed May 22, 2023
1 parent ec7fac2 commit 00ae79a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 64 deletions.
5 changes: 2 additions & 3 deletions packages/expo-dev-launcher/ios/EXDevLauncherBridgeDelegate.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTBridgeDelegate.h>
#import <React-RCTAppDelegate/RCTAppDelegate.h>
#import <React/RCTRootView.h>

@interface EXDevLauncherBridgeDelegate : NSObject <RCTBridgeDelegate>
@interface EXDevLauncherBridgeDelegate : RCTAppDelegate

- (RCTRootView *)createRootViewWithModuleName:(NSString *)moduleName
launchOptions:(NSDictionary *_Nullable)launchOptions
Expand Down
85 changes: 24 additions & 61 deletions packages/expo-dev-launcher/ios/EXDevLauncherBridgeDelegate.mm
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#import <React/RCTRootView.h>

#import "EXDevLauncherBridgeDelegate.h"

#import "EXDevLauncherController.h"
#import "EXDevLauncherRCTBridge.h"

#import <React/RCTBundleURLProvider.h>
#import "React/RCTAppSetupUtils.h"

#if RCT_NEW_ARCH_ENABLED
#import <memory>
Expand All @@ -25,13 +24,9 @@

#endif

#import "React/RCTAppSetupUtils.h"

@interface EXDevLauncherBridgeDelegate () <RCTTurboModuleManagerDelegate, RCTCxxBridgeDelegate, RCTBridgeDelegate> {
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
@interface EXDevLauncherBridgeDelegate () <RCTTurboModuleManagerDelegate, RCTCxxBridgeDelegate> {
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
facebook::react::ContextContainer::Shared _contextContainer;
RCTTurboModuleManager *turboModuleManager;
}
@end

Expand All @@ -41,71 +36,39 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
return [[EXDevLauncherController sharedInstance] sourceURLForBridge:bridge];
}

- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
return [[EXDevLauncherController sharedInstance] extraModulesForBridge:bridge];
}

- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
delegate:self
jsInvoker:bridge.jsCallInvoker];
return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager);
}

- (Class)getModuleClassFromName:(const char *)name
{
return RCTCoreModulesClassProvider(name);
}


- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
{
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}

- (BOOL)turboModuleEnabled
{
return YES;
}

- (BOOL)fabricEnabled
{
return YES;
}

- (RCTRootView *)createRootViewWithModuleName:(NSString *)moduleName launchOptions:(NSDictionary * _Nullable)launchOptions application:(UIApplication *)application{
BOOL enableTM = NO;
#if RCT_NEW_ARCH_ENABLED
enableTM = YES;
#endif
#if RCT_NEW_ARCH_ENABLED
enableTM = YES;
#endif

RCTAppSetupPrepareApp(application, enableTM);

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

#if RCT_NEW_ARCH_ENABLED
if (!self.bridge) {
self.bridge = [self createBridgeWithDelegate: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);

_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge
contextContainer:_contextContainer];
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
#endif
self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
contextContainer:_contextContainer];
self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;
#endif

NSMutableDictionary *initProps = [NSMutableDictionary new];
#ifdef RCT_NEW_ARCH_ENABLED
initProps[kRNConcurrentRoot] = @YES;
#endif
#ifdef RCT_NEW_ARCH_ENABLED
initProps[kRNConcurrentRoot] = @YES;
#endif


BOOL enableFabric = NO;
#if RCT_NEW_ARCH_ENABLED
enableFabric = TRUE;
#endif
return [super createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps];
}

return RCTAppSetupDefaultRootView(bridge, moduleName, initProps, enableFabric);
- (BOOL)concurrentRootEnabled
{
return true;
}

@end

0 comments on commit 00ae79a

Please sign in to comment.