From fb64bbf6715f3ca992e2d4b66a7b45bed2248772 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Thu, 25 May 2023 00:37:37 -0700 Subject: [PATCH] pass in bundle url as a dependency of RCTHost (#37568) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- .../react/bridgeless/platform/ios/Core/RCTHost.h | 9 +++++---- .../react/bridgeless/platform/ios/Core/RCTHost.mm | 13 +++++++------ .../platform/ios/Core/RCTHostCreationHelpers.h | 1 + .../platform/ios/Core/RCTHostCreationHelpers.mm | 10 ++++++---- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h index 96fd88a7afd..50e2e0bf166 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h @@ -48,10 +48,11 @@ typedef std::shared_ptr (^RCTHostJSEngineProv */ @interface RCTHost : NSObject -- (instancetype)initWithHostDelegate:(id)hostDelegate - turboModuleManagerDelegate:(id)turboModuleManagerDelegate - bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc - jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER FB_OBJC_DIRECT; +- (instancetype)initWithBundleURL:(NSURL *)bundleURL + hostDelegate:(id)hostDelegate + turboModuleManagerDelegate:(id)turboModuleManagerDelegate + bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc + jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER FB_OBJC_DIRECT; /** * This function initializes an RCTInstance if one does not yet exist. This function is currently only called on the diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm index 97e9c1be4f9..7ab1b72146c 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm @@ -52,10 +52,11 @@ using namespace facebook::react; Host initialization should not be resource intensive. A host may be created before any intention of using React Native has been expressed. */ -- (instancetype)initWithHostDelegate:(id)hostDelegate - turboModuleManagerDelegate:(id)turboModuleManagerDelegate - bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc - jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider +- (instancetype)initWithBundleURL:(NSURL *)bundleURL + hostDelegate:(id)hostDelegate + turboModuleManagerDelegate:(id)turboModuleManagerDelegate + bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc + jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider { if (self = [super init]) { _hostDelegate = hostDelegate; @@ -78,7 +79,7 @@ using namespace facebook::react; return strongSelf->_bundleURL; }; - auto bundleURLSetter = ^(NSURL *bundleURL) { + auto bundleURLSetter = ^(NSURL *bundleURL_) { [weakSelf _setBundleURL:bundleURL]; }; @@ -92,6 +93,7 @@ using namespace facebook::react; return [strongSelf->_hostDelegate getBundleURL]; }; + [self _setBundleURL:bundleURL]; [_bundleManager setBridgelessBundleURLGetter:bundleURLGetter andSetter:bundleURLSetter andDefaultGetter:defaultBundleURLGetter]; @@ -140,7 +142,6 @@ using namespace facebook::react; @"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."); [_instance invalidate]; } - [self _setBundleURL:[_hostDelegate getBundleURL]]; _instance = [[RCTInstance alloc] initWithDelegate:self jsEngineInstance:[self _provideJSEngine] bundleManager:_bundleManager diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.h b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.h index 5006e14ef0c..da866c481a9 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.h +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.h @@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN RCT_EXTERN_C_BEGIN RCTHost *RCTHostCreateDefault( + NSURL *bundleURL, id hostDelegate, id turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider); diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.mm b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.mm index 31d1af728d2..3b928e3332e 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.mm +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHostCreationHelpers.mm @@ -8,12 +8,14 @@ #import "RCTHostCreationHelpers.h" RCTHost *RCTHostCreateDefault( + NSURL *bundleURL, id hostDelegate, id turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider) { - return [[RCTHost alloc] initWithHostDelegate:hostDelegate - turboModuleManagerDelegate:turboModuleManagerDelegate - bindingsInstallFunc:nullptr - jsEngineProvider:jsEngineProvider]; + return [[RCTHost alloc] initWithBundleURL:bundleURL + hostDelegate:hostDelegate + turboModuleManagerDelegate:turboModuleManagerDelegate + bindingsInstallFunc:nullptr + jsEngineProvider:jsEngineProvider]; }