Skip to content

Commit

Permalink
fix: PerfMonitor option not showing on iOS (Bridgeless) (#42891)
Browse files Browse the repository at this point in the history
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: #42891

Test Plan: Run RNTester, open Perf monitor

Reviewed By: RSNara

Differential Revision: D53518507

Pulled By: cipolleschi

fbshipit-source-id: c16d41006c5a3f96d53d4f76fd317941a1eb839f
  • Loading branch information
okwasniewski authored and facebook-github-bot committed Feb 15, 2024
1 parent 24f7bd7 commit 2091400
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
11 changes: 11 additions & 0 deletions packages/react-native/React/CoreModules/RCTDevMenu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#import <React/RCTInspectorDevServerHelper.h>
#endif

@protocol RCTDevMenuItemProvider
- (RCTDevMenuItem *)devMenuItem;
@end

NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification";

@implementation UIWindow (RCTDevMenu)
Expand Down Expand Up @@ -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 * {
Expand Down
16 changes: 2 additions & 14 deletions packages/react-native/React/CoreModules/RCTPerfMonitor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,8 @@ static vm_size_t RCTGetResidentMemorySize(void)
return memoryUsageInByte;
}

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

#if __has_include(<React/RCTDevMenu.h>)
@property (nonatomic, strong, readonly) RCTDevMenuItem *devMenuItem;
Expand Down Expand Up @@ -131,13 +126,6 @@ - (dispatch_queue_t)methodQueue
return dispatch_get_main_queue();
}

- (void)initialize
{
#if __has_include(<React/RCTDevMenu.h>)
[(RCTDevMenu *)[_moduleRegistry moduleForName:"DevMenu"] addItem:self.devMenuItem];
#endif
}

- (void)invalidate
{
[self hide];
Expand Down

0 comments on commit 2091400

Please sign in to comment.