Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#import <React/RCTLinkingManager.h>

#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTBridge.h>
#import <React/RCTConvert.h>
#import <React/RCTLog.h>
#import <React/RCTUtils.h>
Expand Down Expand Up @@ -36,6 +35,8 @@ @implementation RCTLinkingManager

RCT_EXPORT_MODULE()

@synthesize launchOptions = _launchOptions;

+ (void)postNotificationWithURL:(NSURL *)URL
{
NSDictionary<NSString *, id> *payload = @{@"url" : URL.absoluteString};
Expand Down Expand Up @@ -207,11 +208,10 @@ - (void)canOpenURL:(NSString *)urlString
- (void)getInitialURL:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject
{
NSURL *initialURL = nil;
if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey] != nullptr) {
initialURL = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
if (self.launchOptions[UIApplicationLaunchOptionsURLKey] != nullptr) {
initialURL = self.launchOptions[UIApplicationLaunchOptionsURLKey];
} else {
NSDictionary *userActivityDictionary =
self.bridge.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
NSDictionary *userActivityDictionary = self.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
if ([userActivityDictionary[UIApplicationLaunchOptionsUserActivityTypeKey] isEqual:NSUserActivityTypeBrowsingWeb]) {
initialURL = ((NSUserActivity *)userActivityDictionary[@"UIApplicationLaunchOptionsUserActivityKey"]).webpageURL;
}
Expand Down
20 changes: 20 additions & 0 deletions packages/react-native/React/Base/RCTBridgeModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@class RCTModuleRegistry;
@class RCTViewRegistry;
@class RCTCallableJSModules;
@class RCTPerformanceLogger;

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

/**
* The launch options that were used to initialize the React instance.
* Useful for modules that need to read launch-time configuration.
*
* To implement this in your module, just add `@synthesize launchOptions =
* _launchOptions;`. If using Swift, add `@objc var launchOptions:
* NSDictionary!` to your module.
*/
@property (nonatomic, copy, readwrite) NSDictionary *launchOptions;

/**
* Link to the Performance Logger that logs React Native perf events.
*
* To implement this in your module, just add `@synthesize performanceLogger =
* _performanceLogger;`. If using Swift, add `@objc var performanceLogger:
* RCTPerformanceLogger!` to your module.
*/
@property (nonatomic, strong, readwrite) RCTPerformanceLogger *performanceLogger;

/**
* A reference to the RCTBridge. Useful for modules that require access
* to bridge features, such as sending events or making JS calls. This
Expand Down
7 changes: 6 additions & 1 deletion packages/react-native/React/Base/RCTBridgeModuleDecorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@class RCTBundleManager;
@class RCTCallableJSModules;
@class RCTModuleRegistry;
@class RCTPerformanceLogger;
@class RCTViewRegistry;

/**
Expand All @@ -24,11 +25,15 @@
@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry;
@property (nonatomic, strong, readonly) RCTBundleManager *bundleManager;
@property (nonatomic, strong, readonly) RCTCallableJSModules *callableJSModules;
@property (nonatomic, copy, readonly) NSDictionary *launchOptions;
@property (nonatomic, strong, readonly) RCTPerformanceLogger *performanceLogger;

- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
bundleManager:(RCTBundleManager *)bundleManager
callableJSModules:(RCTCallableJSModules *)callableJSModules;
callableJSModules:(RCTCallableJSModules *)callableJSModules
launchOptions:(NSDictionary *)launchOptions
performanceLogger:(RCTPerformanceLogger *)performanceLogger;

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

Expand Down
26 changes: 26 additions & 0 deletions packages/react-native/React/Base/RCTBridgeModuleDecorator.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
bundleManager:(RCTBundleManager *)bundleManager
callableJSModules:(RCTCallableJSModules *)callableJSModules
launchOptions:(NSDictionary *)launchOptions
performanceLogger:(RCTPerformanceLogger *)performanceLogger
{
if (self = [super init]) {
_viewRegistry_DEPRECATED = viewRegistry;
_moduleRegistry = moduleRegistry;
_bundleManager = bundleManager;
_callableJSModules = callableJSModules;
_launchOptions = [launchOptions copy];
_performanceLogger = performanceLogger;
}
return self;
}
Expand Down Expand Up @@ -68,6 +72,28 @@ - (void)attachInteropAPIsToModule:(id<RCTBridgeModule>)bridgeModule
if ([bridgeModule respondsToSelector:@selector(setModuleRegistry:)]) {
bridgeModule.moduleRegistry = _moduleRegistry;
}

/**
* Attach the launch options to this TurboModule, which allows this TurboModule
* to read the launch-time configuration of the React instance.
*
* Usage: In the TurboModule @implementation, include:
* `@synthesize launchOptions = _launchOptions`
*/
if ([bridgeModule respondsToSelector:@selector(setLaunchOptions:)]) {
bridgeModule.launchOptions = _launchOptions;
}

/**
* Attach the RCTPerformanceLogger to this TurboModule, which allows this
* TurboModule to read React Native perf events.
*
* Usage: In the TurboModule @implementation, include:
* `@synthesize performanceLogger = _performanceLogger`
*/
if ([bridgeModule respondsToSelector:@selector(setPerformanceLogger:)]) {
bridgeModule.performanceLogger = _performanceLogger;
}
}

@end
92 changes: 9 additions & 83 deletions packages/react-native/React/CoreModules/RCTDevSettings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#import <React/RCTDevMenu.h>
#import <React/RCTEventDispatcherProtocol.h>
#import <React/RCTLog.h>
#import <React/RCTProfile.h>
#import <React/RCTReloadCommand.h>
#import <React/RCTUtils.h>
#import <atomic>
Expand Down Expand Up @@ -165,11 +164,6 @@ + (BOOL)requiresMainQueueSetup
return NO;
}

- (BOOL)_isBridgeMode
{
return [self.bridge isKindOfClass:[RCTBridge class]];
}

- (instancetype)initWithDataSource:(id<RCTDevSettingsDataSource>)dataSource
{
if (self = [super init]) {
Expand Down Expand Up @@ -221,36 +215,9 @@ - (void)initialize
#endif

#if RCT_ENABLE_INSPECTOR
if ([self _isBridgeMode]) {
// We need this dispatch to the main thread because the bridge is not yet
// finished with its initialisation. By the time it relinquishes control of
// the main thread, this operation can be performed.
__weak __typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
__typeof(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
id dispatchBlock = ^{
__typeof(self) strongSelf2 = weakSelf;
if (!strongSelf2) {
return;
}
NSURL *url = strongSelf2.bundleManager.bundleURL;
[RCTInspectorDevServerHelper connectWithBundleURL:url];
};
[strongSelf.bridge dispatchBlock:dispatchBlock queue:RCTJSThread];
});
} else {
NSURL *url = self.bundleManager.bundleURL;
[RCTInspectorDevServerHelper connectWithBundleURL:url];
}
NSURL *url = self.bundleManager.bundleURL;
[RCTInspectorDevServerHelper connectWithBundleURL:url];
#endif

__weak __typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf _synchronizeAllSettings];
});
}

- (dispatch_queue_t)methodQueue
Expand Down Expand Up @@ -295,11 +262,7 @@ - (void)setIsShakeGestureEnabled:(BOOL)isShakeGestureEnabled
- (BOOL)isDeviceDebuggingAvailable
{
#if RCT_ENABLE_INSPECTOR
if ([self _isBridgeMode]) {
return self.bridge.isInspectable;
} else {
return self.isInspectable;
}
return self.isInspectable;
#else
return false;
#endif // RCT_ENABLE_INSPECTOR
Expand Down Expand Up @@ -341,33 +304,13 @@ - (BOOL)isShakeToShowDevMenuEnabled
- (void)setProfilingEnabled:(BOOL)enabled
{
[self _updateSettingWithValue:@(enabled) forKey:kRCTDevSettingProfilingEnabled];
[self _profilingSettingDidChange];
}

- (BOOL)isProfilingEnabled
{
return [[self settingForKey:kRCTDevSettingProfilingEnabled] boolValue];
}

- (void)_profilingSettingDidChange
{
BOOL enabled = self.isProfilingEnabled;
if (self.isHotLoadingAvailable && enabled != RCTProfileIsProfiling()) {
if (enabled) {
[self.bridge startProfiling];
} else {
__weak __typeof(self) weakSelf = self;
[self.bridge stopProfiling:^(NSData *logData) {
__typeof(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
RCTProfileSendResult(strongSelf.bridge, @"systrace", logData);
}];
}
}
}

- (void)setHotLoadingEnabled:(BOOL)enabled
{
if (self.isHotLoadingEnabled != enabled) {
Expand Down Expand Up @@ -430,17 +373,12 @@ - (BOOL)isPerfMonitorShown

- (void)setExecutorClass:(Class)executorClass
{
_executorClass = executorClass;
if (self.bridge.executorClass != executorClass) {
// TODO (6929129): we can remove this special case test once we have better
// support for custom executors in the dev menu. But right now this is
// needed to prevent overriding a custom executor with the default if a
// custom executor has been set directly on the bridge
if (executorClass == Nil) {
return;
}

self.bridge.executorClass = executorClass;
if (executorClass == Nil) {
_executorClass = Nil;
return;
}
if (_executorClass != executorClass) {
_executorClass = executorClass;
RCTTriggerReloadCommandListeners(@"Custom executor class reset");
}
}
Expand Down Expand Up @@ -505,15 +443,6 @@ - (void)openDebugger

#pragma mark - Internal

/**
* Query the data source for all possible settings and make sure we're doing the right
* thing for the state of each setting.
*/
- (void)_synchronizeAllSettings
{
[self _profilingSettingDidChange];
}

- (void)jsLoaded:(NSNotification *)notification
{
// In bridge mode, the bridge that sent the notif must be the same as the one stored in this module.
Expand All @@ -530,9 +459,6 @@ - (void)jsLoaded:(NSNotification *)notification
if (!strongSelf) {
return;
}
// update state again after the bridge has finished loading
[strongSelf _synchronizeAllSettings];

// Inspector can only be shown after JS has loaded
if ([strongSelf isElementInspectorShown]) {
#pragma clang diagnostic push
Expand Down
Loading
Loading