Skip to content

Commit 90296be

Browse files
zhongwuzwfacebook-github-bot
authored andcommitted
Support launchOptions in bridgeless mode (#43757)
Summary: Support launchOptions in bridgeless mode bypass-github-export-checks ## Changelog: [IOS] [FIXED] - Support launchOptions in bridgeless mode Pull Request resolved: #43757 Test Plan: ``` useEffect(() => { const processInitialURL = async () => { const url = await Linking.getInitialURL(); if (url !== null) { console.log(`Initial url is: ${url}`); } }; processInitialURL(); }, []); ``` Reviewed By: javache Differential Revision: D55790758 Pulled By: cipolleschi fbshipit-source-id: 0f6aa6bdcebfc5bc42d632bea9193f122c1eb84f
1 parent 5ea5117 commit 90296be

File tree

11 files changed

+38
-16
lines changed

11 files changed

+38
-16
lines changed

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName
123123
RCTEnableTurboModuleInterop(YES);
124124
RCTEnableTurboModuleInteropBridgeProxy(YES);
125125

126-
[self createReactHostIfNeeded];
126+
[self createReactHostIfNeeded:launchOptions];
127127

128128
RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:moduleName initialProperties:initProps];
129129

@@ -207,7 +207,7 @@ - (void)createBridgeAdapterIfNeeded
207207

208208
#pragma mark - New Arch Utilities
209209

210-
- (void)createReactHostIfNeeded
210+
- (void)createReactHostIfNeeded:(NSDictionary *)launchOptions
211211
{
212212
if (_reactHost) {
213213
return;
@@ -219,7 +219,8 @@ - (void)createReactHostIfNeeded
219219
turboModuleManagerDelegate:_turboModuleManagerDelegate
220220
jsEngineProvider:^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
221221
return [weakSelf createJSRuntimeFactory];
222-
}];
222+
}
223+
launchOptions:launchOptions];
223224
[_reactHost setBundleURLProvider:^NSURL *() {
224225
return [weakSelf bundleURL];
225226
}];

packages/react-native/React/Base/RCTBridgeProxy.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#import "RCTBridgeModule.h"
1111

12+
NS_ASSUME_NONNULL_BEGIN
13+
1214
@class RCTBundleManager;
1315
@class RCTCallableJSModules;
1416
@class RCTModuleRegistry;
@@ -22,7 +24,8 @@
2224
callableJSModules:(RCTCallableJSModules *)callableJSModules
2325
dispatchToJSThread:(void (^)(dispatch_block_t))dispatchToJSThread
2426
registerSegmentWithId:(void (^)(NSNumber *, NSString *))registerSegmentWithId
25-
runtime:(void *)runtime NS_DESIGNATED_INITIALIZER;
27+
runtime:(void *)runtime
28+
launchOptions:(nullable NSDictionary *)launchOptions NS_DESIGNATED_INITIALIZER;
2629

2730
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel;
2831
- (void)forwardInvocation:(NSInvocation *)invocation;
@@ -37,3 +40,5 @@
3740
- (id)moduleForName:(NSString *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyLoad;
3841

3942
@end
43+
44+
NS_ASSUME_NONNULL_END

packages/react-native/React/Base/RCTBridgeProxy.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ @implementation RCTBridgeProxy {
3535
RCTModuleRegistry *_moduleRegistry;
3636
RCTBundleManager *_bundleManager;
3737
RCTCallableJSModules *_callableJSModules;
38+
NSDictionary *_launchOptions;
3839
void (^_dispatchToJSThread)(dispatch_block_t);
3940
void (^_registerSegmentWithId)(NSNumber *, NSString *);
4041
void *_runtime;
@@ -47,6 +48,7 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
4748
dispatchToJSThread:(void (^)(dispatch_block_t))dispatchToJSThread
4849
registerSegmentWithId:(void (^)(NSNumber *, NSString *))registerSegmentWithId
4950
runtime:(void *)runtime
51+
launchOptions:(nullable NSDictionary *)launchOptions
5052
{
5153
self = [super self];
5254
if (self) {
@@ -57,6 +59,7 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
5759
_dispatchToJSThread = dispatchToJSThread;
5860
_registerSegmentWithId = registerSegmentWithId;
5961
_runtime = runtime;
62+
_launchOptions = [launchOptions copy];
6063
}
6164
return self;
6265
}
@@ -191,8 +194,7 @@ - (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path
191194

192195
- (NSDictionary *)launchOptions
193196
{
194-
[self logError:@"This method is not supported. Returning nil." cmd:_cmd];
195-
return nil;
197+
return _launchOptions;
196198
}
197199

198200
- (BOOL)loading

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass
674674
*/
675675
if (_bridge) {
676676
[(id)module setValue:_bridge forKey:@"bridge"];
677-
} else if (_bridgeProxy && [self _isLegacyModuleClass:[module class]]) {
677+
} else if (_bridgeProxy) {
678678
[(id)module setValue:_bridgeProxy forKey:@"bridge"];
679679
}
680680
} @catch (NSException *exception) {

packages/react-native/ReactCommon/react/runtime/iostests/RCTHostTests.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ - (void)setUp
5858
turboModuleManagerDelegate:OCMProtocolMock(@protocol(RCTTurboModuleManagerDelegate))
5959
jsEngineProvider:^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
6060
return std::make_shared<facebook::react::RCTHermesInstance>();
61-
}];
61+
}
62+
launchOptions:nil];
6263
}
6364

6465
- (void)tearDown

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ typedef std::shared_ptr<facebook::react::JSRuntimeFactory> (^RCTHostJSEngineProv
4848
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
4949
hostDelegate:(id<RCTHostDelegate>)hostDelegate
5050
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
51-
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider NS_DESIGNATED_INITIALIZER;
51+
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
52+
launchOptions:(nullable NSDictionary *)launchOptions NS_DESIGNATED_INITIALIZER;
5253

5354
@property (nonatomic, weak, nullable) id<RCTHostRuntimeDelegate> runtimeDelegate;
5455

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ @implementation RCTHost {
5858
RCTHostBundleURLProvider _bundleURLProvider;
5959
RCTHostJSEngineProvider _jsEngineProvider;
6060

61+
NSDictionary *_launchOptions;
62+
6163
// All the surfaces that need to be started after main bundle execution
6264
NSMutableArray<RCTFabricSurface *> *_surfaceStartBuffer;
6365
std::mutex _surfaceStartBufferMutex;
@@ -85,6 +87,7 @@ - (instancetype)initWithBundleURL:(NSURL *)bundleURL
8587
hostDelegate:(id<RCTHostDelegate>)hostDelegate
8688
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
8789
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
90+
launchOptions:(nullable NSDictionary *)launchOptions
8891
{
8992
if (self = [super init]) {
9093
_hostDelegate = hostDelegate;
@@ -93,6 +96,7 @@ - (instancetype)initWithBundleURL:(NSURL *)bundleURL
9396
_bundleManager = [RCTBundleManager new];
9497
_moduleRegistry = [RCTModuleRegistry new];
9598
_jsEngineProvider = [jsEngineProvider copy];
99+
_launchOptions = [launchOptions copy];
96100

97101
__weak RCTHost *weakSelf = self;
98102

@@ -204,7 +208,8 @@ - (void)start
204208
turboModuleManagerDelegate:_turboModuleManagerDelegate
205209
onInitialBundleLoad:_onInitialBundleLoad
206210
moduleRegistry:_moduleRegistry
207-
parentInspectorTarget:_inspectorTarget.get()];
211+
parentInspectorTarget:_inspectorTarget.get()
212+
launchOptions:_launchOptions];
208213
[_hostDelegate hostDidStart:self];
209214
}
210215

@@ -284,7 +289,8 @@ - (void)didReceiveReloadCommand
284289
turboModuleManagerDelegate:_turboModuleManagerDelegate
285290
onInitialBundleLoad:_onInitialBundleLoad
286291
moduleRegistry:_moduleRegistry
287-
parentInspectorTarget:_inspectorTarget.get()];
292+
parentInspectorTarget:_inspectorTarget.get()
293+
launchOptions:_launchOptions];
288294
[_hostDelegate hostDidStart:self];
289295

290296
for (RCTFabricSurface *surface in [self _getAttachedSurfaces]) {

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ typedef void (^_Null_unspecified RCTInstanceInitialBundleLoadCompletionBlock)();
6262
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
6363
onInitialBundleLoad:(RCTInstanceInitialBundleLoadCompletionBlock)onInitialBundleLoad
6464
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
65-
parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget;
65+
parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget
66+
launchOptions:(nullable NSDictionary *)launchOptions;
6667

6768
- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args;
6869

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ @implementation RCTInstance {
8484
std::mutex _invalidationMutex;
8585
std::atomic<bool> _valid;
8686
RCTJSThreadManager *_jsThreadManager;
87+
NSDictionary *_launchOptions;
8788

8889
// APIs supporting interop with native modules and view managers
8990
RCTBridgeModuleDecorator *_bridgeModuleDecorator;
@@ -100,6 +101,7 @@ - (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
100101
onInitialBundleLoad:(RCTInstanceInitialBundleLoadCompletionBlock)onInitialBundleLoad
101102
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
102103
parentInspectorTarget:(jsinspector_modern::HostTarget *)parentInspectorTarget
104+
launchOptions:(nullable NSDictionary *)launchOptions
103105
{
104106
if (self = [super init]) {
105107
_performanceLogger = [RCTPerformanceLogger new];
@@ -125,6 +127,7 @@ - (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
125127
[weakSelf callFunctionOnJSModule:moduleName method:methodName args:args];
126128
}];
127129
}
130+
_launchOptions = launchOptions;
128131

129132
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
130133

@@ -277,7 +280,8 @@ - (void)_start
277280
[strongSelf registerSegmentWithId:segmentId path:path];
278281
}
279282
}
280-
runtime:_reactInstance->getJavaScriptContext()];
283+
runtime:_reactInstance->getJavaScriptContext()
284+
launchOptions:_launchOptions];
281285
bridgeProxy.jsCallInvoker = jsCallInvoker;
282286
[RCTBridge setCurrentBridge:(RCTBridge *)bridgeProxy];
283287

packages/react-native/ReactCommon/react/test_utils/ios/Shims/ShimRCTInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@property int initCount;
1313
@property int invalidateCount;
14-
14+
@property NSDictionary *launchOptions;
1515
@property NSString *jsModuleName;
1616
@property NSString *method;
1717
@property NSArray *args;

0 commit comments

Comments
 (0)