Skip to content

Commit b0a1068

Browse files
coadofacebook-github-bot
authored andcommitted
iOS: Set RCTBundleConfiguration on RCTReactNativeFactory and pass it down to the RCTHost (#54256)
Summary: ## Summary In this diff the `RCTBundleConfiguration` is set on the `RCTReactNativeFactory` and passed down to the `RCTHost` instance where it is set on the bundle manager. The diff prepares bundle config for final usage by packager connection and bundle loader. Differential Revision: D85247248
1 parent be4ff3a commit b0a1068

File tree

6 files changed

+59
-16
lines changed

6 files changed

+59
-16
lines changed

packages/react-native/Libraries/AppDelegate/RCTReactNativeFactory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
@class RCTBridge;
2525
@protocol RCTComponentViewProtocol;
2626
@class RCTSurfacePresenterBridgeAdapter;
27+
@class RCTBundleConfiguration;
2728
@class RCTDevMenuConfiguration;
2829

2930
NS_ASSUME_NONNULL_BEGIN
@@ -117,6 +118,8 @@ typedef NS_ENUM(NSInteger, RCTReleaseLevel) { Canary, Experimental, Stable };
117118

118119
@property (nonatomic, weak) id<RCTReactNativeFactoryDelegate> delegate;
119120

121+
@property (nonatomic, strong, nonnull) RCTBundleConfiguration *bundleConfiguration;
122+
120123
@property (nonatomic, nullable) RCTDevMenuConfiguration *devMenuConfiguration;
121124

122125
@end

packages/react-native/Libraries/AppDelegate/RCTReactNativeFactory.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#import "RCTReactNativeFactory.h"
9+
#import <React/RCTBundleManager.h>
910
#import <React/RCTColorSpaceUtils.h>
1011
#import <React/RCTDevMenu.h>
1112
#import <React/RCTLog.h>
@@ -42,6 +43,8 @@ @interface RCTReactNativeFactory () <
4243

4344
@implementation RCTReactNativeFactory
4445

46+
@synthesize bundleConfiguration = _bundleConfiguration;
47+
4548
- (instancetype)initWithDelegate:(id<RCTReactNativeFactoryDelegate>)delegate
4649
{
4750
return [self initWithDelegate:delegate releaseLevel:Stable];
@@ -84,6 +87,7 @@ - (void)startReactNativeWithModuleName:(NSString *)moduleName
8487
UIView *rootView = [self.rootViewFactory viewWithModuleName:moduleName
8588
initialProperties:initialProperties
8689
launchOptions:launchOptions
90+
bundleConfiguration:self.bundleConfiguration
8791
devMenuConfiguration:self.devMenuConfiguration];
8892
UIViewController *rootViewController = [_delegate createRootViewController];
8993
[_delegate setRootView:rootView toRootViewController:rootViewController];
@@ -112,6 +116,14 @@ - (NSURL *_Nullable)bundleURL
112116
return _delegate.bundleURL;
113117
}
114118

119+
- (RCTBundleConfiguration *)bundleConfiguration
120+
{
121+
if (_bundleConfiguration == nullptr) {
122+
_bundleConfiguration = [RCTBundleConfiguration new];
123+
}
124+
return _bundleConfiguration;
125+
}
126+
115127
#pragma mark - RCTJSRuntimeConfiguratorProtocol
116128

117129
- (JSRuntimeFactoryRef)createJSRuntimeFactory

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@class RCTHost;
1919
@class RCTRootView;
2020
@class RCTSurfacePresenterBridgeAdapter;
21+
@class RCTBundleConfiguration;
2122
@class RCTDevMenuConfiguration;
2223

2324
NS_ASSUME_NONNULL_BEGIN
@@ -202,12 +203,14 @@ typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBloc
202203
* @parameter: moduleName - the name of the app, used by Metro to resolve the module.
203204
* @parameter: initialProperties - a set of initial properties.
204205
* @parameter: launchOptions - a dictionary with a set of options.
206+
* @parameter: bundleConfiguration - a configuration for custom bundle source URL.
205207
* @parameter: devMenuConfiguration - a configuration for enabling/disabling dev menu.
206208
*/
207209
- (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName
208210
initialProperties:(NSDictionary *__nullable)initialProperties
209211
launchOptions:(NSDictionary *__nullable)launchOptions
210-
devMenuConfiguration:(RCTDevMenuConfiguration *__nullable)devMenuConfiguration;
212+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
213+
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration;
211214

212215
- (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName
213216
initialProperties:(NSDictionary *__nullable)initialProperties
@@ -226,15 +229,18 @@ typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBloc
226229
* Use it to speed up later viewWithModuleName: calls.
227230
*
228231
* @parameter: launchOptions - a dictionary with a set of options.
232+
* @parameter: bundleConfiguration - a configuration for custom bundle source URL.
229233
* @parameter: devMenuConfiguration - a configuration for enabling/disabling dev menu.
230234
*/
231235
- (void)initializeReactHostWithLaunchOptions:(NSDictionary *__nullable)launchOptions
236+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
232237
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration;
233238

234-
- (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions;
235-
236239
- (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions
237-
devMenuConfiguration:(RCTDevMenuConfiguration *__nullable)devMenuConfiguration;
240+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
241+
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration;
242+
243+
- (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions;
238244

239245
@end
240246

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#else
2222
#import <React/CoreModulesPlugins.h>
2323
#endif
24-
#import <React/RCTBundleURLProvider.h>
2524
#import <React/RCTComponentViewFactory.h>
2625
#import <React/RCTComponentViewProtocol.h>
2726
#import <React/RCTFabricSurface.h>
@@ -137,6 +136,7 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName initialProperties:(NSDicti
137136
return [self viewWithModuleName:moduleName
138137
initialProperties:initialProperties
139138
launchOptions:nil
139+
bundleConfiguration:[RCTBundleConfiguration new]
140140
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
141141
}
142142

@@ -145,17 +145,21 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
145145
return [self viewWithModuleName:moduleName
146146
initialProperties:nil
147147
launchOptions:nil
148+
bundleConfiguration:[RCTBundleConfiguration new]
148149
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
149150
}
150151

151152
- (void)initializeReactHostWithLaunchOptions:(NSDictionary *)launchOptions
153+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
152154
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
153155
{
154156
// Enable TurboModule interop by default in Bridgeless mode
155157
RCTEnableTurboModuleInterop(YES);
156158
RCTEnableTurboModuleInteropBridgeProxy(YES);
157159

158-
[self createReactHostIfNeeded:launchOptions devMenuConfiguration:devMenuConfiguration];
160+
[self createReactHostIfNeeded:launchOptions
161+
bundleConfiguration:bundleConfiguration
162+
devMenuConfiguration:devMenuConfiguration];
159163
return;
160164
}
161165

@@ -166,15 +170,19 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
166170
return [self viewWithModuleName:moduleName
167171
initialProperties:initialProperties
168172
launchOptions:launchOptions
173+
bundleConfiguration:[RCTBundleConfiguration new]
169174
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
170175
}
171176

172177
- (UIView *)viewWithModuleName:(NSString *)moduleName
173178
initialProperties:(NSDictionary *)initProps
174179
launchOptions:(NSDictionary *)launchOptions
180+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
175181
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
176182
{
177-
[self initializeReactHostWithLaunchOptions:launchOptions devMenuConfiguration:devMenuConfiguration];
183+
[self initializeReactHostWithLaunchOptions:launchOptions
184+
bundleConfiguration:bundleConfiguration
185+
devMenuConfiguration:devMenuConfiguration];
178186

179187
RCTFabricSurface *surface = [self.reactHost createSurfaceWithModuleName:moduleName
180188
initialProperties:initProps ? initProps : @{}];
@@ -245,20 +253,27 @@ - (void)createBridgeAdapterIfNeeded
245253
#pragma mark - New Arch Utilities
246254

247255
- (void)createReactHostIfNeeded:(NSDictionary *)launchOptions
256+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
248257
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
249258
{
250259
if (self.reactHost) {
251260
return;
252261
}
253-
self.reactHost = [self createReactHost:launchOptions devMenuConfiguration:devMenuConfiguration];
262+
263+
self.reactHost = [self createReactHost:launchOptions
264+
bundleConfiguration:bundleConfiguration
265+
devMenuConfiguration:devMenuConfiguration];
254266
}
255267

256268
- (RCTHost *)createReactHost:(NSDictionary *)launchOptions
257269
{
258-
return [self createReactHost:launchOptions devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
270+
return [self createReactHost:launchOptions
271+
bundleConfiguration:[RCTBundleConfiguration new]
272+
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
259273
}
260274

261275
- (RCTHost *)createReactHost:(NSDictionary *)launchOptions
276+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
262277
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
263278
{
264279
__weak __typeof(self) weakSelf = self;
@@ -270,6 +285,7 @@ - (RCTHost *)createReactHost:(NSDictionary *)launchOptions
270285
return [weakSelf createJSRuntimeFactory];
271286
}
272287
launchOptions:launchOptions
288+
bundleConfiguration:bundleConfiguration
273289
devMenuConfiguration:devMenuConfiguration];
274290
[reactHost setBundleURLProvider:^NSURL *() {
275291
return [weakSelf bundleURL];

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
1818
@class RCTFabricSurface;
1919
@class RCTHost;
2020
@class RCTModuleRegistry;
21+
@class RCTBundleConfiguration;
2122
@class RCTDevMenuConfiguration;
2223

2324
@protocol RCTTurboModuleManagerDelegate;
@@ -65,8 +66,8 @@ typedef std::shared_ptr<facebook::react::JSRuntimeFactory> (^RCTHostJSEngineProv
6566
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
6667
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
6768
launchOptions:(nullable NSDictionary *)launchOptions
68-
devMenuConfiguration:(RCTDevMenuConfiguration *__nullable)devMenuConfiguration
69-
NS_DESIGNATED_INITIALIZER;
69+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
70+
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration NS_DESIGNATED_INITIALIZER;
7071

7172
- (instancetype)initWithBundleURLProvider:(RCTHostBundleURLProvider)provider
7273
hostDelegate:(id<RCTHostDelegate>)hostDelegate

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ - (instancetype)initWithBundleURL:(NSURL *)bundleURL
152152
launchOptions:launchOptions];
153153
}
154154

155-
/**
156-
Host initialization should not be resource intensive. A host may be created before any intention of using React Native
157-
has been expressed.
158-
*/
159155
- (instancetype)initWithBundleURLProvider:(RCTHostBundleURLProvider)provider
160156
hostDelegate:(id<RCTHostDelegate>)hostDelegate
161157
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
@@ -167,14 +163,20 @@ - (instancetype)initWithBundleURLProvider:(RCTHostBundleURLProvider)provider
167163
turboModuleManagerDelegate:turboModuleManagerDelegate
168164
jsEngineProvider:jsEngineProvider
169165
launchOptions:launchOptions
166+
bundleConfiguration:[RCTBundleConfiguration new]
170167
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
171168
}
172169

170+
/**
171+
Host initialization should not be resource intensive. A host may be created before any intention of using React Native
172+
has been expressed.
173+
*/
173174
- (instancetype)initWithBundleURLProvider:(RCTHostBundleURLProvider)provider
174175
hostDelegate:(id<RCTHostDelegate>)hostDelegate
175176
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
176177
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
177178
launchOptions:(nullable NSDictionary *)launchOptions
179+
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
178180
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
179181
{
180182
if (self = [super init]) {
@@ -184,6 +186,9 @@ - (instancetype)initWithBundleURLProvider:(RCTHostBundleURLProvider)provider
184186
_moduleRegistry = [RCTModuleRegistry new];
185187
_jsEngineProvider = [jsEngineProvider copy];
186188
_launchOptions = [launchOptions copy];
189+
_bundleManager.bundleConfig = bundleConfiguration;
190+
191+
[self setBundleURLProvider:provider];
187192

188193
__weak RCTHost *weakSelf = self;
189194
auto bundleURLGetter = ^NSURL *() {
@@ -450,7 +455,7 @@ - (void)_setBundleURL:(NSURL *)bundleURL
450455
// Sanitize the bundle URL
451456
_bundleURL = [RCTConvert NSURL:_bundleURL.absoluteString];
452457

453-
// Update the global bundle URLq
458+
// Update the global bundle URL
454459
RCTReloadCommandSetBundleURL(_bundleURL);
455460
}
456461

0 commit comments

Comments
 (0)