Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ typedef std::shared_ptr<facebook::react::JSEngineInstance> (^RCTHostJSEngineProv
*/
@interface RCTHost : NSObject

- (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER FB_OBJC_DIRECT;
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
hostDelegate:(id<RCTHostDelegate>)hostDelegate
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ + (void)initialize
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<RCTHostDelegate>)hostDelegate
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
hostDelegate:(id<RCTHostDelegate>)hostDelegate
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
{
if (self = [super init]) {
_hostDelegate = hostDelegate;
Expand All @@ -78,12 +79,8 @@ - (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
return strongSelf->_bundleURL;
};

auto bundleURLSetter = ^(NSURL *bundleURL) {
RCTHost *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
strongSelf->_bundleURL = bundleURL;
auto bundleURLSetter = ^(NSURL *bundleURL_) {
[weakSelf _setBundleURL:bundleURL];
};

auto defaultBundleURLGetter = ^NSURL *()
Expand All @@ -96,6 +93,7 @@ - (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
return [strongSelf->_hostDelegate getBundleURL];
};

[self _setBundleURL:bundleURL];
[_bundleManager setBridgelessBundleURLGetter:bundleURLGetter
andSetter:bundleURLSetter
andDefaultGetter:defaultBundleURLGetter];
Expand Down Expand Up @@ -144,8 +142,6 @@ - (void)start
@"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 _refreshBundleURL];
RCTReloadCommandSetBundleURL(_bundleURL);
_instance = [[RCTInstance alloc] initWithDelegate:self
jsEngineInstance:[self _provideJSEngine]
bundleManager:_bundleManager
Expand Down Expand Up @@ -204,8 +200,7 @@ - (void)didReceiveReloadCommand
{
[_instance invalidate];
_instance = nil;
[self _refreshBundleURL];
RCTReloadCommandSetBundleURL(_bundleURL);
[self _setBundleURL:[_hostDelegate getBundleURL]];

// Ensure all attached surfaces are restarted after reload
{
Expand Down Expand Up @@ -272,19 +267,6 @@ - (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path

#pragma mark - Private

- (void)_refreshBundleURL FB_OBJC_DIRECT
{
// Reset the _bundleURL ivar if the RCTHost delegate presents a new bundleURL
NSURL *newDelegateBundleURL = [_hostDelegate getBundleURL];
if (newDelegateBundleURL && ![newDelegateBundleURL isEqual:_oldDelegateBundleURL]) {
_oldDelegateBundleURL = newDelegateBundleURL;
_bundleURL = newDelegateBundleURL;
}

// Sanitize the bundle URL
_bundleURL = [RCTConvert NSURL:_bundleURL.absoluteString];
}

- (void)_attachSurface:(RCTFabricSurface *)surface FB_OBJC_DIRECT
{
_attachedSurfaces.push_back(surface);
Expand All @@ -311,4 +293,20 @@ - (void)_attachSurface:(RCTFabricSurface *)surface FB_OBJC_DIRECT
return jsEngine;
}

- (void)_setBundleURL:(NSURL *)bundleURL
{
// Reset the _bundleURL ivar if the RCTHost delegate presents a new bundleURL
NSURL *newDelegateBundleURL = bundleURL;
if (newDelegateBundleURL && ![newDelegateBundleURL isEqual:_oldDelegateBundleURL]) {
_oldDelegateBundleURL = newDelegateBundleURL;
_bundleURL = newDelegateBundleURL;
}

// Sanitize the bundle URL
_bundleURL = [RCTConvert NSURL:_bundleURL.absoluteString];

// Update the global bundle URLq
RCTReloadCommandSetBundleURL(_bundleURL);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
RCT_EXTERN_C_BEGIN

RCTHost *RCTHostCreateDefault(
NSURL *bundleURL,
id<RCTHostDelegate> hostDelegate,
id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate,
RCTHostJSEngineProvider jsEngineProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#import "RCTHostCreationHelpers.h"

RCTHost *RCTHostCreateDefault(
NSURL *bundleURL,
id<RCTHostDelegate> hostDelegate,
id<RCTTurboModuleManagerDelegate> 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];
}