Skip to content

Commit 9d7447a

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Add launchOptions and performanceLogger module injection (#59257)
Summary: Pull Request resolved: #59257 Extend RCTBridgeModule with optional launchOptions and performanceLogger properties, injected through RCTBridgeModuleDecorator from RCTInstance. This lets TurboModules read launch configuration and perf events without touching the deprecated bridge property. Changelog: [iOS][Added] - Add injectable launchOptions and performanceLogger module APIs Reviewed By: shwanton Differential Revision: D126567157 fbshipit-source-id: dca00a46c99cad9a0fd2e65a9fa71441941d411d
1 parent ba0b3db commit 9d7447a

8 files changed

Lines changed: 75 additions & 6 deletions

File tree

‎packages/react-native/React/Base/RCTBridgeModule.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@class RCTModuleRegistry;
2323
@class RCTViewRegistry;
2424
@class RCTCallableJSModules;
25+
@class RCTPerformanceLogger;
2526

2627
/**
2728
* The type of a block that is capable of sending a response to a bridged
@@ -168,6 +169,25 @@ RCT_EXTERN_C_END
168169
*/
169170
@property (nonatomic, weak, readwrite) RCTCallableJSModules *callableJSModules;
170171

172+
/**
173+
* The launch options that were used to initialize the React instance.
174+
* Useful for modules that need to read launch-time configuration.
175+
*
176+
* To implement this in your module, just add `@synthesize launchOptions =
177+
* _launchOptions;`. If using Swift, add `@objc var launchOptions:
178+
* NSDictionary!` to your module.
179+
*/
180+
@property (nonatomic, copy, readwrite) NSDictionary *launchOptions;
181+
182+
/**
183+
* Link to the Performance Logger that logs React Native perf events.
184+
*
185+
* To implement this in your module, just add `@synthesize performanceLogger =
186+
* _performanceLogger;`. If using Swift, add `@objc var performanceLogger:
187+
* RCTPerformanceLogger!` to your module.
188+
*/
189+
@property (nonatomic, strong, readwrite) RCTPerformanceLogger *performanceLogger;
190+
171191
/**
172192
* A reference to the RCTBridge. Useful for modules that require access
173193
* to bridge features, such as sending events or making JS calls. This

‎packages/react-native/React/Base/RCTBridgeModuleDecorator.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@class RCTBundleManager;
1111
@class RCTCallableJSModules;
1212
@class RCTModuleRegistry;
13+
@class RCTPerformanceLogger;
1314
@class RCTViewRegistry;
1415

1516
/**
@@ -24,11 +25,15 @@
2425
@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry;
2526
@property (nonatomic, strong, readonly) RCTBundleManager *bundleManager;
2627
@property (nonatomic, strong, readonly) RCTCallableJSModules *callableJSModules;
28+
@property (nonatomic, copy, readonly) NSDictionary *launchOptions;
29+
@property (nonatomic, strong, readonly) RCTPerformanceLogger *performanceLogger;
2730

2831
- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
2932
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
3033
bundleManager:(RCTBundleManager *)bundleManager
31-
callableJSModules:(RCTCallableJSModules *)callableJSModules;
34+
callableJSModules:(RCTCallableJSModules *)callableJSModules
35+
launchOptions:(NSDictionary *)launchOptions
36+
performanceLogger:(RCTPerformanceLogger *)performanceLogger;
3237

3338
- (void)attachInteropAPIsToModule:(id<RCTBridgeModule>)bridgeModule;
3439

‎packages/react-native/React/Base/RCTBridgeModuleDecorator.m‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
1313
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
1414
bundleManager:(RCTBundleManager *)bundleManager
1515
callableJSModules:(RCTCallableJSModules *)callableJSModules
16+
launchOptions:(NSDictionary *)launchOptions
17+
performanceLogger:(RCTPerformanceLogger *)performanceLogger
1618
{
1719
if (self = [super init]) {
1820
_viewRegistry_DEPRECATED = viewRegistry;
1921
_moduleRegistry = moduleRegistry;
2022
_bundleManager = bundleManager;
2123
_callableJSModules = callableJSModules;
24+
_launchOptions = [launchOptions copy];
25+
_performanceLogger = performanceLogger;
2226
}
2327
return self;
2428
}
@@ -68,6 +72,28 @@ - (void)attachInteropAPIsToModule:(id<RCTBridgeModule>)bridgeModule
6872
if ([bridgeModule respondsToSelector:@selector(setModuleRegistry:)]) {
6973
bridgeModule.moduleRegistry = _moduleRegistry;
7074
}
75+
76+
/**
77+
* Attach the launch options to this TurboModule, which allows this TurboModule
78+
* to read the launch-time configuration of the React instance.
79+
*
80+
* Usage: In the TurboModule @implementation, include:
81+
* `@synthesize launchOptions = _launchOptions`
82+
*/
83+
if ([bridgeModule respondsToSelector:@selector(setLaunchOptions:)]) {
84+
bridgeModule.launchOptions = _launchOptions;
85+
}
86+
87+
/**
88+
* Attach the RCTPerformanceLogger to this TurboModule, which allows this
89+
* TurboModule to read React Native perf events.
90+
*
91+
* Usage: In the TurboModule @implementation, include:
92+
* `@synthesize performanceLogger = _performanceLogger`
93+
*/
94+
if ([bridgeModule respondsToSelector:@selector(setPerformanceLogger:)]) {
95+
bridgeModule.performanceLogger = _performanceLogger;
96+
}
7197
}
7298

7399
@end

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ - (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
129129
_bridgeModuleDecorator = [[RCTBridgeModuleDecorator alloc] initWithViewRegistry:[RCTViewRegistry new]
130130
moduleRegistry:moduleRegistry
131131
bundleManager:bundleManager
132-
callableJSModules:[RCTCallableJSModules new]];
132+
callableJSModules:[RCTCallableJSModules new]
133+
launchOptions:launchOptions
134+
performanceLogger:_performanceLogger];
133135
_devMenuConfigurationDecorator =
134136
#if RCT_DEV_MENU
135137
[[RCTDevMenuConfigurationDecorator alloc] initWithDevMenuConfiguration:devMenuConfiguration];

‎scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,12 @@ interface RCTBridge : public NSObject <RCTInvalidating> {
703703
}
704704

705705
interface RCTBridgeModuleDecorator : public NSObject {
706+
public @property (copy, readonly) NSDictionary* launchOptions;
706707
public @property (strong, readonly) RCTBundleManager* bundleManager;
707708
public @property (strong, readonly) RCTCallableJSModules* callableJSModules;
708709
public @property (strong, readonly) RCTModuleRegistry* moduleRegistry;
709-
public virtual instancetype initWithViewRegistry:moduleRegistry:bundleManager:callableJSModules:(RCTViewRegistry* viewRegistry, RCTModuleRegistry* moduleRegistry, RCTBundleManager* bundleManager, RCTCallableJSModules* callableJSModules);
710+
public @property (strong, readonly) RCTPerformanceLogger* performanceLogger;
711+
public virtual instancetype initWithViewRegistry:moduleRegistry:bundleManager:callableJSModules:launchOptions:performanceLogger:(RCTViewRegistry* viewRegistry, RCTModuleRegistry* moduleRegistry, RCTBundleManager* bundleManager, RCTCallableJSModules* callableJSModules, NSDictionary* launchOptions, RCTPerformanceLogger* performanceLogger);
710712
public virtual void attachInteropAPIsToModule:(id<RCTBridgeModule> bridgeModule);
711713
}
712714

@@ -2555,6 +2557,8 @@ protocol RCTBridgeMethod : public NSObject {
25552557
}
25562558

25572559
protocol RCTBridgeModule : public NSObject {
2560+
public @property (copy) NSDictionary* launchOptions;
2561+
public @property (strong) RCTPerformanceLogger* performanceLogger;
25582562
public @property (strong, readonly) dispatch_queue_t methodQueue;
25592563
public @property (weak) RCTBundleManager* bundleManager;
25602564
public @property (weak) RCTCallableJSModules* callableJSModules;

‎scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,12 @@ interface RCTBridge : public NSObject <RCTInvalidating> {
712712
}
713713

714714
interface RCTBridgeModuleDecorator : public NSObject {
715+
public @property (copy, readonly) NSDictionary* launchOptions;
715716
public @property (strong, readonly) RCTBundleManager* bundleManager;
716717
public @property (strong, readonly) RCTCallableJSModules* callableJSModules;
717718
public @property (strong, readonly) RCTModuleRegistry* moduleRegistry;
718-
public virtual instancetype initWithViewRegistry:moduleRegistry:bundleManager:callableJSModules:(RCTViewRegistry* viewRegistry, RCTModuleRegistry* moduleRegistry, RCTBundleManager* bundleManager, RCTCallableJSModules* callableJSModules);
719+
public @property (strong, readonly) RCTPerformanceLogger* performanceLogger;
720+
public virtual instancetype initWithViewRegistry:moduleRegistry:bundleManager:callableJSModules:launchOptions:performanceLogger:(RCTViewRegistry* viewRegistry, RCTModuleRegistry* moduleRegistry, RCTBundleManager* bundleManager, RCTCallableJSModules* callableJSModules, NSDictionary* launchOptions, RCTPerformanceLogger* performanceLogger);
719721
public virtual void attachInteropAPIsToModule:(id<RCTBridgeModule> bridgeModule);
720722
}
721723

@@ -2613,6 +2615,8 @@ protocol RCTBridgeMethod : public NSObject {
26132615
}
26142616

26152617
protocol RCTBridgeModule : public NSObject {
2618+
public @property (copy) NSDictionary* launchOptions;
2619+
public @property (strong) RCTPerformanceLogger* performanceLogger;
26162620
public @property (strong, readonly) dispatch_queue_t methodQueue;
26172621
public @property (weak) RCTBundleManager* bundleManager;
26182622
public @property (weak) RCTCallableJSModules* callableJSModules;

‎scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,12 @@ interface RCTBridge : public NSObject <RCTInvalidating> {
703703
}
704704

705705
interface RCTBridgeModuleDecorator : public NSObject {
706+
public @property (copy, readonly) NSDictionary* launchOptions;
706707
public @property (strong, readonly) RCTBundleManager* bundleManager;
707708
public @property (strong, readonly) RCTCallableJSModules* callableJSModules;
708709
public @property (strong, readonly) RCTModuleRegistry* moduleRegistry;
709-
public virtual instancetype initWithViewRegistry:moduleRegistry:bundleManager:callableJSModules:(RCTViewRegistry* viewRegistry, RCTModuleRegistry* moduleRegistry, RCTBundleManager* bundleManager, RCTCallableJSModules* callableJSModules);
710+
public @property (strong, readonly) RCTPerformanceLogger* performanceLogger;
711+
public virtual instancetype initWithViewRegistry:moduleRegistry:bundleManager:callableJSModules:launchOptions:performanceLogger:(RCTViewRegistry* viewRegistry, RCTModuleRegistry* moduleRegistry, RCTBundleManager* bundleManager, RCTCallableJSModules* callableJSModules, NSDictionary* launchOptions, RCTPerformanceLogger* performanceLogger);
710712
public virtual void attachInteropAPIsToModule:(id<RCTBridgeModule> bridgeModule);
711713
}
712714

@@ -2547,6 +2549,8 @@ protocol RCTBridgeMethod : public NSObject {
25472549
}
25482550

25492551
protocol RCTBridgeModule : public NSObject {
2552+
public @property (copy) NSDictionary* launchOptions;
2553+
public @property (strong) RCTPerformanceLogger* performanceLogger;
25502554
public @property (strong, readonly) dispatch_queue_t methodQueue;
25512555
public @property (weak) RCTBundleManager* bundleManager;
25522556
public @property (weak) RCTCallableJSModules* callableJSModules;

‎scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,12 @@ interface RCTBridge : public NSObject <RCTInvalidating> {
703703
}
704704

705705
interface RCTBridgeModuleDecorator : public NSObject {
706+
public @property (copy, readonly) NSDictionary* launchOptions;
706707
public @property (strong, readonly) RCTBundleManager* bundleManager;
707708
public @property (strong, readonly) RCTCallableJSModules* callableJSModules;
708709
public @property (strong, readonly) RCTModuleRegistry* moduleRegistry;
709-
public virtual instancetype initWithViewRegistry:moduleRegistry:bundleManager:callableJSModules:(RCTViewRegistry* viewRegistry, RCTModuleRegistry* moduleRegistry, RCTBundleManager* bundleManager, RCTCallableJSModules* callableJSModules);
710+
public @property (strong, readonly) RCTPerformanceLogger* performanceLogger;
711+
public virtual instancetype initWithViewRegistry:moduleRegistry:bundleManager:callableJSModules:launchOptions:performanceLogger:(RCTViewRegistry* viewRegistry, RCTModuleRegistry* moduleRegistry, RCTBundleManager* bundleManager, RCTCallableJSModules* callableJSModules, NSDictionary* launchOptions, RCTPerformanceLogger* performanceLogger);
710712
public virtual void attachInteropAPIsToModule:(id<RCTBridgeModule> bridgeModule);
711713
}
712714

@@ -2555,6 +2557,8 @@ protocol RCTBridgeMethod : public NSObject {
25552557
}
25562558

25572559
protocol RCTBridgeModule : public NSObject {
2560+
public @property (copy) NSDictionary* launchOptions;
2561+
public @property (strong) RCTPerformanceLogger* performanceLogger;
25582562
public @property (strong, readonly) dispatch_queue_t methodQueue;
25592563
public @property (weak) RCTBundleManager* bundleManager;
25602564
public @property (weak) RCTCallableJSModules* callableJSModules;

0 commit comments

Comments
 (0)