Skip to content

Commit 992c45c

Browse files
philIipfacebook-github-bot
authored andcommitted
introduce a private API for RCTHost to refresh its bundle url (#37567)
Summary: Pull Request resolved: #37567 Changelog: [Internal] in the situation where we want to refresh the bundle url due to developer mode, we add a private API that allows the host to refresh its bundle URL if needed. this private API will be called on cmd + R, which is the only case that supports the changing bundle URL in the middle of the app session. Reviewed By: cipolleschi Differential Revision: D45937856 fbshipit-source-id: 718047abcbce983c4f820eb550d6fce05d03bfee
1 parent fb64bbf commit 992c45c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
#import "RCTHost.h"
99

10+
typedef NSURL * (^RCTHostBundleURLProvider)(void);
11+
1012
@interface RCTHost (Internal)
1113

1214
- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path;
15+
- (void)setBundleURLProvider:(RCTHostBundleURLProvider)bundleURLProvider;
1316

1417
@end

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ typedef std::shared_ptr<facebook::react::JSEngineInstance> (^RCTHostJSEngineProv
2929

3030
@protocol RCTHostDelegate <NSObject>
3131

32-
- (NSURL *)getBundleURL;
3332
- (std::shared_ptr<facebook::react::ContextContainer>)createContextContainer;
3433

3534
- (void)host:(RCTHost *)host

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ @implementation RCTHost {
3030
NSURL *_oldDelegateBundleURL;
3131
NSURL *_bundleURL;
3232
RCTBundleManager *_bundleManager;
33+
RCTHostBundleURLProvider _bundleURLProvider;
3334
facebook::react::ReactInstance::BindingsInstallFunc _bindingsInstallFunc;
3435
RCTHostJSEngineProvider _jsEngineProvider;
3536

@@ -86,11 +87,11 @@ - (instancetype)initWithBundleURL:(NSURL *)bundleURL
8687
auto defaultBundleURLGetter = ^NSURL *()
8788
{
8889
RCTHost *strongSelf = weakSelf;
89-
if (!strongSelf) {
90+
if (!strongSelf || !strongSelf->_bundleURLProvider) {
9091
return nil;
9192
}
9293

93-
return [strongSelf->_hostDelegate getBundleURL];
94+
return strongSelf->_bundleURLProvider();
9495
};
9596

9697
[self _setBundleURL:bundleURL];
@@ -200,7 +201,9 @@ - (void)didReceiveReloadCommand
200201
{
201202
[_instance invalidate];
202203
_instance = nil;
203-
[self _setBundleURL:[_hostDelegate getBundleURL]];
204+
if (_bundleURLProvider) {
205+
[self _setBundleURL:_bundleURLProvider()];
206+
}
204207

205208
// Ensure all attached surfaces are restarted after reload
206209
{
@@ -265,6 +268,11 @@ - (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
265268
[_instance registerSegmentWithId:segmentId path:path];
266269
}
267270

271+
- (void)setBundleURLProvider:(RCTHostBundleURLProvider)bundleURLProvider
272+
{
273+
_bundleURLProvider = [bundleURLProvider copy];
274+
}
275+
268276
#pragma mark - Private
269277

270278
- (void)_attachSurface:(RCTFabricSurface *)surface FB_OBJC_DIRECT

0 commit comments

Comments
 (0)