@@ -86,62 +86,18 @@ - (instancetype)init
8686
8787- (BOOL )application : (UIApplication *)application didFinishLaunchingWithOptions : (NSDictionary *)launchOptions
8888{
89- BOOL enableTM = NO ;
90- BOOL enableBridgeless = NO ;
91- BOOL fabricEnabled = NO ;
92- #if RCT_NEW_ARCH_ENABLED
93- enableTM = self.turboModuleEnabled ;
94- enableBridgeless = self.bridgelessEnabled ;
95- fabricEnabled = [self fabricEnabled ];
96- #endif
97- NSDictionary *initProps = updateInitialProps ([self prepareInitialProps ], fabricEnabled);
98-
99- RCTAppSetupPrepareApp (application, enableTM);
100-
101- UIView *rootView;
102-
103- if (enableBridgeless) {
104- #if RCT_NEW_ARCH_ENABLED
105- // Enable native view config interop only if both bridgeless mode and Fabric is enabled.
106- RCTSetUseNativeViewConfigsInBridgelessMode (fabricEnabled);
89+ RCTSetNewArchEnabled ([self newArchEnabled ]);
90+ BOOL enableTM = self.turboModuleEnabled ;
10791
108- // Enable TurboModule interop by default in Bridgeless mode
109- RCTEnableTurboModuleInterop (YES );
110- RCTEnableTurboModuleInteropBridgeProxy (YES );
111-
112- [self createReactHost ];
113- [self unstable_registerLegacyComponents ];
114- [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
115- RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName: self .moduleName initialProperties: initProps];
116-
117- RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc ]
118- initWithSurface: surface
119- sizeMeasureMode: RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
120-
121- rootView = (RCTRootView *)surfaceHostingProxyRootView;
122- #endif
123- } else {
124- if (!self.bridge ) {
125- self.bridge = [self createBridgeWithDelegate: self launchOptions: launchOptions];
126- }
127- #if RCT_NEW_ARCH_ENABLED
128- self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc ] initWithBridge: self .bridge
129- contextContainer: _contextContainer];
130- self.bridge .surfacePresenter = self.bridgeAdapter .surfacePresenter ;
131-
132- [self unstable_registerLegacyComponents ];
133- [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
134- #endif
135-
136- rootView = [self createRootViewWithBridge: self .bridge moduleName: self .moduleName initProps: initProps];
137- }
138-
139- [self customizeRootView: (RCTRootView *)rootView];
92+ RCTAppSetupPrepareApp (application, enableTM, *_reactNativeConfig);
93+
14094#if TARGET_OS_VISION
141- self.window = [[UIWindow alloc ] initWithFrame: RCTForegroundWindow ().bounds];
95+ // / Bail out of UIWindow initializaiton to support multi-window scenarios in SwiftUI lifecycle.
96+ return YES ;
14297#else
98+ UIView* rootView = [self viewWithModuleName: self .moduleName initialProperties: [self prepareInitialProps ] launchOptions: launchOptions];
99+
143100 self.window = [[UIWindow alloc ] initWithFrame: [UIScreen mainScreen ].bounds];
144- #endif
145101
146102 UIViewController *rootViewController = [self createRootViewController ];
147103 [self setRootView: rootView toRootViewController: rootViewController];
@@ -150,6 +106,57 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
150106 [self .window makeKeyAndVisible ];
151107
152108 return YES ;
109+ #endif
110+ }
111+
112+ - (void )applicationDidEnterBackground : (UIApplication *)application
113+ {
114+ // Noop
115+ }
116+
117+ - (UIView *)viewWithModuleName : (NSString *)moduleName initialProperties : (NSDictionary *)initialProperties launchOptions : (NSDictionary *)launchOptions {
118+ BOOL fabricEnabled = self.fabricEnabled ;
119+ BOOL enableBridgeless = self.bridgelessEnabled ;
120+
121+ NSDictionary *initProps = updateInitialProps (initialProperties, fabricEnabled);
122+
123+ UIView *rootView;
124+ if (enableBridgeless) {
125+ // Enable native view config interop only if both bridgeless mode and Fabric is enabled.
126+ RCTSetUseNativeViewConfigsInBridgelessMode (self.fabricEnabled );
127+
128+ // Enable TurboModule interop by default in Bridgeless mode
129+ RCTEnableTurboModuleInterop (YES );
130+ RCTEnableTurboModuleInteropBridgeProxy (YES );
131+
132+ [self createReactHost ];
133+ [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
134+ RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName: self .moduleName initialProperties: initProps];
135+
136+ RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc ]
137+ initWithSurface: surface
138+ sizeMeasureMode: RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
139+
140+ rootView = (RCTRootView *)surfaceHostingProxyRootView;
141+ } else {
142+ if (!self.bridge ) {
143+ self.bridge = [self createBridgeWithDelegate: self launchOptions: launchOptions];
144+ }
145+ if ([self newArchEnabled ]) {
146+ if (!self.bridgeAdapter ) {
147+ self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc ] initWithBridge: self .bridge
148+ contextContainer: _contextContainer];
149+ self.bridge .surfacePresenter = self.bridgeAdapter .surfacePresenter ;
150+
151+ [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
152+ }
153+ }
154+ rootView = [self createRootViewWithBridge: self .bridge moduleName: moduleName initProps: initProps];
155+ }
156+
157+ [self customizeRootView: (RCTRootView *)rootView];
158+
159+ return rootView;
153160}
154161
155162- (NSURL *)sourceURLForBridge : (RCTBridge *)bridge
@@ -212,45 +219,44 @@ - (void)windowScene:(UIWindowScene *)windowScene
212219- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge : (RCTBridge *)bridge
213220{
214221 _runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge (bridge));
215- # if RCT_NEW_ARCH_ENABLED
216- std::shared_ptr<facebook::react::CallInvoker> callInvoker =
217- std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
218- RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc ] initWithBridge: bridge
219- delegate: self
220- jsInvoker: callInvoker];
221- _contextContainer->erase (" RuntimeScheduler" );
222- _contextContainer->insert (" RuntimeScheduler" , _runtimeScheduler);
223- return RCTAppSetupDefaultJsExecutorFactory (bridge, turboModuleManager, _runtimeScheduler);
224- # else
225- return RCTAppSetupJsExecutorFactoryForOldArch (bridge, _runtimeScheduler);
226- # endif
222+ if ([ self newArchEnabled ]) {
223+ std::shared_ptr<facebook::react::CallInvoker> callInvoker =
224+ std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
225+ RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc ] initWithBridge: bridge
226+ delegate: self
227+ jsInvoker: callInvoker];
228+ _contextContainer->erase (" RuntimeScheduler" );
229+ _contextContainer->insert (" RuntimeScheduler" , _runtimeScheduler);
230+ return RCTAppSetupDefaultJsExecutorFactory (bridge, turboModuleManager, _runtimeScheduler);
231+ } else {
232+ return RCTAppSetupJsExecutorFactoryForOldArch (bridge, _runtimeScheduler);
233+ }
227234}
228235
229- #if RCT_NEW_ARCH_ENABLED
230-
231- #pragma mark - RCTTurboModuleManagerDelegate
236+ #pragma mark - New Arch Enabled settings
232237
233- - (Class ) getModuleClassFromName : ( const char *) name
238+ - (BOOL ) newArchEnabled
234239{
235- return RCTCoreModulesClassProvider (name);
240+ #if RCT_NEW_ARCH_ENABLED
241+ return YES ;
242+ #else
243+ return NO ;
244+ #endif
236245}
237246
238- - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
239- jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
247+ - (BOOL )turboModuleEnabled
240248{
241- return nullptr ;
249+ return [ self newArchEnabled ] ;
242250}
243251
244- - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
245- initParams :
246- (const facebook::react::ObjCTurboModule::InitParams &)params
252+ - (BOOL )fabricEnabled
247253{
248- return nullptr ;
254+ return [ self newArchEnabled ] ;
249255}
250256
251- - (id <RCTTurboModule>) getModuleInstanceFromClass : ( Class ) moduleClass
257+ - (BOOL ) bridgelessEnabled
252258{
253- return RCTAppSetupDefaultModuleFromClass (moduleClass) ;
259+ return NO ;
254260}
255261
256262#pragma mark - RCTComponentViewFactoryComponentProvider
@@ -260,34 +266,38 @@ - (Class)getModuleClassFromName:(const char *)name
260266 return @{};
261267}
262268
263- #pragma mark - New Arch Enabled settings
269+ #pragma mark - RCTTurboModuleManagerDelegate
264270
265- - (BOOL ) turboModuleEnabled
271+ - (Class ) getModuleClassFromName : ( const char *) name
266272{
267- return YES ;
273+ return RCTCoreModulesClassProvider (name) ;
268274}
269275
270- - (BOOL )fabricEnabled
276+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
277+ jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
271278{
272- return YES ;
279+ return nullptr ;
273280}
274281
275- - (BOOL )bridgelessEnabled
282+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
283+ initParams :
284+ (const facebook::react::ObjCTurboModule::InitParams &)params
276285{
277- return NO ;
286+ return nullptr ;
278287}
279288
280- #pragma mark - New Arch Utilities
281-
282- - (void )unstable_registerLegacyComponents
289+ - (id <RCTTurboModule>)getModuleInstanceFromClass : (Class )moduleClass
283290{
284- for (NSString *legacyComponent in [RCTLegacyInteropComponents legacyInteropComponents ]) {
285- [RCTLegacyViewManagerInteropComponentView supportLegacyViewManagerWithName: legacyComponent];
286- }
291+ return RCTAppSetupDefaultModuleFromClass (moduleClass);
287292}
288293
294+ #pragma mark - New Arch Utilities
295+
289296- (void )createReactHost
290297{
298+ if (_reactHost != nil ) {
299+ return ;
300+ }
291301 __weak __typeof (self) weakSelf = self;
292302 _reactHost = [[RCTHost alloc ] initWithBundleURL: [self getBundleURL ]
293303 hostDelegate: nil
0 commit comments