From 209140046b451170315f9f30a19644a04ab80207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Thu, 15 Feb 2024 09:11:41 -0800 Subject: [PATCH] fix: PerfMonitor option not showing on iOS (Bridgeless) (#42891) Summary: This PR fixes PerfMonitor option not showing on iOS when running bridgeless. The `initialize` method is not called in bridgeless which causes this option to not be added. I've converted this approach to work for both bridgeless and non-bridgeless. bypass-github-export-checks ## Changelog: [IOS] [FIXED] - Perf Monitor option not showing in Bridgeless Pull Request resolved: https://github.com/facebook/react-native/pull/42891 Test Plan: Run RNTester, open Perf monitor Reviewed By: RSNara Differential Revision: D53518507 Pulled By: cipolleschi fbshipit-source-id: c16d41006c5a3f96d53d4f76fd317941a1eb839f --- .../react-native/React/CoreModules/RCTDevMenu.mm | 11 +++++++++++ .../React/CoreModules/RCTPerfMonitor.mm | 16 ++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTDevMenu.mm b/packages/react-native/React/CoreModules/RCTDevMenu.mm index 035355a038eb49..9e220790d55fa4 100644 --- a/packages/react-native/React/CoreModules/RCTDevMenu.mm +++ b/packages/react-native/React/CoreModules/RCTDevMenu.mm @@ -23,6 +23,10 @@ #import #endif +@protocol RCTDevMenuItemProvider +- (RCTDevMenuItem *)devMenuItem; +@end + NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification"; @implementation UIWindow (RCTDevMenu) @@ -302,6 +306,13 @@ - (void)setDefaultJSBundle }]]; } + id perfMonitorItemOpaque = [_moduleRegistry moduleForName:"PerfMonitor"]; + SEL devMenuItem = @selector(devMenuItem); + if ([perfMonitorItemOpaque respondsToSelector:devMenuItem]) { + RCTDevMenuItem *perfMonitorItem = [perfMonitorItemOpaque devMenuItem]; + [items addObject:perfMonitorItem]; + } + [items addObject:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString * { diff --git a/packages/react-native/React/CoreModules/RCTPerfMonitor.mm b/packages/react-native/React/CoreModules/RCTPerfMonitor.mm index a089054feb6fb0..776b5e77083a68 100644 --- a/packages/react-native/React/CoreModules/RCTPerfMonitor.mm +++ b/packages/react-native/React/CoreModules/RCTPerfMonitor.mm @@ -60,13 +60,8 @@ static vm_size_t RCTGetResidentMemorySize(void) return memoryUsageInByte; } -@interface RCTPerfMonitor : NSObject < - RCTBridgeModule, - RCTTurboModule, - RCTInitializing, - RCTInvalidating, - UITableViewDataSource, - UITableViewDelegate> +@interface RCTPerfMonitor + : NSObject #if __has_include() @property (nonatomic, strong, readonly) RCTDevMenuItem *devMenuItem; @@ -131,13 +126,6 @@ - (dispatch_queue_t)methodQueue return dispatch_get_main_queue(); } -- (void)initialize -{ -#if __has_include() - [(RCTDevMenu *)[_moduleRegistry moduleForName:"DevMenu"] addItem:self.devMenuItem]; -#endif -} - - (void)invalidate { [self hide];