Skip to content

Commit fb64bbf

Browse files
philIipfacebook-github-bot
authored andcommitted
pass in bundle url as a dependency of RCTHost (#37568)
Summary: Pull Request resolved: #37568 Changelog: [Internal] since bundleURL is constant throughout an app session, we should pass it in as a dependency from above. in the next diff, i'll get rid of `getBundleURL` from the react host's delegate. Reviewed By: sammy-SC Differential Revision: D45937855 fbshipit-source-id: 6306407f25c0f3eb8547e6aaf6e10ed9d2fddeaa
1 parent c24b5e9 commit fb64bbf

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ typedef std::shared_ptr<facebook::react::JSEngineInstance> (^RCTHostJSEngineProv
4848
*/
4949
@interface RCTHost : NSObject
5050

51-
- (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
52-
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
53-
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
54-
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER FB_OBJC_DIRECT;
51+
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
52+
hostDelegate:(id<RCTHostDelegate>)hostDelegate
53+
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
54+
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
55+
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER FB_OBJC_DIRECT;
5556

5657
/**
5758
* This function initializes an RCTInstance if one does not yet exist. This function is currently only called on the

packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ + (void)initialize
5252
Host initialization should not be resource intensive. A host may be created before any intention of using React Native
5353
has been expressed.
5454
*/
55-
- (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
56-
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
57-
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
58-
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
55+
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
56+
hostDelegate:(id<RCTHostDelegate>)hostDelegate
57+
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
58+
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
59+
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
5960
{
6061
if (self = [super init]) {
6162
_hostDelegate = hostDelegate;
@@ -78,7 +79,7 @@ - (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
7879
return strongSelf->_bundleURL;
7980
};
8081

81-
auto bundleURLSetter = ^(NSURL *bundleURL) {
82+
auto bundleURLSetter = ^(NSURL *bundleURL_) {
8283
[weakSelf _setBundleURL:bundleURL];
8384
};
8485

@@ -92,6 +93,7 @@ - (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
9293
return [strongSelf->_hostDelegate getBundleURL];
9394
};
9495

96+
[self _setBundleURL:bundleURL];
9597
[_bundleManager setBridgelessBundleURLGetter:bundleURLGetter
9698
andSetter:bundleURLSetter
9799
andDefaultGetter:defaultBundleURLGetter];
@@ -140,7 +142,6 @@ - (void)start
140142
@"RCTHost should not be creating a new instance if one already exists. This implies there is a bug with how/when this method is being called.");
141143
[_instance invalidate];
142144
}
143-
[self _setBundleURL:[_hostDelegate getBundleURL]];
144145
_instance = [[RCTInstance alloc] initWithDelegate:self
145146
jsEngineInstance:[self _provideJSEngine]
146147
bundleManager:_bundleManager

packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
2020
RCT_EXTERN_C_BEGIN
2121

2222
RCTHost *RCTHostCreateDefault(
23+
NSURL *bundleURL,
2324
id<RCTHostDelegate> hostDelegate,
2425
id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate,
2526
RCTHostJSEngineProvider jsEngineProvider);

packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
#import "RCTHostCreationHelpers.h"
99

1010
RCTHost *RCTHostCreateDefault(
11+
NSURL *bundleURL,
1112
id<RCTHostDelegate> hostDelegate,
1213
id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate,
1314
RCTHostJSEngineProvider jsEngineProvider)
1415
{
15-
return [[RCTHost alloc] initWithHostDelegate:hostDelegate
16-
turboModuleManagerDelegate:turboModuleManagerDelegate
17-
bindingsInstallFunc:nullptr
18-
jsEngineProvider:jsEngineProvider];
16+
return [[RCTHost alloc] initWithBundleURL:bundleURL
17+
hostDelegate:hostDelegate
18+
turboModuleManagerDelegate:turboModuleManagerDelegate
19+
bindingsInstallFunc:nullptr
20+
jsEngineProvider:jsEngineProvider];
1921
}

0 commit comments

Comments
 (0)