diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h index 7db5cc6b9c8..e0e316660b0 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h @@ -212,6 +212,15 @@ typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBloc #pragma mark - RCTRootViewFactory Helpers +/** + * Initialize React Host/Bridge without creating a view. + * + * Use it to speed up later viewWithModuleName: calls. + * + * @parameter: launchOptions - a dictionary with a set of options. + */ +- (void)initializeReactHostWithLaunchOptions:(NSDictionary *__nullable)launchOptions; + - (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions; @end diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm index 1ed25b29ba4..b25ee11ce90 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm @@ -132,9 +132,7 @@ return [self viewWithModuleName:moduleName initialProperties:nil launchOptions:nil]; } -- (UIView *)viewWithModuleName:(NSString *)moduleName - initialProperties:(NSDictionary *)initProps - launchOptions:(NSDictionary *)launchOptions +- (void)initializeReactHostWithLaunchOptions:(NSDictionary *)launchOptions { if (_configuration.bridgelessEnabled) { // Enable TurboModule interop by default in Bridgeless mode @@ -142,7 +140,20 @@ RCTEnableTurboModuleInteropBridgeProxy(YES); [self createReactHostIfNeeded:launchOptions]; + return; + } + [self createBridgeIfNeeded:launchOptions]; + [self createBridgeAdapterIfNeeded]; +} + +- (UIView *)viewWithModuleName:(NSString *)moduleName + initialProperties:(NSDictionary *)initProps + launchOptions:(NSDictionary *)launchOptions +{ + [self initializeReactHostWithLaunchOptions:launchOptions]; + + if (_configuration.bridgelessEnabled) { RCTFabricSurface *surface = [self.reactHost createSurfaceWithModuleName:moduleName initialProperties:initProps]; RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = @@ -155,9 +166,6 @@ return surfaceHostingProxyRootView; } - [self createBridgeIfNeeded:launchOptions]; - [self createBridgeAdapterIfNeeded]; - UIView *rootView; if (_configuration.createRootViewWithBridge != nil) { rootView = _configuration.createRootViewWithBridge(self.bridge, moduleName, initProps);