From 258f41a30f5a797c0cfdb256a6824b7284dcc8e2 Mon Sep 17 00:00:00 2001 From: Kacper Rozniata <56474758+krozniata@users.noreply.github.com> Date: Mon, 8 Jul 2024 04:04:06 -0700 Subject: [PATCH] fix(iOS): remove deprecated method from RCTPerfMonitor & fix position (#43058) Summary: This PR removes usage of deprecated `statusBarFrame` method in `RCTPerfMonitor` . Instead `RCTPerfMonitor` now uses `safeAreaInsets` which also fixes issue causing Perf Monitor to appear under corner in landscape mode on e.g. `iPhone 15 Pro`. It also fixes initial position of expanded state which was causing it to render under notch. Also removed duplicate background color setting ## Changelog: [IOS] [REMOVED] - Remove usage of deprecated statusBarFrame method [IOS] [FIXED] - Fix position of RCTPerfMonitor in landscape mode & expanded mode Pull Request resolved: https://github.com/facebook/react-native/pull/43058 Test Plan: `RNTester` builds and runs successfully, `RCTPerfMonitor` works and displays correctly Reviewed By: dmytrorykun Differential Revision: D59116913 Pulled By: cipolleschi fbshipit-source-id: 0ff61f61b206c530cfb9e471bc2dc33a0a43c833 --- .../React/CoreModules/RCTPerfMonitor.mm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTPerfMonitor.mm b/packages/react-native/React/CoreModules/RCTPerfMonitor.mm index 13872eac556..771d93ff9d9 100644 --- a/packages/react-native/React/CoreModules/RCTPerfMonitor.mm +++ b/packages/react-native/React/CoreModules/RCTPerfMonitor.mm @@ -171,16 +171,15 @@ RCT_EXPORT_MODULE() - (UIView *)container { if (!_container) { - CGSize statusBarSize = RCTUIStatusBarManager().statusBarFrame.size; - CGFloat statusBarHeight = statusBarSize.height; - _container = [[UIView alloc] initWithFrame:CGRectMake(10, statusBarHeight, 180, RCTPerfMonitorBarHeight)]; + UIEdgeInsets safeInsets = RCTKeyWindow().safeAreaInsets; + + _container = + [[UIView alloc] initWithFrame:CGRectMake(safeInsets.left, safeInsets.top, 180, RCTPerfMonitorBarHeight)]; _container.layer.borderWidth = 2; _container.layer.borderColor = [UIColor lightGrayColor].CGColor; [_container addGestureRecognizer:self.gestureRecognizer]; [_container addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]]; - _container.backgroundColor = [UIColor whiteColor]; - _container.backgroundColor = [UIColor systemBackgroundColor]; } @@ -449,7 +448,9 @@ RCT_EXPORT_MODULE() { [self loadPerformanceLoggerData]; if (CGRectIsEmpty(_storedMonitorFrame)) { - _storedMonitorFrame = CGRectMake(0, 20, self.container.window.frame.size.width, RCTPerfMonitorExpandHeight); + UIEdgeInsets safeInsets = RCTKeyWindow().safeAreaInsets; + _storedMonitorFrame = + CGRectMake(safeInsets.left, safeInsets.top, self.container.window.frame.size.width, RCTPerfMonitorExpandHeight); [self.container addSubview:self.metrics]; } else { [_metrics reloadData];