@@ -86,10 +86,17 @@ - (instancetype)init
8686
8787- (BOOL )application : (UIApplication *)application didFinishLaunchingWithOptions : (NSDictionary *)launchOptions
8888{
89- RCTSetNewArchEnabled ([self newArchEnabled ]);
90- BOOL enableTM = self.turboModuleEnabled ;
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+
98+ RCTAppSetupPrepareApp (application, enableTM);
9199
92- RCTAppSetupPrepareApp (application, enableTM, *_reactNativeConfig);
93100
94101#if TARGET_OS_VISION
95102 // / Bail out of UIWindow initializaiton to support multi-window scenarios in SwiftUI lifecycle.
@@ -115,48 +122,52 @@ - (void)applicationDidEnterBackground:(UIApplication *)application
115122}
116123
117124- (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);
125+ BOOL enableTM = NO ;
126+ BOOL enableBridgeless = NO ;
127+ BOOL fabricEnabled = NO ;
128+ #if RCT_NEW_ARCH_ENABLED
129+ enableTM = self.turboModuleEnabled ;
130+ enableBridgeless = self.bridgelessEnabled ;
131+ fabricEnabled = [self fabricEnabled ];
132+ #endif
133+ UIView *rootView;
134+
135+ if (enableBridgeless) {
136+ #if RCT_NEW_ARCH_ENABLED
137+ // Enable native view config interop only if both bridgeless mode and Fabric is enabled.
138+ RCTSetUseNativeViewConfigsInBridgelessMode (fabricEnabled);
122139
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];
140+ // Enable TurboModule interop by default in Bridgeless mode
141+ RCTEnableTurboModuleInterop (YES );
142+ RCTEnableTurboModuleInteropBridgeProxy (YES );
143+
144+ [self createReactHost ];
145+ [self unstable_registerLegacyComponents ];
146+ [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
147+ RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName: moduleName initialProperties: initialProperties];
148+
149+ RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc ]
150+ initWithSurface: surface
151+ sizeMeasureMode: RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
152+
153+ rootView = (RCTRootView *)surfaceHostingProxyRootView;
154+ #endif
155+ } else {
156+ if (!self.bridge ) {
157+ self.bridge = [self createBridgeWithDelegate: self launchOptions: launchOptions];
155158 }
156-
157- [self customizeRootView: (RCTRootView *)rootView];
159+ #if RCT_NEW_ARCH_ENABLED
160+ self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc ] initWithBridge: self .bridge
161+ contextContainer: _contextContainer];
162+ self.bridge .surfacePresenter = self.bridgeAdapter .surfacePresenter ;
158163
159- return rootView;
164+ [self unstable_registerLegacyComponents ];
165+ [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
166+ #endif
167+
168+ rootView = [self createRootViewWithBridge: self .bridge moduleName: moduleName initProps: initialProperties];
169+ }
170+ return rootView;
160171}
161172
162173- (NSURL *)sourceURLForBridge : (RCTBridge *)bridge
@@ -219,20 +230,19 @@ - (void)windowScene:(UIWindowScene *)windowScene
219230- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge : (RCTBridge *)bridge
220231{
221232 _runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge (bridge));
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- }
233+ # if RCT_NEW_ARCH_ENABLED
234+ std::shared_ptr<facebook::react::CallInvoker> callInvoker =
235+ std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
236+ RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc ] initWithBridge: bridge
237+ delegate: self
238+ jsInvoker: callInvoker];
239+ _contextContainer->erase (" RuntimeScheduler" );
240+ _contextContainer->insert (" RuntimeScheduler" , _runtimeScheduler);
241+ return RCTAppSetupDefaultJsExecutorFactory (bridge, turboModuleManager, _runtimeScheduler);
242+ # else
243+ return RCTAppSetupJsExecutorFactoryForOldArch (bridge, _runtimeScheduler);
244+ # endif
234245}
235-
236246#pragma mark - New Arch Enabled settings
237247
238248- (BOOL )newArchEnabled
@@ -259,6 +269,15 @@ - (BOOL)bridgelessEnabled
259269 return NO ;
260270}
261271
272+ #pragma mark - New Arch Utilities
273+
274+ - (void )unstable_registerLegacyComponents
275+ {
276+ for (NSString *legacyComponent in [RCTLegacyInteropComponents legacyInteropComponents ]) {
277+ [RCTLegacyViewManagerInteropComponentView supportLegacyViewManagerWithName: legacyComponent];
278+ }
279+ }
280+
262281#pragma mark - RCTComponentViewFactoryComponentProvider
263282
264283- (NSDictionary <NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
0 commit comments