diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTContextContainerHandling.h b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTContextContainerHandling.h new file mode 100644 index 00000000000..1fc73afe85d --- /dev/null +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTContextContainerHandling.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +#import + +@protocol RCTContextContainerHandling + +- (void)didCreateContextContainer:(std::shared_ptr)contextContainer; + +@end diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost+Internal.h b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost+Internal.h index 114e7923981..bedae4a3d98 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost+Internal.h +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost+Internal.h @@ -7,6 +7,7 @@ #import "RCTHost.h" +#import #import typedef NSURL * (^RCTHostBundleURLProvider)(void); @@ -22,5 +23,6 @@ typedef NSURL * (^RCTHostBundleURLProvider)(void); - (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path; - (void)setBundleURLProvider:(RCTHostBundleURLProvider)bundleURLProvider; - (void)setRuntimeDelegate:(id)runtimeDelegate; +- (void)setContextContainerHandler:(id)contextContainerHandler; @end 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 49bc3a24165..b5a3f18ca85 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 @@ -29,8 +29,6 @@ typedef std::shared_ptr (^RCTHostJSEngineProv @protocol RCTHostDelegate -- (std::shared_ptr)createContextContainer; - - (void)host:(RCTHost *)host didReceiveJSErrorStack:(NSArray *> *)stack message:(NSString *)message 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 fb84893af05..104b51e8ab8 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 @@ -25,9 +25,12 @@ using namespace facebook::react; @implementation RCTHost { RCTInstance *_instance; + __weak id _hostDelegate; __weak id _turboModuleManagerDelegate; __weak id _runtimeDelegate; + __weak id _contextContainerHandler; + NSURL *_oldDelegateBundleURL; NSURL *_bundleURL; RCTBundleManager *_bundleManager; @@ -228,11 +231,6 @@ using namespace facebook::react; #pragma mark - RCTInstanceDelegate -- (std::shared_ptr)createContextContainer -{ - return [_hostDelegate createContextContainer]; -} - - (void)instance:(RCTInstance *)instance didReceiveErrorMap:(facebook::react::MapBuffer)errorMap { NSString *message = [NSString stringWithCString:errorMap.getString(JSErrorHandlerKey::kErrorMessage).c_str() @@ -262,6 +260,13 @@ using namespace facebook::react; [_runtimeDelegate hostDidInitializeRuntime:runtime]; } +#pragma mark - RCTContextContainerHandling + +- (void)didCreateContextContainer:(std::shared_ptr)contextContainer +{ + [_contextContainerHandler didCreateContextContainer:contextContainer]; +} + #pragma mark - Internal - (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path @@ -279,6 +284,11 @@ using namespace facebook::react; _runtimeDelegate = runtimeDelegate; } +- (void)setContextContainerHandler:(id)contextContainerHandler +{ + _contextContainerHandler = contextContainerHandler; +} + #pragma mark - Private - (void)_attachSurface:(RCTFabricSurface *)surface 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 472ae6f69e3..80c10803316 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 @@ -12,7 +12,8 @@ #import #import #import -#import + +#import "RCTContextContainerHandling.h" NS_ASSUME_NONNULL_BEGIN @@ -35,9 +36,7 @@ RCT_EXTERN void RCTInstanceSetRuntimeDiagnosticFlags(NSString *_Nullable flags); FB_RUNTIME_PROTOCOL @protocol RCTTurboModuleManagerDelegate; -@protocol RCTInstanceDelegate - -- (std::shared_ptr)createContextContainer; +@protocol RCTInstanceDelegate - (void)instance:(RCTInstance *)instance didReceiveErrorMap:(facebook::react::MapBuffer)errorMap; - (void)instance:(RCTInstance *)instance didInitializeRuntime:(facebook::jsi::Runtime &)runtime; diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.mm b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.mm index 6067cccacba..b8c42e99d66 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.mm +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTInstance.mm @@ -235,10 +235,9 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags) RCTLogSetBridgelessModuleRegistry(_bridgeModuleDecorator.moduleRegistry); RCTLogSetBridgelessCallableJSModules(_bridgeModuleDecorator.callableJSModules); - auto contextContainer = [_delegate createContextContainer]; - if (!contextContainer) { - contextContainer = std::make_shared(); - } + auto contextContainer = std::make_shared(); + [_delegate didCreateContextContainer:contextContainer]; + contextContainer->insert( "RCTImageLoader", facebook::react::wrapManagedObject([_turboModuleManager moduleForName:"RCTImageLoader"])); contextContainer->insert(