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
This commit is contained in:
Родитель
3c2fb72541
Коммит
1a1a304ed2
|
@ -39,6 +39,11 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
|
|||
*/
|
||||
@property (nonatomic, assign) BOOL hotLoadingEnabled DEPRECATED_ATTRIBUTE;
|
||||
|
||||
/**
|
||||
* Whether the hotkeys that toggles the developer menu is enabled.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL hotkeysEnabled;
|
||||
|
||||
/**
|
||||
* Presented items in development menu
|
||||
*/
|
||||
|
|
|
@ -123,37 +123,66 @@ RCT_EXPORT_MODULE()
|
|||
object:nil];
|
||||
_extraMenuItems = [NSMutableArray new];
|
||||
|
||||
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
|
||||
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
|
||||
// Toggle debug menu
|
||||
[commands registerKeyCommandWithInput:@"d"
|
||||
modifierFlags:UIKeyModifierCommand
|
||||
action:^(__unused UIKeyCommand *command) {
|
||||
[weakSelf toggle];
|
||||
}];
|
||||
|
||||
// Toggle element inspector
|
||||
[commands registerKeyCommandWithInput:@"i"
|
||||
modifierFlags:UIKeyModifierCommand
|
||||
action:^(__unused UIKeyCommand *command) {
|
||||
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
|
||||
toggleElementInspector];
|
||||
}];
|
||||
|
||||
// Reload in normal mode
|
||||
[commands registerKeyCommandWithInput:@"n"
|
||||
modifierFlags:UIKeyModifierCommand
|
||||
action:^(__unused UIKeyCommand *command) {
|
||||
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
|
||||
setIsDebuggingRemotely:NO];
|
||||
}];
|
||||
#endif
|
||||
[self registerHotkeys];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)registerHotkeys
|
||||
{
|
||||
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
|
||||
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
|
||||
// Toggle debug menu
|
||||
[commands registerKeyCommandWithInput:@"d"
|
||||
modifierFlags:UIKeyModifierCommand
|
||||
action:^(__unused UIKeyCommand *command) {
|
||||
[weakSelf toggle];
|
||||
}];
|
||||
|
||||
// Toggle element inspector
|
||||
[commands registerKeyCommandWithInput:@"i"
|
||||
modifierFlags:UIKeyModifierCommand
|
||||
action:^(__unused UIKeyCommand *command) {
|
||||
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
|
||||
toggleElementInspector];
|
||||
}];
|
||||
|
||||
// Reload in normal mode
|
||||
[commands registerKeyCommandWithInput:@"n"
|
||||
modifierFlags:UIKeyModifierCommand
|
||||
action:^(__unused UIKeyCommand *command) {
|
||||
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
|
||||
setIsDebuggingRemotely:NO];
|
||||
}];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)unregisterHotkeys
|
||||
{
|
||||
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
|
||||
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
|
||||
|
||||
[commands unregisterKeyCommandWithInput:@"d" modifierFlags:UIKeyModifierCommand];
|
||||
[commands unregisterKeyCommandWithInput:@"i" modifierFlags:UIKeyModifierCommand];
|
||||
[commands unregisterKeyCommandWithInput:@"n" modifierFlags:UIKeyModifierCommand];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (BOOL)isHotkeysRegistered
|
||||
{
|
||||
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
|
||||
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
|
||||
|
||||
return [commands isKeyCommandRegisteredForInput:@"d" modifierFlags:UIKeyModifierCommand] &&
|
||||
[commands isKeyCommandRegisteredForInput:@"i" modifierFlags:UIKeyModifierCommand] &&
|
||||
[commands isKeyCommandRegisteredForInput:@"n" modifierFlags:UIKeyModifierCommand];
|
||||
#else
|
||||
return NO;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (dispatch_queue_t)methodQueue
|
||||
{
|
||||
return dispatch_get_main_queue();
|
||||
|
@ -481,6 +510,20 @@ RCT_EXPORT_METHOD(setHotLoadingEnabled : (BOOL)enabled)
|
|||
return ((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isHotLoadingEnabled;
|
||||
}
|
||||
|
||||
- (void)setHotkeysEnabled:(BOOL)enabled
|
||||
{
|
||||
if (enabled) {
|
||||
[self registerHotkeys];
|
||||
} else {
|
||||
[self unregisterHotkeys];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)hotkeysEnabled
|
||||
{
|
||||
return [self isHotkeysRegistered];
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
||||
(const facebook::react::ObjCTurboModule::InitParams &)params
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче