Skip to content

Commit 1a1a304

Browse files
Ersan Kavafoglufacebook-github-bot
Ersan Kavafoglu
authored andcommitted
Add hotkeysEnabled property to RCTDevMenu for iOS
Summary: `hotkeysEnabled` property is added to `RCTDevMenu` which allows enabling/disabling hotkeys that triggers developer menu popup Changelog: [iOS][Added] - `hotkeysEnabled` property is added to `RCTDevMenu` which allows enabling/disabling hotkeys that triggers developer menu popup Reviewed By: arhelmus Differential Revision: D35777883 fbshipit-source-id: a7435358701bedb54e33198724180eb1c27248b8
1 parent 3c2fb72 commit 1a1a304

File tree

2 files changed

+73
-25
lines changed

2 files changed

+73
-25
lines changed

React/CoreModules/RCTDevMenu.h

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
3939
*/
4040
@property (nonatomic, assign) BOOL hotLoadingEnabled DEPRECATED_ATTRIBUTE;
4141

42+
/**
43+
* Whether the hotkeys that toggles the developer menu is enabled.
44+
*/
45+
@property (nonatomic, assign) BOOL hotkeysEnabled;
46+
4247
/**
4348
* Presented items in development menu
4449
*/

React/CoreModules/RCTDevMenu.mm

+68-25
Original file line numberDiff line numberDiff line change
@@ -123,35 +123,64 @@ - (instancetype)init
123123
object:nil];
124124
_extraMenuItems = [NSMutableArray new];
125125

126+
[self registerHotkeys];
127+
}
128+
return self;
129+
}
130+
131+
- (void)registerHotkeys
132+
{
126133
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
127-
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
128-
__weak __typeof(self) weakSelf = self;
129-
130-
// Toggle debug menu
131-
[commands registerKeyCommandWithInput:@"d"
132-
modifierFlags:UIKeyModifierCommand
133-
action:^(__unused UIKeyCommand *command) {
134-
[weakSelf toggle];
135-
}];
134+
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
135+
__weak __typeof(self) weakSelf = self;
136+
137+
// Toggle debug menu
138+
[commands registerKeyCommandWithInput:@"d"
139+
modifierFlags:UIKeyModifierCommand
140+
action:^(__unused UIKeyCommand *command) {
141+
[weakSelf toggle];
142+
}];
143+
144+
// Toggle element inspector
145+
[commands registerKeyCommandWithInput:@"i"
146+
modifierFlags:UIKeyModifierCommand
147+
action:^(__unused UIKeyCommand *command) {
148+
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
149+
toggleElementInspector];
150+
}];
151+
152+
// Reload in normal mode
153+
[commands registerKeyCommandWithInput:@"n"
154+
modifierFlags:UIKeyModifierCommand
155+
action:^(__unused UIKeyCommand *command) {
156+
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
157+
setIsDebuggingRemotely:NO];
158+
}];
159+
#endif
160+
}
136161

137-
// Toggle element inspector
138-
[commands registerKeyCommandWithInput:@"i"
139-
modifierFlags:UIKeyModifierCommand
140-
action:^(__unused UIKeyCommand *command) {
141-
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
142-
toggleElementInspector];
143-
}];
162+
- (void)unregisterHotkeys
163+
{
164+
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
165+
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
144166

145-
// Reload in normal mode
146-
[commands registerKeyCommandWithInput:@"n"
147-
modifierFlags:UIKeyModifierCommand
148-
action:^(__unused UIKeyCommand *command) {
149-
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
150-
setIsDebuggingRemotely:NO];
151-
}];
167+
[commands unregisterKeyCommandWithInput:@"d" modifierFlags:UIKeyModifierCommand];
168+
[commands unregisterKeyCommandWithInput:@"i" modifierFlags:UIKeyModifierCommand];
169+
[commands unregisterKeyCommandWithInput:@"n" modifierFlags:UIKeyModifierCommand];
170+
#endif
171+
}
172+
173+
- (BOOL)isHotkeysRegistered
174+
{
175+
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
176+
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
177+
178+
return [commands isKeyCommandRegisteredForInput:@"d" modifierFlags:UIKeyModifierCommand] &&
179+
[commands isKeyCommandRegisteredForInput:@"i" modifierFlags:UIKeyModifierCommand] &&
180+
[commands isKeyCommandRegisteredForInput:@"n" modifierFlags:UIKeyModifierCommand];
181+
#else
182+
return NO;
152183
#endif
153-
}
154-
return self;
155184
}
156185

157186
- (dispatch_queue_t)methodQueue
@@ -481,6 +510,20 @@ - (BOOL)hotLoadingEnabled
481510
return ((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isHotLoadingEnabled;
482511
}
483512

513+
- (void)setHotkeysEnabled:(BOOL)enabled
514+
{
515+
if (enabled) {
516+
[self registerHotkeys];
517+
} else {
518+
[self unregisterHotkeys];
519+
}
520+
}
521+
522+
- (BOOL)hotkeysEnabled
523+
{
524+
return [self isHotkeysRegistered];
525+
}
526+
484527
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
485528
(const facebook::react::ObjCTurboModule::InitParams &)params
486529
{

0 commit comments

Comments
 (0)