diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm index e8ebdefba1dc7e..4edd8fef3e4218 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm @@ -123,7 +123,7 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName RCTEnableTurboModuleInterop(YES); RCTEnableTurboModuleInteropBridgeProxy(YES); - [self createReactHostIfNeeded]; + [self createReactHostIfNeeded:launchOptions]; RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:moduleName initialProperties:initProps]; @@ -206,7 +206,7 @@ - (void)createBridgeAdapterIfNeeded #pragma mark - New Arch Utilities -- (void)createReactHostIfNeeded +- (void)createReactHostIfNeeded:(NSDictionary *)launchOptions { if (_reactHost) { return; @@ -218,7 +218,8 @@ - (void)createReactHostIfNeeded turboModuleManagerDelegate:_turboModuleManagerDelegate jsEngineProvider:^std::shared_ptr() { return [weakSelf createJSRuntimeFactory]; - }]; + } + launchOptions:launchOptions]; [_reactHost setBundleURLProvider:^NSURL *() { return [weakSelf bundleURL]; }]; diff --git a/packages/react-native/React/Base/RCTBridgeProxy.h b/packages/react-native/React/Base/RCTBridgeProxy.h index 3a6de36473ee5b..71bb9cf0831640 100644 --- a/packages/react-native/React/Base/RCTBridgeProxy.h +++ b/packages/react-native/React/Base/RCTBridgeProxy.h @@ -9,6 +9,8 @@ #import "RCTBridgeModule.h" +NS_ASSUME_NONNULL_BEGIN + @class RCTBundleManager; @class RCTCallableJSModules; @class RCTModuleRegistry; @@ -22,7 +24,8 @@ callableJSModules:(RCTCallableJSModules *)callableJSModules dispatchToJSThread:(void (^)(dispatch_block_t))dispatchToJSThread registerSegmentWithId:(void (^)(NSNumber *, NSString *))registerSegmentWithId - runtime:(void *)runtime NS_DESIGNATED_INITIALIZER; + runtime:(void *)runtime + launchOptions:(nullable NSDictionary *)launchOptions NS_DESIGNATED_INITIALIZER; - (NSMethodSignature *)methodSignatureForSelector:(SEL)sel; - (void)forwardInvocation:(NSInvocation *)invocation; @@ -37,3 +40,5 @@ - (id)moduleForName:(NSString *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyLoad; @end + +NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/Base/RCTBridgeProxy.mm b/packages/react-native/React/Base/RCTBridgeProxy.mm index 27637daf654c1c..5b3e0656929ee3 100644 --- a/packages/react-native/React/Base/RCTBridgeProxy.mm +++ b/packages/react-native/React/Base/RCTBridgeProxy.mm @@ -35,6 +35,7 @@ @implementation RCTBridgeProxy { RCTModuleRegistry *_moduleRegistry; RCTBundleManager *_bundleManager; RCTCallableJSModules *_callableJSModules; + NSDictionary *_launchOptions; void (^_dispatchToJSThread)(dispatch_block_t); void (^_registerSegmentWithId)(NSNumber *, NSString *); void *_runtime; @@ -47,6 +48,7 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry dispatchToJSThread:(void (^)(dispatch_block_t))dispatchToJSThread registerSegmentWithId:(void (^)(NSNumber *, NSString *))registerSegmentWithId runtime:(void *)runtime + launchOptions:(nullable NSDictionary *)launchOptions { self = [super self]; if (self) { @@ -57,6 +59,7 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry _dispatchToJSThread = dispatchToJSThread; _registerSegmentWithId = registerSegmentWithId; _runtime = runtime; + _launchOptions = [launchOptions copy]; } return self; } @@ -191,8 +194,7 @@ - (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path - (NSDictionary *)launchOptions { - [self logError:@"This method is not supported. Returning nil." cmd:_cmd]; - return nil; + return _launchOptions; } - (BOOL)loading diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm index d93d606fce4117..9a34ab1ab7d357 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm @@ -674,7 +674,7 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass */ if (_bridge) { [(id)module setValue:_bridge forKey:@"bridge"]; - } else if (_bridgeProxy && [self _isLegacyModuleClass:[module class]]) { + } else if (_bridgeProxy) { [(id)module setValue:_bridgeProxy forKey:@"bridge"]; } } @catch (NSException *exception) { diff --git a/packages/react-native/ReactCommon/react/runtime/iostests/RCTHostTests.mm b/packages/react-native/ReactCommon/react/runtime/iostests/RCTHostTests.mm index de2e016b95afc4..cadf6d61cdca8e 100644 --- a/packages/react-native/ReactCommon/react/runtime/iostests/RCTHostTests.mm +++ b/packages/react-native/ReactCommon/react/runtime/iostests/RCTHostTests.mm @@ -58,7 +58,8 @@ - (void)setUp turboModuleManagerDelegate:OCMProtocolMock(@protocol(RCTTurboModuleManagerDelegate)) jsEngineProvider:^std::shared_ptr() { return std::make_shared(); - }]; + } + launchOptions:nil]; } - (void)tearDown diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h index ea4492980f976f..8f3c0460f38ed8 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h @@ -48,7 +48,8 @@ typedef std::shared_ptr (^RCTHostJSEngineProv - (instancetype)initWithBundleURL:(NSURL *)bundleURL hostDelegate:(id)hostDelegate turboModuleManagerDelegate:(id)turboModuleManagerDelegate - jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER; + jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider + launchOptions:(nullable NSDictionary *)launchOptions NS_DESIGNATED_INITIALIZER; @property (nonatomic, weak, nullable) id runtimeDelegate; diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm index ff0bb9703d386c..791bdf5f838bbe 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm @@ -58,6 +58,8 @@ @implementation RCTHost { RCTHostBundleURLProvider _bundleURLProvider; RCTHostJSEngineProvider _jsEngineProvider; + NSDictionary *_launchOptions; + // All the surfaces that need to be started after main bundle execution NSMutableArray *_surfaceStartBuffer; std::mutex _surfaceStartBufferMutex; @@ -85,6 +87,7 @@ - (instancetype)initWithBundleURL:(NSURL *)bundleURL hostDelegate:(id)hostDelegate turboModuleManagerDelegate:(id)turboModuleManagerDelegate jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider + launchOptions:(nullable NSDictionary *)launchOptions { if (self = [super init]) { _hostDelegate = hostDelegate; @@ -93,6 +96,7 @@ - (instancetype)initWithBundleURL:(NSURL *)bundleURL _bundleManager = [RCTBundleManager new]; _moduleRegistry = [RCTModuleRegistry new]; _jsEngineProvider = [jsEngineProvider copy]; + _launchOptions = [launchOptions copy]; __weak RCTHost *weakSelf = self; @@ -204,7 +208,8 @@ - (void)start turboModuleManagerDelegate:_turboModuleManagerDelegate onInitialBundleLoad:_onInitialBundleLoad moduleRegistry:_moduleRegistry - parentInspectorTarget:_inspectorTarget.get()]; + parentInspectorTarget:_inspectorTarget.get() + launchOptions:_launchOptions]; [_hostDelegate hostDidStart:self]; } @@ -284,7 +289,8 @@ - (void)didReceiveReloadCommand turboModuleManagerDelegate:_turboModuleManagerDelegate onInitialBundleLoad:_onInitialBundleLoad moduleRegistry:_moduleRegistry - parentInspectorTarget:_inspectorTarget.get()]; + parentInspectorTarget:_inspectorTarget.get() + launchOptions:_launchOptions]; [_hostDelegate hostDidStart:self]; for (RCTFabricSurface *surface in [self _getAttachedSurfaces]) { diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h index a24cc08a496e0e..e66e2b2bb37b70 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h @@ -62,7 +62,8 @@ typedef void (^_Null_unspecified RCTInstanceInitialBundleLoadCompletionBlock)(); turboModuleManagerDelegate:(id)turboModuleManagerDelegate onInitialBundleLoad:(RCTInstanceInitialBundleLoadCompletionBlock)onInitialBundleLoad moduleRegistry:(RCTModuleRegistry *)moduleRegistry - parentInspectorTarget:(facebook::react::jsinspector_modern::PageTarget *)parentInspectorTarget; + parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget + launchOptions:(nullable NSDictionary *)launchOptions; - (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args; diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm index 6edf015e41be7a..dba72329584c57 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm @@ -83,6 +83,7 @@ @implementation RCTInstance { std::mutex _invalidationMutex; std::atomic _valid; RCTJSThreadManager *_jsThreadManager; + NSDictionary *_launchOptions; // APIs supporting interop with native modules and view managers RCTBridgeModuleDecorator *_bridgeModuleDecorator; @@ -98,7 +99,8 @@ - (instancetype)initWithDelegate:(id)delegate turboModuleManagerDelegate:(id)tmmDelegate onInitialBundleLoad:(RCTInstanceInitialBundleLoadCompletionBlock)onInitialBundleLoad moduleRegistry:(RCTModuleRegistry *)moduleRegistry - parentInspectorTarget:(jsinspector_modern::PageTarget *)parentInspectorTarget + parentInspectorTarget:(jsinspector_modern::HostTarget *)parentInspectorTarget + launchOptions:(nullable NSDictionary *)launchOptions { if (self = [super init]) { _performanceLogger = [RCTPerformanceLogger new]; @@ -124,6 +126,7 @@ - (instancetype)initWithDelegate:(id)delegate [weakSelf callFunctionOnJSModule:moduleName method:methodName args:args]; }]; } + _launchOptions = launchOptions; NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; @@ -270,7 +273,8 @@ - (void)_start [strongSelf registerSegmentWithId:segmentId path:path]; } } - runtime:_reactInstance->getJavaScriptContext()]; + runtime:_reactInstance->getJavaScriptContext() + launchOptions:_launchOptions]; bridgeProxy.jsCallInvoker = jsCallInvoker; [RCTBridge setCurrentBridge:(RCTBridge *)bridgeProxy]; diff --git a/packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.h b/packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.h index e11e88c560a72a..654cf17657c9be 100644 --- a/packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.h +++ b/packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.h @@ -11,7 +11,7 @@ @property int initCount; @property int invalidateCount; - +@property NSDictionary *launchOptions; @property NSString *jsModuleName; @property NSString *method; @property NSArray *args; diff --git a/packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.mm b/packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.mm index a6be15a7f03011..2575f1453a2953 100644 --- a/packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.mm +++ b/packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.mm @@ -24,7 +24,7 @@ - (instancetype)init [ShimRCTInstance class], @selector(initWithDelegate: jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:onInitialBundleLoad:moduleRegistry - :parentInspectorTarget:)); + :parentInspectorTarget:launchOptions:)); RCTSwizzleInstanceSelector([RCTInstance class], [ShimRCTInstance class], @selector(invalidate)); RCTSwizzleInstanceSelector( [RCTInstance class], [ShimRCTInstance class], @selector(callFunctionOnJSModule:method:args:)); @@ -40,7 +40,7 @@ - (void)reset [ShimRCTInstance class], @selector(initWithDelegate: jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:onInitialBundleLoad:moduleRegistry - :parentInspectorTarget:)); + :parentInspectorTarget:launchOptions:)); RCTSwizzleInstanceSelector([RCTInstance class], [ShimRCTInstance class], @selector(invalidate)); RCTSwizzleInstanceSelector( [RCTInstance class], [ShimRCTInstance class], @selector(callFunctionOnJSModule:method:args:)); @@ -54,7 +54,8 @@ - (instancetype)initWithDelegate:(id)delegate turboModuleManagerDelegate:(id)tmmDelegate onInitialBundleLoad:(RCTInstanceInitialBundleLoadCompletionBlock)onInitialBundleLoad moduleRegistry:(RCTModuleRegistry *)moduleRegistry - parentInspectorTarget:(facebook::react::jsinspector_modern::PageTarget *)parentInspectorTarget + parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget + launchOptions:(NSDictionary *)launchOptions { weakShim.initCount++; return self;