Skip to content
Closed
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
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
66 changes: 23 additions & 43 deletions packages/react-native/React/CoreModules/RCTPerfMonitor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#import <React/RCTDevSettings.h>

#import <React/RCTBridge+Private.h>
#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcherProtocol.h>
#import <React/RCTFPSGraph.h>
#import <React/RCTInitializing.h>
#import <React/RCTInvalidating.h>
Expand Down Expand Up @@ -58,8 +58,13 @@ static vm_size_t RCTGetResidentMemorySize(void)
return memoryUsageInByte;
}

@interface RCTPerfMonitor
: NSObject <RCTBridgeModule, RCTTurboModule, RCTInvalidating, UITableViewDataSource, UITableViewDelegate>
@interface RCTPerfMonitor : NSObject <
RCTBridgeModule,
RCTTurboModule,
RCTInvalidating,
RCTJSDispatcherModule,
UITableViewDataSource,
UITableViewDelegate>

#if __has_include(<React/RCTDevMenu.h>)
@property (nonatomic, strong, readonly) RCTDevMenuItem *devMenuItem;
Expand All @@ -68,7 +73,6 @@ @interface RCTPerfMonitor
@property (nonatomic, strong, readonly) UIView *container;
@property (nonatomic, strong, readonly) UILabel *memory;
@property (nonatomic, strong, readonly) UILabel *heap;
@property (nonatomic, strong, readonly) UILabel *views;
@property (nonatomic, strong, readonly) UITableView *metrics;
@property (nonatomic, strong, readonly) RCTFPSGraph *jsGraph;
@property (nonatomic, strong, readonly) RCTFPSGraph *uiGraph;
Expand All @@ -85,7 +89,6 @@ @implementation RCTPerfMonitor {
UIView *_container;
UILabel *_memory;
UILabel *_heap;
UILabel *_views;
UILabel *_uiGraphLabel;
UILabel *_jsGraphLabel;
UITableView *_metrics;
Expand All @@ -109,8 +112,9 @@ @implementation RCTPerfMonitor {
NSArray *_perfLoggerMarks;
}

@synthesize bridge = _bridge;
@synthesize dispatchToJSThread = _dispatchToJSThread;
@synthesize moduleRegistry = _moduleRegistry;
@synthesize performanceLogger = _performanceLogger;

RCT_EXPORT_MODULE()

Expand Down Expand Up @@ -172,7 +176,7 @@ - (UIView *)container
UIEdgeInsets safeInsets = RCTKeyWindow().safeAreaInsets;

_container =
[[UIView alloc] initWithFrame:CGRectMake(safeInsets.left, safeInsets.top, 180, RCTPerfMonitorBarHeight)];
[[UIView alloc] initWithFrame:CGRectMake(safeInsets.left, safeInsets.top, 136, RCTPerfMonitorBarHeight)];
_container.layer.borderWidth = 2;
_container.layer.borderColor = [UIColor lightGrayColor].CGColor;
[_container addGestureRecognizer:self.gestureRecognizer];
Expand Down Expand Up @@ -212,38 +216,26 @@ - (UILabel *)heap
return _heap;
}

- (UILabel *)views
{
if (_views == nullptr) {
_views = [[UILabel alloc] initWithFrame:CGRectMake(88, 0, 44, RCTPerfMonitorBarHeight)];
_views.font = [UIFont systemFontOfSize:12];
_views.numberOfLines = 3;
_views.textAlignment = NSTextAlignmentCenter;
}

return _views;
}

- (RCTFPSGraph *)uiGraph
{
if (_uiGraph == nullptr) {
_uiGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(134, 14, 40, 30) color:[UIColor lightGrayColor]];
_uiGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(90, 14, 40, 30) color:[UIColor lightGrayColor]];
}
return _uiGraph;
}

- (RCTFPSGraph *)jsGraph
{
if (_jsGraph == nullptr) {
_jsGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(178, 14, 40, 30) color:[UIColor lightGrayColor]];
_jsGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(134, 14, 40, 30) color:[UIColor lightGrayColor]];
}
return _jsGraph;
}

- (UILabel *)uiGraphLabel
{
if (_uiGraphLabel == nullptr) {
_uiGraphLabel = [[UILabel alloc] initWithFrame:CGRectMake(134, 3, 40, 10)];
_uiGraphLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 3, 40, 10)];
_uiGraphLabel.font = [UIFont systemFontOfSize:11];
_uiGraphLabel.textAlignment = NSTextAlignmentCenter;
_uiGraphLabel.text = @"UI";
Expand All @@ -255,7 +247,7 @@ - (UILabel *)uiGraphLabel
- (UILabel *)jsGraphLabel
{
if (_jsGraphLabel == nullptr) {
_jsGraphLabel = [[UILabel alloc] initWithFrame:CGRectMake(178, 3, 38, 10)];
_jsGraphLabel = [[UILabel alloc] initWithFrame:CGRectMake(134, 3, 38, 10)];
_jsGraphLabel.font = [UIFont systemFontOfSize:11];
_jsGraphLabel.textAlignment = NSTextAlignmentCenter;
_jsGraphLabel.text = @"JS";
Expand Down Expand Up @@ -289,7 +281,6 @@ - (void)show

[self.container addSubview:self.memory];
[self.container addSubview:self.heap];
[self.container addSubview:self.views];
[self.container addSubview:self.uiGraph];
[self.container addSubview:self.uiGraphLabel];

Expand All @@ -309,12 +300,12 @@ - (void)show
[self.container addSubview:self.jsGraph];
[self.container addSubview:self.jsGraphLabel];

[_bridge
dispatchBlock:^{
self->_jsDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(threadUpdate:)];
[self->_jsDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
queue:RCTJSThread];
if (_dispatchToJSThread != nullptr) {
_dispatchToJSThread(^{
self->_jsDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(threadUpdate:)];
[self->_jsDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
});
}
}

- (void)hide
Expand Down Expand Up @@ -415,15 +406,6 @@ - (void)parse:(NSString *)log

- (void)updateStats
{
NSDictionary<NSNumber *, UIView *> *views = [_bridge.uiManager valueForKey:@"viewRegistry"];
NSUInteger viewCount = views.count;
NSUInteger visibleViewCount = 0;
for (UIView *view in views.allValues) {
if ((view.window != nullptr) || (view.superview.window != nullptr)) {
visibleViewCount++;
}
}

// Ensure the container always stays on top of newly added views
if ([_container.superview.subviews lastObject] != _container) {
[_container.superview bringSubviewToFront:_container];
Expand All @@ -432,8 +414,6 @@ - (void)updateStats
double mem = (double)RCTGetResidentMemorySize() / 1024 / 1024;
self.memory.text = [NSString stringWithFormat:@"RAM\n%.2lf\nMB", mem];
self.heap.text = [NSString stringWithFormat:@"JSC\n%.2lf\nMB", (double)_heapSize / 1024];
self.views.text =
[NSString stringWithFormat:@"Views\n%lu\n%lu", (unsigned long)visibleViewCount, (unsigned long)viewCount];

__weak __typeof__(self) weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -481,7 +461,7 @@ - (void)loadPerformanceLoggerData
{
NSUInteger i = 0;
NSMutableArray<NSString *> *data = [NSMutableArray new];
RCTPerformanceLogger *performanceLogger = [_bridge performanceLogger];
RCTPerformanceLogger *performanceLogger = _performanceLogger;
NSArray<NSNumber *> *values = [performanceLogger valuesForTags];
for (NSString *label in LabelsForRCTPerformanceLoggerTags()) {
long long value = values[i + 1].longLongValue - values[i].longLongValue;
Expand Down
8 changes: 3 additions & 5 deletions packages/react-native/React/Views/RCTComponentData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, readonly) Class managerClass;
@property (nonatomic, copy, readonly) NSString *name;
@property (nonatomic, weak, readonly) RCTViewManager *manager;
/*
* When running React Native with the bridge, view managers are retained by the
* bridge. When running in bridgeless mode, allocate and retain view managers
* in this class.
* The view manager for this component. In bridgeless mode, view managers
* are allocated and retained by this class.
*/
@property (nonatomic, strong, readonly) RCTViewManager *bridgelessViewManager;
@property (nonatomic, strong, readonly, nullable) RCTViewManager *manager;

- (instancetype)initWithManagerClass:(Class)managerClass
bridge:(RCTBridge *)bridge
Expand Down
Loading
Loading