39
39
#import < react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
40
40
#import < react/runtime/JSRuntimeFactory.h>
41
41
42
- static NSString *const kRNConcurrentRoot = @" concurrentRoot" ;
43
-
44
- @interface RCTAppDelegate () <
45
- RCTTurboModuleManagerDelegate,
46
- RCTComponentViewFactoryComponentProvider,
47
- RCTContextContainerHandling> {
48
- std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
49
- facebook::react::ContextContainer::Shared _contextContainer;
50
- }
51
- @end
52
-
53
- static NSDictionary *updateInitialProps (NSDictionary *initialProps, BOOL isFabricEnabled)
54
- {
55
- NSMutableDictionary *mutableProps = [initialProps mutableCopy ] ?: [NSMutableDictionary new ];
56
- // Hardcoding the Concurrent Root as it it not recommended to
57
- // have the concurrentRoot turned off when Fabric is enabled.
58
- mutableProps[kRNConcurrentRoot ] = @(isFabricEnabled);
59
- return mutableProps;
60
- }
61
-
62
- @interface RCTAppDelegate () <RCTCxxBridgeDelegate> {
63
- std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
64
- }
42
+ @interface RCTAppDelegate () <RCTComponentViewFactoryComponentProvider>
65
43
@end
66
44
67
- @implementation RCTAppDelegate {
68
- RCTHost *_reactHost;
69
- }
70
-
71
- - (instancetype )init
72
- {
73
- if (self = [super init ]) {
74
- _contextContainer = std::make_shared<facebook::react::ContextContainer const >();
75
- _reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const >();
76
- _contextContainer->insert (" ReactNativeConfig" , _reactNativeConfig);
77
- }
78
- return self;
79
- }
45
+ @implementation RCTAppDelegate
80
46
81
47
- (BOOL )application : (UIApplication *)application didFinishLaunchingWithOptions : (NSDictionary *)launchOptions
82
48
{
83
49
RCTSetNewArchEnabled ([self newArchEnabled ]);
84
50
BOOL enableTM = self.turboModuleEnabled ;
85
-
86
- RCTAppSetupPrepareApp (application, enableTM, *_reactNativeConfig);
87
51
88
- UIView *rootView = [self viewWithModuleName: self .moduleName initialProperties: [self prepareInitialProps ] launchOptions: launchOptions];
89
-
52
+ #pragma clang diagnostic push
53
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
54
+ RCTAppSetupPrepareApp (application, enableTM);
55
+ #pragma clang diagnostic pop
56
+
57
+ RCTRootViewFactoryConfiguration *configuration = [[RCTRootViewFactoryConfiguration alloc ] initWithBundleURL: self .bundleURL];
58
+ configuration.fabricEnabled = self.fabricEnabled ;
59
+ configuration.turboModuleEnabled = self.turboModuleEnabled ;
60
+ configuration.bridgelessEnabled = self.bridgelessEnabled ;
61
+
62
+ __weak __typeof (self) weakSelf = self;
63
+ configuration.createRootViewWithBridge = ^UIView* (RCTBridge *bridge, NSString *moduleName, NSDictionary *initProps) {
64
+ return [weakSelf createRootViewWithBridge: bridge moduleName: moduleName initProps: initProps];
65
+ };
66
+
67
+ configuration.createBridgeWithDelegate = ^RCTBridge* (id <RCTBridgeDelegate> delegate, NSDictionary * launchOptions) {
68
+ return [weakSelf createBridgeWithDelegate: delegate launchOptions: launchOptions];
69
+ };
70
+
71
+ self.rootViewFactory = [[RCTRootViewFactory alloc ] initWithConfiguration: configuration];
72
+
73
+ UIView *rootView = [self .rootViewFactory viewWithModuleName: self .moduleName
74
+ initialProperties: self .initialProps
75
+ launchOptions: launchOptions];
76
+
77
+ if (self.newArchEnabled || self.bridgelessEnabled ) {
78
+ [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
79
+ }
80
+
81
+ [self customizeRootView: (RCTRootView* )rootView];
82
+
90
83
self.window = [[UIWindow alloc ] initWithFrame: [UIScreen mainScreen ].bounds];
91
84
UIViewController *rootViewController = [self createRootViewController ];
92
85
[self setRootView: rootView toRootViewController: rootViewController];
@@ -97,55 +90,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
97
90
return YES ;
98
91
}
99
92
100
- - (UIView *)viewWithModuleName : (NSString *)moduleName
101
- initialProperties : (NSDictionary *)initialProperties
102
- launchOptions : (NSDictionary *)launchOptions {
103
- BOOL fabricEnabled = self.fabricEnabled ;
104
- BOOL enableBridgeless = self.bridgelessEnabled ;
105
-
106
- NSDictionary *initProps = updateInitialProps (initialProperties, fabricEnabled);
107
-
108
- UIView *rootView;
109
- if (enableBridgeless) {
110
- // Enable native view config interop only if both bridgeless mode and Fabric is enabled.
111
- RCTSetUseNativeViewConfigsInBridgelessMode (fabricEnabled);
112
-
113
- // Enable TurboModule interop by default in Bridgeless mode
114
- RCTEnableTurboModuleInterop (YES );
115
- RCTEnableTurboModuleInteropBridgeProxy (YES );
116
-
117
- if (!_reactHost) {
118
- [self createReactHost ];
119
- }
120
-
121
- [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
122
- RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName: self .moduleName initialProperties: initProps];
123
-
124
- RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc ]
125
- initWithSurface: surface
126
- sizeMeasureMode: RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
127
-
128
- rootView = (RCTRootView *)surfaceHostingProxyRootView;
129
- } else {
130
- if (!self.bridge ) {
131
- self.bridge = [self createBridgeWithDelegate: self launchOptions: launchOptions];
132
- }
133
- if ([self newArchEnabled ]) {
134
- if (!self.bridgeAdapter ) {
135
- self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc ] initWithBridge: self .bridge
136
- contextContainer: _contextContainer];
137
- self.bridge .surfacePresenter = self.bridgeAdapter .surfacePresenter ;
138
-
139
- [RCTComponentViewFactory currentComponentViewFactory ].thirdPartyFabricComponentsProvider = self;
140
- }
141
- }
142
- rootView = [self createRootViewWithBridge: self .bridge moduleName: self .moduleName initProps: initProps];
143
- }
144
- [self customizeRootView: (RCTRootView *)rootView];
145
-
146
- return rootView;
147
- }
148
-
149
93
- (void )applicationDidEnterBackground : (UIApplication *)application
150
94
{
151
95
// Noop
@@ -158,21 +102,11 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
158
102
return nil ;
159
103
}
160
104
161
- - (NSDictionary *)prepareInitialProps
162
- {
163
- return self.initialProps ;
164
- }
165
-
166
105
- (RCTBridge *)createBridgeWithDelegate : (id <RCTBridgeDelegate>)delegate launchOptions : (NSDictionary *)launchOptions
167
106
{
168
107
return [[RCTBridge alloc ] initWithDelegate: delegate launchOptions: launchOptions];
169
108
}
170
109
171
- - (void )customizeRootView : (RCTRootView *)rootView
172
- {
173
- // Override point for customization after application launch.
174
- }
175
-
176
110
- (UIView *)createRootViewWithBridge : (RCTBridge *)bridge
177
111
moduleName : (NSString *)moduleName
178
112
initProps : (NSDictionary *)initProps
@@ -211,9 +145,9 @@ - (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)
211
145
rootViewController.view = rootView;
212
146
}
213
147
214
- - (BOOL ) runtimeSchedulerEnabled
148
+ - (void ) customizeRootView : (RCTRootView *) rootView
215
149
{
216
- return YES ;
150
+ // Override point for customization after application launch.
217
151
}
218
152
219
153
#pragma mark - UISceneDelegate
@@ -225,24 +159,6 @@ - (void)windowScene:(UIWindowScene *)windowScene
225
159
[[NSNotificationCenter defaultCenter ] postNotificationName: RCTWindowFrameDidChangeNotification object: self ];
226
160
}
227
161
228
- #pragma mark - RCTCxxBridgeDelegate
229
- - (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge : (RCTBridge *)bridge
230
- {
231
- _runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge (bridge));
232
- if ([self newArchEnabled ]) {
233
- std::shared_ptr<facebook::react::CallInvoker> callInvoker =
234
- std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
235
- RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc ] initWithBridge: bridge
236
- delegate: self
237
- jsInvoker: callInvoker];
238
- _contextContainer->erase (" RuntimeScheduler" );
239
- _contextContainer->insert (" RuntimeScheduler" , _runtimeScheduler);
240
- return RCTAppSetupDefaultJsExecutorFactory (bridge, turboModuleManager, _runtimeScheduler);
241
- } else {
242
- return RCTAppSetupJsExecutorFactoryForOldArch (bridge, _runtimeScheduler);
243
- }
244
- }
245
-
246
162
#pragma mark - New Arch Enabled settings
247
163
248
164
- (BOOL )newArchEnabled
@@ -269,79 +185,18 @@ - (BOOL)bridgelessEnabled
269
185
return NO ;
270
186
}
271
187
272
- #pragma mark - RCTComponentViewFactoryComponentProvider
273
-
274
- - (NSDictionary <NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
275
- {
276
- return @{};
277
- }
278
-
279
- #pragma mark - RCTTurboModuleManagerDelegate
280
-
281
- - (Class )getModuleClassFromName : (const char *)name
282
- {
283
- #if RN_DISABLE_OSS_PLUGIN_HEADER
284
- return RCTTurboModulePluginClassProvider (name);
285
- #else
286
- return RCTCoreModulesClassProvider (name);
287
- #endif
288
- }
289
-
290
- - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
291
- jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
292
- {
293
- return nullptr ;
294
- }
295
-
296
- - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
297
- initParams :
298
- (const facebook::react::ObjCTurboModule::InitParams &)params
299
- {
188
+ - (NSURL *)bundleURL {
189
+ [NSException raise :@" RCTAppDelegate::bundleURL not implemented"
190
+ format: @" Subclasses must implement a valid getBundleURL method" ];
300
191
return nullptr ;
301
192
}
302
193
303
- - (id <RCTTurboModule>)getModuleInstanceFromClass : (Class )moduleClass
304
- {
305
- return RCTAppSetupDefaultModuleFromClass (moduleClass);
306
- }
307
-
308
- #pragma mark - New Arch Utilities
309
-
310
- - (void )createReactHost
311
- {
312
- __weak __typeof (self) weakSelf = self;
313
- _reactHost = [[RCTHost alloc ] initWithBundleURL: [self bundleURL ]
314
- hostDelegate: nil
315
- turboModuleManagerDelegate: self
316
- jsEngineProvider: ^std: :shared_ptr<facebook: :react: :JSRuntimeFactory>() {
317
- return [weakSelf createJSRuntimeFactory ];
318
- }];
319
- [_reactHost setBundleURLProvider: ^NSURL *() {
320
- return [weakSelf bundleURL ];
321
- }];
322
- [_reactHost setContextContainerHandler: self ];
323
- [_reactHost start ];
324
- }
325
-
326
- - (std::shared_ptr<facebook::react::JSRuntimeFactory>)createJSRuntimeFactory
327
- {
328
- #if USE_HERMES
329
- return std::make_shared<facebook::react::RCTHermesInstance>(_reactNativeConfig, nullptr );
330
- #else
331
- return std::make_shared<facebook::react::RCTJscInstance>();
332
- #endif
333
- }
334
194
335
- - (void )didCreateContextContainer : (std::shared_ptr<facebook::react::ContextContainer>)contextContainer
336
- {
337
- contextContainer->insert (" ReactNativeConfig" , _reactNativeConfig);
338
- }
195
+ #pragma mark - RCTComponentViewFactoryComponentProvider
339
196
340
- - (NSURL *) bundleURL
197
+ - (NSDictionary <NSString *, Class<RCTComponentViewProtocol>> *) thirdPartyFabricComponents
341
198
{
342
- [NSException raise :@" RCTAppDelegate::bundleURL not implemented"
343
- format: @" Subclasses must implement a valid getBundleURL method" ];
344
- return nullptr ;
199
+ return @{};
345
200
}
346
201
347
202
@end
0 commit comments