Skip to content

Commit 64e3268

Browse files
philIipfacebook-github-bot
authored andcommitted
introduce a private API for RCTHost to refresh its bundle url (facebook#37567)
Summary: Pull Request resolved: facebook#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: bb7882ab6f4bad124e2ee2296cbd2314d6b1c9d1
1 parent 3b14e81 commit 64e3268

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
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

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate,
1414
RCTHostJSEngineProvider jsEngineProvider)
1515
{
16-
return [[RCTHost alloc] initWithHostDelegate:hostDelegate
17-
turboModuleManagerDelegate:turboModuleManagerDelegate
18-
bindingsInstallFunc:nullptr
19-
jsEngineProvider:jsEngineProvider];
16+
return [[RCTHost alloc] initWithBundleURL:bundleURL
17+
hostDelegate:hostDelegate
18+
turboModuleManagerDelegate:turboModuleManagerDelegate
19+
bindingsInstallFunc:nullptr
20+
jsEngineProvider:jsEngineProvider];
2021
}

0 commit comments

Comments
 (0)