From 6f75065d8294cc21961fd39ca9fb0c975aa7a0a5 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Tue, 26 May 2020 20:14:35 -0700 Subject: [PATCH] Remove unused double key press code Summary: This was added in D3343907 June 1st 2016, disabled in D3428043 June 16, 2016 and never re-enabled. Changelog: [Internal] Reviewed By: shergin Differential Revision: D21635227 fbshipit-source-id: db51dfb6271359bea7da34b4e2a71931fc7c2a63 --- React/Base/RCTKeyCommands.h | 23 ++------ React/Base/RCTKeyCommands.m | 102 ------------------------------------ 2 files changed, 3 insertions(+), 122 deletions(-) diff --git a/React/Base/RCTKeyCommands.h b/React/Base/RCTKeyCommands.h index 983348e9989..2bdefcfab9d 100644 --- a/React/Base/RCTKeyCommands.h +++ b/React/Base/RCTKeyCommands.h @@ -12,37 +12,20 @@ + (instancetype)sharedInstance; /** - * Register a single-press keyboard command. + * Register a keyboard command. */ - (void)registerKeyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags action:(void (^)(UIKeyCommand *command))block; /** - * Unregister a single-press keyboard command. + * Unregister a keyboard command. */ - (void)unregisterKeyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags; /** - * Check if a single-press command is registered. + * Check if a command is registered. */ - (BOOL)isKeyCommandRegisteredForInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags; -/** - * Register a double-press keyboard command. - */ -- (void)registerDoublePressKeyCommandWithInput:(NSString *)input - modifierFlags:(UIKeyModifierFlags)flags - action:(void (^)(UIKeyCommand *command))block; - -/** - * Unregister a double-press keyboard command. - */ -- (void)unregisterDoublePressKeyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags; - -/** - * Check if a double-press command is registered. - */ -- (BOOL)isDoublePressKeyCommandRegisteredForInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags; - @end diff --git a/React/Base/RCTKeyCommands.m b/React/Base/RCTKeyCommands.m index d48ba935d22..974e415181e 100644 --- a/React/Base/RCTKeyCommands.m +++ b/React/Base/RCTKeyCommands.m @@ -128,54 +128,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) } } -/** - * Double Press Key Command Response - * Double KeyEvent (Double R, etc.) - */ -- (void)RCT_handleDoublePressKeyCommand:(UIKeyCommand *)key -{ - static BOOL firstPress = YES; - static NSTimeInterval lastCommand = 0; - static NSTimeInterval lastDoubleCommand = 0; - static NSString *lastInput = nil; - static UIKeyModifierFlags lastModifierFlags = 0; - - if (firstPress) { - for (RCTKeyCommand *command in [RCTKeyCommands sharedInstance].commands) { - if ([command.keyCommand.input isEqualToString:key.input] && - command.keyCommand.modifierFlags == key.modifierFlags && command.block) { - firstPress = NO; - lastCommand = CACurrentMediaTime(); - lastInput = key.input; - lastModifierFlags = key.modifierFlags; - return; - } - } - } else { - // Second keyevent within 0.2 second, - // with the same key as the first one. - if (CACurrentMediaTime() - lastCommand < 0.2 && lastInput == key.input && lastModifierFlags == key.modifierFlags) { - for (RCTKeyCommand *command in [RCTKeyCommands sharedInstance].commands) { - if ([command.keyCommand.input isEqualToString:key.input] && - command.keyCommand.modifierFlags == key.modifierFlags && command.block) { - // NOTE: throttle the key handler because on iOS 9 the handleKeyCommand: - // method gets called repeatedly if the command key is held down. - if (CACurrentMediaTime() - lastDoubleCommand > 0.5) { - command.block(key); - lastDoubleCommand = CACurrentMediaTime(); - } - firstPress = YES; - return; - } - } - } - - lastCommand = CACurrentMediaTime(); - lastInput = key.input; - lastModifierFlags = key.modifierFlags; - } -} - @end @implementation RCTKeyCommands @@ -244,45 +196,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) return NO; } -- (void)registerDoublePressKeyCommandWithInput:(NSString *)input - modifierFlags:(UIKeyModifierFlags)flags - action:(void (^)(UIKeyCommand *))block -{ - RCTAssertMainQueue(); - - UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:input - modifierFlags:flags - action:@selector(RCT_handleDoublePressKeyCommand:)]; - - RCTKeyCommand *keyCommand = [[RCTKeyCommand alloc] initWithKeyCommand:command block:block]; - [_commands removeObject:keyCommand]; - [_commands addObject:keyCommand]; -} - -- (void)unregisterDoublePressKeyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags -{ - RCTAssertMainQueue(); - - for (RCTKeyCommand *command in _commands.allObjects) { - if ([command matchesInput:input flags:flags]) { - [_commands removeObject:command]; - break; - } - } -} - -- (BOOL)isDoublePressKeyCommandRegisteredForInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags -{ - RCTAssertMainQueue(); - - for (RCTKeyCommand *command in _commands) { - if ([command matchesInput:input flags:flags]) { - return YES; - } - } - return NO; -} - @end #else @@ -309,21 +222,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) return NO; } -- (void)registerDoublePressKeyCommandWithInput:(NSString *)input - modifierFlags:(UIKeyModifierFlags)flags - action:(void (^)(UIKeyCommand *))block -{ -} - -- (void)unregisterDoublePressKeyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags -{ -} - -- (BOOL)isDoublePressKeyCommandRegisteredForInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags -{ - return NO; -} - @end #endif