Skip to content

Commit 2b50adc

Browse files
committed
unregister reload command, fix isHotkeysRegistered
1 parent f743b3c commit 2b50adc

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

packages/react-native/React/Base/RCTDevMenuConfigurationDecorator.mm

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ - (instancetype)initWithDevMenuConfiguration:(RCTDevMenuConfiguration *)devMenuC
1515
if (self = [super init]) {
1616
_devMenuConfiguration = devMenuConfiguration;
1717
}
18-
18+
1919
return self;
2020
}
2121

@@ -24,9 +24,16 @@ - (void)decorate:(id<RCTBridgeModule>)bridgeModule
2424
if ([bridgeModule isKindOfClass:[RCTDevMenu class]]) {
2525
RCTDevMenu *devMenu = (RCTDevMenu *)bridgeModule;
2626
devMenu.isDevMenuEnabled = _devMenuConfiguration.isDevMenuEnabled;
27-
[devMenu setHotkeysEnabled:_devMenuConfiguration.areKeyboardShortcutsEnabled];
27+
28+
if (_devMenuConfiguration.areKeyboardShortcutsEnabled == false) {
29+
if ([devMenu hotkeysEnabled]) {
30+
[devMenu setHotkeysEnabled:_devMenuConfiguration.areKeyboardShortcutsEnabled];
31+
}
32+
33+
[devMenu disableReloadCommand];
34+
}
2835
}
29-
36+
3037
if ([bridgeModule isKindOfClass:[RCTDevSettings class]]) {
3138
RCTDevSettings *devSettings = (RCTDevSettings *)bridgeModule;
3239
[devSettings setIsShakeToShowDevMenuEnabled:_devMenuConfiguration.isShakeGestureEnabled];

packages/react-native/React/CoreModules/RCTDevMenu.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
2525
@property (nonatomic, readonly) BOOL isShakeGestureEnabled;
2626
@property (nonatomic, readonly) BOOL areKeyboardShortcutsEnabled;
2727

28-
- (instancetype)initWithDevMenuEnabled:(BOOL) isDevMenuEnabled
29-
shakeGestureEnabled:(BOOL) isShakeGestureEnabled
30-
keyboardShortcutsEnabled:(BOOL) areKeyboardShortcutsEnabled;
28+
- (instancetype)initWithDevMenuEnabled:(BOOL)isDevMenuEnabled
29+
shakeGestureEnabled:(BOOL)isShakeGestureEnabled
30+
keyboardShortcutsEnabled:(BOOL)areKeyboardShortcutsEnabled;
3131
@end
3232

3333
/**
@@ -88,6 +88,11 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
8888
*/
8989
- (void)addItem:(RCTDevMenuItem *)item;
9090

91+
/**
92+
* Disable the reload command (Cmd+R) in the simulator.
93+
*/
94+
- (void)disableReloadCommand;
95+
9196
@end
9297

9398
typedef NSString * (^RCTDevMenuItemTitleBlock)(void);

packages/react-native/React/CoreModules/RCTDevMenu.mm

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ - (void)unregisterHotkeys
180180

181181
[commands unregisterKeyCommandWithInput:@"d" modifierFlags:UIKeyModifierCommand];
182182
[commands unregisterKeyCommandWithInput:@"i" modifierFlags:UIKeyModifierCommand];
183-
[commands unregisterKeyCommandWithInput:@"n" modifierFlags:UIKeyModifierCommand];
184183
#endif
185184
}
186185

@@ -190,13 +189,30 @@ - (BOOL)isHotkeysRegistered
190189
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
191190

192191
return [commands isKeyCommandRegisteredForInput:@"d" modifierFlags:UIKeyModifierCommand] &&
193-
[commands isKeyCommandRegisteredForInput:@"i" modifierFlags:UIKeyModifierCommand] &&
194-
[commands isKeyCommandRegisteredForInput:@"n" modifierFlags:UIKeyModifierCommand];
192+
[commands isKeyCommandRegisteredForInput:@"i" modifierFlags:UIKeyModifierCommand];
195193
#else
196194
return NO;
197195
#endif
198196
}
199197

198+
- (BOOL)isReloadCommandRegistered
199+
{
200+
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
201+
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
202+
return [commands isKeyCommandRegisteredForInput:@"r" modifierFlags:UIKeyModifierCommand];
203+
#else
204+
return NO;
205+
#endif
206+
}
207+
208+
- (void)unregisterReloadCommand
209+
{
210+
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
211+
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
212+
[commands unregisterKeyCommandWithInput:@"r" modifierFlags:UIKeyModifierCommand];
213+
#endif
214+
}
215+
200216
- (dispatch_queue_t)methodQueue
201217
{
202218
return dispatch_get_main_queue();
@@ -496,6 +512,13 @@ - (BOOL)hotkeysEnabled
496512
return [self isHotkeysRegistered];
497513
}
498514

515+
- (void)disableReloadCommand
516+
{
517+
if ([self isReloadCommandRegistered]) {
518+
[self unregisterReloadCommand];
519+
}
520+
}
521+
499522
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
500523
(const facebook::react::ObjCTurboModule::InitParams &)params
501524
{

0 commit comments

Comments
 (0)