Skip to content

Commit f448adf

Browse files
feat: jsBundleName -> jsBundleSource + accept URL
1 parent 53b0587 commit f448adf

File tree

9 files changed

+36
-33
lines changed

9 files changed

+36
-33
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ function HostApp() {
7777
return (
7878
<View>
7979
<Button onPress={sendMessageToSandbox} title="Send to Sandbox" />
80-
<SandboxReactNativeView
81-
ref={sandboxRef}
82-
jsBundleName={"sandbox"} // The name of the JS bundle for the sandbox
83-
moduleName={"SandboxApp"} // The registered module name in the sandbox
80+
<SandboxReactNativeView ref={sandboxRef}
81+
moduleName={"ModuleName"} // The name of your JS module
82+
jsBundleSource={"sandbox"} // The JS bundle: file name or URL
8483
onMessage={handleMessage}
8584
onError={handleError}
8685
/>

docs/presentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function App() {
7373
<Button onPress={onPress} title="Send to sandbox" />
7474
...
7575
<SandboxReactNativeView ref={sandbox1Ref}
76-
jsBundleName={"sandbox"}
76+
jsBundleSource={"sandbox"}
7777
moduleName={"SandboxApp"}
7878
onMessage={onMessage}
7979
onError={onError}
@@ -178,7 +178,7 @@ function App() {
178178
<Button onPress={onPress} title="Send to sandbox" />
179179
...
180180
<SandboxReactNativeView ref={sandbox1Ref}
181-
jsBundleName={"sandbox"}
181+
jsBundleSource={"sandbox"}
182182
moduleName={"SandboxApp"}
183183
onMessage={onMessage}
184184
onError={onError}

packages/examples/side-by-side/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function SandboxDemoView({initialProperties}: {initialProperties: any}) {
2828
{isVisible ?
2929
<SandboxReactNativeView
3030
ref={sandboxRef}
31-
jsBundleName={'sandbox'}
31+
jsBundleSource={'sandbox'}
3232
moduleName={'SandboxApp'}
3333
style={styles.sandboxView}
3434
initialProperties={initialProperties}

packages/react-native-multinstance/ios/SandboxReactNativeDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
1818
@property (nonatomic, copy, nullable) RCTDirectEventBlock onErrorHost;
1919
@property (nonatomic, copy) NSArray<NSString *> *allowedTurboModules;
2020

21-
- (instancetype)initWithJSBundleName:(NSString *)jsBundleName;
21+
- (instancetype)initWithJSBundleSource:(NSString *)jsBundleSource;
2222
- (void)postMessage:(NSDictionary *)message;
2323

2424
@end

packages/react-native-multinstance/ios/SandboxReactNativeDelegate.mm

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ @interface SandboxReactNativeDelegate () {
4444
std::set<std::string> _allowedModules;
4545
}
4646

47-
@property (nonatomic, strong) NSString *jsBundleName;
47+
@property (nonatomic, strong) NSString *jsBundleSource;
4848

4949
@end
5050

@@ -57,9 +57,9 @@ - (void)setAllowedTurboModules:(NSArray<NSString *> *)allowedTurboModules {
5757
}
5858
}
5959

60-
- (instancetype)initWithJSBundleName:(NSString *)jsBundleName {
60+
- (instancetype)initWithJSBundleSource:(NSString *)jsBundleSource {
6161
if (self = [super init]) {
62-
_jsBundleName = jsBundleName;
62+
_jsBundleSource = jsBundleSource;
6363
_onMessageHost = nil;
6464
_onErrorHost = nil;
6565
self.dependencyProvider = [[RCTAppDependencyProvider alloc] init];
@@ -72,11 +72,18 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
7272
}
7373

7474
- (NSURL *)bundleURL {
75-
#if DEBUG
76-
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:self.jsBundleName];
77-
#else
78-
return [[NSBundle mainBundle] URLForResource:self.jsBundleName withExtension:@"jsbundle"];
79-
#endif
75+
NSURL *url = [NSURL URLWithString:self.jsBundleSource];
76+
if (url && url.scheme) {
77+
return url;
78+
}
79+
80+
if ([self.jsBundleSource hasSuffix:@".jsbundle"]) {
81+
return [[NSBundle mainBundle] URLForResource:self.jsBundleSource withExtension:nil];
82+
}
83+
84+
NSString *bundleName = [self.jsBundleSource hasSuffix:@".bundle"] ?
85+
[self.jsBundleSource stringByDeletingPathExtension] : self.jsBundleSource;
86+
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleName];
8087
}
8188

8289
- (void)postMessage:(NSDictionary *)message {
@@ -202,7 +209,6 @@ - (void)hostDidStart:(RCTHost *)host {
202209
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
203210
jsInvoker:
204211
(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker {
205-
NSLog(@"SandboxReactNativeDelegate.getTurboModule:jsInvoker %s", name.c_str());
206212
return _allowedModules.contains(name) ? [super getTurboModule:name jsInvoker:jsInvoker] : nullptr;
207213
}
208214

packages/react-native-multinstance/ios/SandboxReactNativeView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
1212
@interface SandboxReactNativeView : RCTView
1313

1414
@property (nonatomic, copy) NSString *moduleName;
15-
@property (nonatomic, copy) NSString *jsBundleName;
15+
@property (nonatomic, copy) NSString *jsBundleSource;
1616
@property (nonatomic, copy) NSDictionary *initialProperties;
1717
@property (nonatomic, copy) NSDictionary *launchOptions;
1818
@property (nonatomic, copy) NSArray<NSString *> *allowedTurboModules;

packages/react-native-multinstance/ios/SandboxReactNativeView.mm

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ @implementation SandboxReactNativeView
2525

2626
- (instancetype)initWithFrame:(CGRect)frame {
2727
if (self = [super initWithFrame:frame]) {
28-
_moduleName = @"sandbox";
29-
_jsBundleName = @"index";
28+
_moduleName = @"App";
29+
_jsBundleSource = @"sandbox";
30+
_allowedTurboModules = @[@"NativeMicrotasksCxx"];
3031
_initialProperties = @{};
3132
_launchOptions = @{};
32-
_onError = nil;
3333
_onMessage = nil;
34+
_onError = nil;
3435
}
3536
return self;
3637
}
@@ -42,9 +43,9 @@ - (void)setModuleName:(NSString *)moduleName {
4243
}
4344
}
4445

45-
- (void)setJsBundleName:(NSString *)jsBundleName {
46-
if (![_jsBundleName isEqualToString:jsBundleName]) {
47-
_jsBundleName = [jsBundleName copy];
46+
- (void)setJsBundleSource:(NSString *)jsBundleSource {
47+
if (![_jsBundleSource isEqualToString:jsBundleSource]) {
48+
_jsBundleSource = [jsBundleSource copy];
4849
[self scheduleReactViewLoad];
4950
}
5051
}
@@ -77,7 +78,7 @@ - (void)setOnError:(RCTDirectEventBlock)onError {
7778
}
7879
}
7980

80-
- (void)setallowedTurboModules:(NSArray<NSString *> *)allowedTurboModules {
81+
- (void)setAllowedTurboModules:(NSArray<NSString *> *)allowedTurboModules {
8182
if (![allowedTurboModules isEqual:_allowedTurboModules]) {
8283
_allowedTurboModules = [allowedTurboModules copy];
8384
[self scheduleReactViewLoad];
@@ -99,19 +100,16 @@ - (void)scheduleReactViewLoad {
99100
}
100101

101102
- (void)loadReactNativeView {
102-
if (_moduleName.length == 0 || _jsBundleName.length == 0 || _allowedTurboModules == nil) {
103+
if (_moduleName.length == 0 || _jsBundleSource.length == 0 || _allowedTurboModules == nil) {
103104
return;
104105
}
105106

106-
// TODO is it possible to get hostRtcInstance?
107-
108-
SandboxReactNativeDelegate *delegate = [[SandboxReactNativeDelegate alloc] initWithJSBundleName:_jsBundleName];
107+
SandboxReactNativeDelegate *delegate = [[SandboxReactNativeDelegate alloc] initWithJSBundleSource:_jsBundleSource];
109108
delegate.onMessageHost = _onMessage;
110109
delegate.onErrorHost = _onError;
111110
delegate.allowedTurboModules = _allowedTurboModules;
112111

113112
RCTReactNativeFactory *factory = [[RCTReactNativeFactory alloc] initWithDelegate:delegate];
114-
factory.delegate = delegate;
115113

116114
UIView *rnView = [factory.rootViewFactory viewWithModuleName:_moduleName
117115
initialProperties:_initialProperties

packages/react-native-multinstance/ios/SandboxReactNativeViewManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
@interface RCT_EXTERN_MODULE(SandboxReactNativeViewManager, RCTViewManager)
1414

15-
RCT_EXPORT_VIEW_PROPERTY(jsBundleName, NSString)
1615
RCT_EXPORT_VIEW_PROPERTY(moduleName, NSString)
16+
RCT_EXPORT_VIEW_PROPERTY(jsBundleSource, NSString)
1717
RCT_EXPORT_VIEW_PROPERTY(initialProperties, NSDictionary)
1818
RCT_EXPORT_VIEW_PROPERTY(launchOptions, NSDictionary)
1919
RCT_EXPORT_VIEW_PROPERTY(allowedTurboModules, NSArray<NSString *>)

packages/react-native-multinstance/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface IsFatalError extends Error {
1616

1717
export interface NativeSandboxReactNativeViewProps extends ViewProps {
1818
moduleName: string;
19-
jsBundleName?: string;
19+
jsBundleSource?: string;
2020
initialProperties?: GenericProps;
2121
launchOptions?: GenericProps;
2222
allowedTurboModules?: string[];
@@ -26,7 +26,7 @@ export interface NativeSandboxReactNativeViewProps extends ViewProps {
2626

2727
export interface SandboxReactNativeViewProps extends ViewProps {
2828
moduleName: string;
29-
jsBundleName?: string;
29+
jsBundleSource?: string;
3030
initialProperties?: GenericProps;
3131
launchOptions?: GenericProps;
3232
allowedTurboModules?: string[];

0 commit comments

Comments
 (0)