fold RCTInstanceDelegate into RCTHostDelegate (#37245)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37245

in general, userland has no reason to know about RCTInstance. this is the first step in starting to decouple consumers from the implementation details of bridgeless mode.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D45542678

fbshipit-source-id: e3b3c2ea9a913b2a2329f305aebbb6b0235d2a0e
This commit is contained in:
Phillip Pan
2023-05-05 13:14:48 -07:00
committed by Facebook GitHub Bot
parent 83d6e8d450
commit 9b69263a1c
3 changed files with 11 additions and 13 deletions
@@ -38,6 +38,7 @@ RCT_EXTERN NSString *const RCTHostDidReloadNotification;
- (std::shared_ptr<facebook::react::JSEngineInstance>)getJSEngine;
- (NSURL *)getBundleURL;
- (std::shared_ptr<facebook::react::ContextContainer>)createContextContainer;
@end
@@ -49,7 +50,6 @@ RCT_EXTERN NSString *const RCTHostDidReloadNotification;
@interface RCTHost : NSObject <ReactInstanceForwarding>
- (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
instanceDelegate:(id<RCTInstanceDelegate>)instanceDelegate
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
jsErrorHandlingFunc:(facebook::react::JsErrorHandler::JsErrorHandlingFunc)jsErrorHandlingFunc
@@ -22,12 +22,11 @@ using namespace facebook::react;
NSString *const RCTHostWillReloadNotification = @"RCTHostWillReloadNotification";
NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification";
@interface RCTHost () <RCTReloadListener>
@interface RCTHost () <RCTReloadListener, RCTInstanceDelegate>
@end
@implementation RCTHost {
RCTInstance *_instance;
__weak id<RCTInstanceDelegate> _instanceDelegate;
__weak id<RCTHostDelegate> _hostDelegate;
__weak id<RCTTurboModuleManagerDelegate> _turboModuleManagerDelegate;
NSURL *_oldDelegateBundleURL;
@@ -56,18 +55,12 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification";
has been expressed.
*/
- (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
instanceDelegate:(id<RCTInstanceDelegate>)instanceDelegate
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
jsErrorHandlingFunc:(JsErrorHandler::JsErrorHandlingFunc)jsErrorHandlingFunc;
{
RCTAssert(
hostDelegate && instanceDelegate && turboModuleManagerDelegate,
@"RCTHost cannot be instantiated with any nil init params.");
if (self = [super init]) {
_hostDelegate = hostDelegate;
_instanceDelegate = instanceDelegate;
_turboModuleManagerDelegate = turboModuleManagerDelegate;
_surfaceStartBuffer = [NSMutableArray new];
_bundleManager = [RCTBundleManager new];
@@ -155,7 +148,7 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification";
}
[self _refreshBundleURL];
RCTReloadCommandSetBundleURL(_bundleURL);
_instance = [[RCTInstance alloc] initWithDelegate:_instanceDelegate
_instance = [[RCTInstance alloc] initWithDelegate:self
jsEngineInstance:[_hostDelegate getJSEngine]
bundleManager:_bundleManager
turboModuleManagerDelegate:_turboModuleManagerDelegate
@@ -224,7 +217,7 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification";
_surfaceStartBuffer = [NSMutableArray arrayWithArray:[self _getAttachedSurfaces]];
}
_instance = [[RCTInstance alloc] initWithDelegate:_instanceDelegate
_instance = [[RCTInstance alloc] initWithDelegate:self
jsEngineInstance:[_hostDelegate getJSEngine]
bundleManager:_bundleManager
turboModuleManagerDelegate:_turboModuleManagerDelegate
@@ -264,6 +257,13 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification";
[_instance invalidate];
}
#pragma mark - RCTInstanceDelegate
- (std::shared_ptr<facebook::react::ContextContainer>)createContextContainer
{
return [_hostDelegate createContextContainer];
}
#pragma mark - Private
- (void)_refreshBundleURL FB_OBJC_DIRECT
{
@@ -36,8 +36,6 @@ FB_RUNTIME_PROTOCOL
// TODO (T74233481) - Delete this. Communication between Product Code <> RCTInstance should go through RCTHost.
@protocol RCTInstanceDelegate <NSObject>
@required
- (std::shared_ptr<facebook::react::ContextContainer>)createContextContainer;
@end