@@ -123,35 +123,64 @@ - (instancetype)init
123
123
object: nil ];
124
124
_extraMenuItems = [NSMutableArray new ];
125
125
126
+ [self registerHotkeys ];
127
+ }
128
+ return self;
129
+ }
130
+
131
+ - (void )registerHotkeys
132
+ {
126
133
#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
+ }
136
161
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 ];
144
166
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 ;
152
183
#endif
153
- }
154
- return self;
155
184
}
156
185
157
186
- (dispatch_queue_t )methodQueue
@@ -481,6 +510,20 @@ - (BOOL)hotLoadingEnabled
481
510
return ((RCTDevSettings *)[_moduleRegistry moduleForName: " DevSettings" ]).isHotLoadingEnabled ;
482
511
}
483
512
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
+
484
527
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
485
528
(const facebook::react::ObjCTurboModule::InitParams &)params
486
529
{
0 commit comments