From 9b69263a1c79902edad32a0a2e870459d9fef4e4 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Fri, 5 May 2023 13:14:48 -0700 Subject: [PATCH] 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 --- .../bridgeless/platform/ios/Core/RCTHost.h | 2 +- .../bridgeless/platform/ios/Core/RCTHost.mm | 20 +++++++++---------- .../platform/ios/Core/RCTInstance.h | 2 -- 3 files changed, 11 insertions(+), 13 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 fb06e707025..77c043b332a 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 @@ -38,6 +38,7 @@ RCT_EXTERN NSString *const RCTHostDidReloadNotification; - (std::shared_ptr)getJSEngine; - (NSURL *)getBundleURL; +- (std::shared_ptr)createContextContainer; @end @@ -49,7 +50,6 @@ RCT_EXTERN NSString *const RCTHostDidReloadNotification; @interface RCTHost : NSObject - (instancetype)initWithHostDelegate:(id)hostDelegate - instanceDelegate:(id)instanceDelegate turboModuleManagerDelegate:(id)turboModuleManagerDelegate bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc jsErrorHandlingFunc:(facebook::react::JsErrorHandler::JsErrorHandlingFunc)jsErrorHandlingFunc 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 14b0e9b6692..c751606f9fb 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 @@ -22,12 +22,11 @@ using namespace facebook::react; NSString *const RCTHostWillReloadNotification = @"RCTHostWillReloadNotification"; NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification"; -@interface RCTHost () +@interface RCTHost () @end @implementation RCTHost { RCTInstance *_instance; - __weak id _instanceDelegate; __weak id _hostDelegate; __weak id _turboModuleManagerDelegate; NSURL *_oldDelegateBundleURL; @@ -56,18 +55,12 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification"; has been expressed. */ - (instancetype)initWithHostDelegate:(id)hostDelegate - instanceDelegate:(id)instanceDelegate turboModuleManagerDelegate:(id)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)createContextContainer +{ + return [_hostDelegate createContextContainer]; +} + #pragma mark - Private - (void)_refreshBundleURL FB_OBJC_DIRECT { diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.h b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.h index 8411fe05738..62b4eb1a476 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.h +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.h @@ -36,8 +36,6 @@ FB_RUNTIME_PROTOCOL // TODO (T74233481) - Delete this. Communication between Product Code <> RCTInstance should go through RCTHost. @protocol RCTInstanceDelegate -@required - - (std::shared_ptr)createContextContainer; @end