Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@class RCTBridge;
@protocol RCTComponentViewProtocol;
@class RCTSurfacePresenterBridgeAdapter;
@class RCTBundleConfiguration;
@class RCTDevMenuConfiguration;

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

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

@property (nonatomic, strong, nonnull) RCTBundleConfiguration *bundleConfiguration;

@property (nonatomic, nullable) RCTDevMenuConfiguration *devMenuConfiguration;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#import "RCTReactNativeFactory.h"
#import <React/RCTBundleManager.h>
#import <React/RCTColorSpaceUtils.h>
#import <React/RCTDevMenu.h>
#import <React/RCTLog.h>
Expand Down Expand Up @@ -42,6 +43,8 @@ @interface RCTReactNativeFactory () <

@implementation RCTReactNativeFactory

@synthesize bundleConfiguration = _bundleConfiguration;

- (instancetype)initWithDelegate:(id<RCTReactNativeFactoryDelegate>)delegate
{
return [self initWithDelegate:delegate releaseLevel:Stable];
Expand Down Expand Up @@ -84,6 +87,7 @@ - (void)startReactNativeWithModuleName:(NSString *)moduleName
UIView *rootView = [self.rootViewFactory viewWithModuleName:moduleName
initialProperties:initialProperties
launchOptions:launchOptions
bundleConfiguration:self.bundleConfiguration
devMenuConfiguration:self.devMenuConfiguration];
UIViewController *rootViewController = [_delegate createRootViewController];
[_delegate setRootView:rootView toRootViewController:rootViewController];
Expand Down Expand Up @@ -112,6 +116,14 @@ - (NSURL *_Nullable)bundleURL
return _delegate.bundleURL;
}

- (RCTBundleConfiguration *)bundleConfiguration
{
if (_bundleConfiguration == nullptr) {
_bundleConfiguration = [RCTBundleConfiguration defaultConfiguration];
}
return _bundleConfiguration;
}

#pragma mark - RCTJSRuntimeConfiguratorProtocol

- (JSRuntimeFactoryRef)createJSRuntimeFactory
Expand Down
14 changes: 10 additions & 4 deletions packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@class RCTHost;
@class RCTRootView;
@class RCTSurfacePresenterBridgeAdapter;
@class RCTBundleConfiguration;
@class RCTDevMenuConfiguration;

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -202,12 +203,14 @@ typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBloc
* @parameter: moduleName - the name of the app, used by Metro to resolve the module.
* @parameter: initialProperties - a set of initial properties.
* @parameter: launchOptions - a dictionary with a set of options.
* @parameter: bundleConfiguration - a configuration for custom bundle source URL.
* @parameter: devMenuConfiguration - a configuration for enabling/disabling dev menu.
*/
- (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *__nullable)initialProperties
launchOptions:(NSDictionary *__nullable)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *__nullable)devMenuConfiguration;
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration;

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

- (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions;

- (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *__nullable)devMenuConfiguration;
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration;

- (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions;

@end

Expand Down
26 changes: 21 additions & 5 deletions packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#else
#import <React/CoreModulesPlugins.h>
#endif
#import <React/RCTBundleURLProvider.h>
#import <React/RCTComponentViewFactory.h>
#import <React/RCTComponentViewProtocol.h>
#import <React/RCTFabricSurface.h>
Expand Down Expand Up @@ -137,6 +136,7 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName initialProperties:(NSDicti
return [self viewWithModuleName:moduleName
initialProperties:initialProperties
launchOptions:nil
bundleConfiguration:[RCTBundleConfiguration defaultConfiguration]
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
}

Expand All @@ -145,17 +145,21 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
return [self viewWithModuleName:moduleName
initialProperties:nil
launchOptions:nil
bundleConfiguration:[RCTBundleConfiguration defaultConfiguration]
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
}

- (void)initializeReactHostWithLaunchOptions:(NSDictionary *)launchOptions
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
// Enable TurboModule interop by default in Bridgeless mode
RCTEnableTurboModuleInterop(YES);
RCTEnableTurboModuleInteropBridgeProxy(YES);

[self createReactHostIfNeeded:launchOptions devMenuConfiguration:devMenuConfiguration];
[self createReactHostIfNeeded:launchOptions
bundleConfiguration:bundleConfiguration
devMenuConfiguration:devMenuConfiguration];
return;
}

Expand All @@ -166,15 +170,19 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
return [self viewWithModuleName:moduleName
initialProperties:initialProperties
launchOptions:launchOptions
bundleConfiguration:[RCTBundleConfiguration defaultConfiguration]
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
}

- (UIView *)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initProps
launchOptions:(NSDictionary *)launchOptions
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
[self initializeReactHostWithLaunchOptions:launchOptions devMenuConfiguration:devMenuConfiguration];
[self initializeReactHostWithLaunchOptions:launchOptions
bundleConfiguration:bundleConfiguration
devMenuConfiguration:devMenuConfiguration];

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

- (void)createReactHostIfNeeded:(NSDictionary *)launchOptions
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
if (self.reactHost) {
return;
}
self.reactHost = [self createReactHost:launchOptions devMenuConfiguration:devMenuConfiguration];

self.reactHost = [self createReactHost:launchOptions
bundleConfiguration:bundleConfiguration
devMenuConfiguration:devMenuConfiguration];
}

- (RCTHost *)createReactHost:(NSDictionary *)launchOptions
{
return [self createReactHost:launchOptions devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
return [self createReactHost:launchOptions
bundleConfiguration:[RCTBundleConfiguration defaultConfiguration]
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
}

- (RCTHost *)createReactHost:(NSDictionary *)launchOptions
bundleConfiguration:(RCTBundleConfiguration *)bundleConfiguration
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
__weak __typeof(self) weakSelf = self;
Expand All @@ -270,6 +285,7 @@ - (RCTHost *)createReactHost:(NSDictionary *)launchOptions
return [weakSelf createJSRuntimeFactory];
}
launchOptions:launchOptions
bundleConfiguration:bundleConfiguration
devMenuConfiguration:devMenuConfiguration];
[reactHost setBundleURLProvider:^NSURL *() {
return [weakSelf bundleURL];
Expand Down
66 changes: 59 additions & 7 deletions packages/react-native/React/Base/RCTBundleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,71 @@

@class RCTBridge;

typedef NSURL * (^RCTBridgelessBundleURLGetter)(void);
typedef void (^RCTBridgelessBundleURLSetter)(NSURL *bundleURL);
typedef NSURL *_Nullable (^RCTBridgelessBundleURLGetter)(void);
typedef void (^RCTBridgelessBundleURLSetter)(NSURL *_Nullable bundleURL);
typedef NSMutableArray<NSURLQueryItem *> *_Nullable (^RCTPackagerOptionsUpdater)(
NSMutableArray<NSURLQueryItem *> *_Nullable options);

/**
* Configuration class for setting up custom bundle locations
*/
@interface RCTBundleConfiguration : NSObject

+ (nonnull instancetype)defaultConfiguration;

/**
* The URL of the bundle to load from the file system
*/
@property (nonatomic, readonly, nullable) NSURL *bundleFilePath;

/**
* The server scheme (e.g. http or https) to use when loading from the packager
*/
@property (nonatomic, readonly, nullable) NSString *packagerServerScheme;

/**
* The server host (e.g. localhost) to use when loading from the packager
*/
@property (nonatomic, readonly, nullable) NSString *packagerServerHost;

/**
* A block that modifies the packager options when loading from the packager
*/
@property (nonatomic, copy, nullable) RCTPackagerOptionsUpdater packagerOptionsUpdater;

/**
* The relative path to the bundle.
*/
@property (nonatomic, readonly, nullable) NSString *bundlePath;

- (nonnull instancetype)initWithBundleFilePath:(nullable NSURL *)bundleFilePath;

- (nonnull instancetype)initWithPackagerServerScheme:(nullable NSString *)packagerServerScheme
packagerServerHost:(nullable NSString *)packagerServerHost
bundlePath:(nullable NSString *)bundlePath;

- (nullable NSURL *)getBundleURL;

- (nonnull NSString *)getPackagerServerScheme;

- (nonnull NSString *)getPackagerServerHost;

@end

/**
* A class that allows NativeModules/TurboModules to read/write the bundleURL, with or without the bridge.
*/
@interface RCTBundleManager : NSObject

- (nullable instancetype)initWithBundleConfig:(nullable RCTBundleConfiguration *)bundleConfig;

#ifndef RCT_REMOVE_LEGACY_ARCH
- (void)setBridge:(RCTBridge *)bridge;
- (void)setBridge:(nullable RCTBridge *)bridge;
#endif // RCT_REMOVE_LEGACY_ARCH
- (void)setBridgelessBundleURLGetter:(RCTBridgelessBundleURLGetter)getter
andSetter:(RCTBridgelessBundleURLSetter)setter
andDefaultGetter:(RCTBridgelessBundleURLGetter)defaultGetter;
- (void)setBridgelessBundleURLGetter:(nullable RCTBridgelessBundleURLGetter)getter
andSetter:(nullable RCTBridgelessBundleURLSetter)setter
andDefaultGetter:(nullable RCTBridgelessBundleURLGetter)defaultGetter;
- (void)resetBundleURL;
@property NSURL *bundleURL;
@property (nonatomic, nullable) NSURL *bundleURL;
@property (nonatomic, nonnull) RCTBundleConfiguration *bundleConfig;
@end
Loading
Loading