@@ -86,62 +86,18 @@ - (instancetype)init
86
86
87
87
- (BOOL )application : (UIApplication *)application didFinishLaunchingWithOptions : (NSDictionary *)launchOptions
88
88
{
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 ;
107
91
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
+
140
94
#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 ;
142
97
#else
98
+ UIView* rootView = [self viewWithModuleName: self .moduleName initialProperties: [self prepareInitialProps ] launchOptions: launchOptions];
99
+
143
100
self.window = [[UIWindow alloc ] initWithFrame: [UIScreen mainScreen ].bounds];
144
- #endif
145
101
146
102
UIViewController *rootViewController = [self createRootViewController ];
147
103
[self setRootView: rootView toRootViewController: rootViewController];
@@ -150,6 +106,57 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
150
106
[self .window makeKeyAndVisible ];
151
107
152
108
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;
153
160
}
154
161
155
162
- (NSURL *)sourceURLForBridge : (RCTBridge *)bridge
@@ -212,45 +219,44 @@ - (void)windowScene:(UIWindowScene *)windowScene
212
219
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge : (RCTBridge *)bridge
213
220
{
214
221
_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
+ }
227
234
}
228
235
229
- #if RCT_NEW_ARCH_ENABLED
230
-
231
- #pragma mark - RCTTurboModuleManagerDelegate
236
+ #pragma mark - New Arch Enabled settings
232
237
233
- - (Class ) getModuleClassFromName : ( const char *) name
238
+ - (BOOL ) newArchEnabled
234
239
{
235
- return RCTCoreModulesClassProvider (name);
240
+ #if RCT_NEW_ARCH_ENABLED
241
+ return YES ;
242
+ #else
243
+ return NO ;
244
+ #endif
236
245
}
237
246
238
- - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
239
- jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
247
+ - (BOOL )turboModuleEnabled
240
248
{
241
- return nullptr ;
249
+ return [ self newArchEnabled ] ;
242
250
}
243
251
244
- - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
245
- initParams :
246
- (const facebook::react::ObjCTurboModule::InitParams &)params
252
+ - (BOOL )fabricEnabled
247
253
{
248
- return nullptr ;
254
+ return [ self newArchEnabled ] ;
249
255
}
250
256
251
- - (id <RCTTurboModule>) getModuleInstanceFromClass : ( Class ) moduleClass
257
+ - (BOOL ) bridgelessEnabled
252
258
{
253
- return RCTAppSetupDefaultModuleFromClass (moduleClass) ;
259
+ return NO ;
254
260
}
255
261
256
262
#pragma mark - RCTComponentViewFactoryComponentProvider
@@ -260,34 +266,38 @@ - (Class)getModuleClassFromName:(const char *)name
260
266
return @{};
261
267
}
262
268
263
- #pragma mark - New Arch Enabled settings
269
+ #pragma mark - RCTTurboModuleManagerDelegate
264
270
265
- - (BOOL ) turboModuleEnabled
271
+ - (Class ) getModuleClassFromName : ( const char *) name
266
272
{
267
- return YES ;
273
+ return RCTCoreModulesClassProvider (name) ;
268
274
}
269
275
270
- - (BOOL )fabricEnabled
276
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
277
+ jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
271
278
{
272
- return YES ;
279
+ return nullptr ;
273
280
}
274
281
275
- - (BOOL )bridgelessEnabled
282
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
283
+ initParams :
284
+ (const facebook::react::ObjCTurboModule::InitParams &)params
276
285
{
277
- return NO ;
286
+ return nullptr ;
278
287
}
279
288
280
- #pragma mark - New Arch Utilities
281
-
282
- - (void )unstable_registerLegacyComponents
289
+ - (id <RCTTurboModule>)getModuleInstanceFromClass : (Class )moduleClass
283
290
{
284
- for (NSString *legacyComponent in [RCTLegacyInteropComponents legacyInteropComponents ]) {
285
- [RCTLegacyViewManagerInteropComponentView supportLegacyViewManagerWithName: legacyComponent];
286
- }
291
+ return RCTAppSetupDefaultModuleFromClass (moduleClass);
287
292
}
288
293
294
+ #pragma mark - New Arch Utilities
295
+
289
296
- (void )createReactHost
290
297
{
298
+ if (_reactHost != nil ) {
299
+ return ;
300
+ }
291
301
__weak __typeof (self) weakSelf = self;
292
302
_reactHost = [[RCTHost alloc ] initWithBundleURL: [self getBundleURL ]
293
303
hostDelegate: nil
0 commit comments