introduce a private API for RCTHost to refresh its bundle url (#37567)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Phillip Pan 2023-05-25 00:37:37 -07:00 коммит произвёл Facebook GitHub Bot
Родитель fb64bbf671
Коммит 992c45c0e1
3 изменённых файлов: 14 добавлений и 4 удалений

Просмотреть файл

@ -7,8 +7,11 @@
#import "RCTHost.h"
typedef NSURL * (^RCTHostBundleURLProvider)(void);
@interface RCTHost (Internal)
- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path;
- (void)setBundleURLProvider:(RCTHostBundleURLProvider)bundleURLProvider;
@end

Просмотреть файл

@ -29,7 +29,6 @@ typedef std::shared_ptr<facebook::react::JSEngineInstance> (^RCTHostJSEngineProv
@protocol RCTHostDelegate <NSObject>
- (NSURL *)getBundleURL;
- (std::shared_ptr<facebook::react::ContextContainer>)createContextContainer;
- (void)host:(RCTHost *)host

Просмотреть файл

@ -30,6 +30,7 @@ using namespace facebook::react;
NSURL *_oldDelegateBundleURL;
NSURL *_bundleURL;
RCTBundleManager *_bundleManager;
RCTHostBundleURLProvider _bundleURLProvider;
facebook::react::ReactInstance::BindingsInstallFunc _bindingsInstallFunc;
RCTHostJSEngineProvider _jsEngineProvider;
@ -86,11 +87,11 @@ using namespace facebook::react;
auto defaultBundleURLGetter = ^NSURL *()
{
RCTHost *strongSelf = weakSelf;
if (!strongSelf) {
if (!strongSelf || !strongSelf->_bundleURLProvider) {
return nil;
}
return [strongSelf->_hostDelegate getBundleURL];
return strongSelf->_bundleURLProvider();
};
[self _setBundleURL:bundleURL];
@ -200,7 +201,9 @@ using namespace facebook::react;
{
[_instance invalidate];
_instance = nil;
[self _setBundleURL:[_hostDelegate getBundleURL]];
if (_bundleURLProvider) {
[self _setBundleURL:_bundleURLProvider()];
}
// Ensure all attached surfaces are restarted after reload
{
@ -265,6 +268,11 @@ using namespace facebook::react;
[_instance registerSegmentWithId:segmentId path:path];
}
- (void)setBundleURLProvider:(RCTHostBundleURLProvider)bundleURLProvider
{
_bundleURLProvider = [bundleURLProvider copy];
}
#pragma mark - Private
- (void)_attachSurface:(RCTFabricSurface *)surface FB_OBJC_DIRECT