139 lines
5.0 KiB
Diff
139 lines
5.0 KiB
Diff
diff --git a/node_modules/react-native/React/Base/RCTKeyCommands.h b/node_modules/react-native/React/Base/RCTKeyCommands.h
|
|
index 983348e..95742f4 100644
|
|
--- a/node_modules/react-native/React/Base/RCTKeyCommands.h
|
|
+++ b/node_modules/react-native/React/Base/RCTKeyCommands.h
|
|
@@ -18,6 +18,12 @@
|
|
modifierFlags:(UIKeyModifierFlags)flags
|
|
action:(void (^)(UIKeyCommand *command))block;
|
|
|
|
+- (void)registerKeyCommand:(NSString *)input
|
|
+ modifierFlags:(UIKeyModifierFlags)flags
|
|
+ discoverabilityTitle:(NSString *)discoverabilityTitle
|
|
+ action:(void (^)(UIKeyCommand *))block;
|
|
+
|
|
+
|
|
/**
|
|
* Unregister a single-press keyboard command.
|
|
*/
|
|
diff --git a/node_modules/react-native/React/Base/RCTKeyCommands.m b/node_modules/react-native/React/Base/RCTKeyCommands.m
|
|
index d48ba93..387d551 100644
|
|
--- a/node_modules/react-native/React/Base/RCTKeyCommands.m
|
|
+++ b/node_modules/react-native/React/Base/RCTKeyCommands.m
|
|
@@ -12,8 +12,6 @@
|
|
#import "RCTDefines.h"
|
|
#import "RCTUtils.h"
|
|
|
|
-#if RCT_DEV
|
|
-
|
|
@interface RCTKeyCommand : NSObject <NSCopying>
|
|
|
|
@property (nonatomic, strong) UIKeyCommand *keyCommand;
|
|
@@ -115,7 +113,9 @@ - (void)RCT_handleKeyCommand:(UIKeyCommand *)key
|
|
// NOTE: throttle the key handler because on iOS 9 the handleKeyCommand:
|
|
// method gets called repeatedly if the command key is held down.
|
|
static NSTimeInterval lastCommand = 0;
|
|
- if (CACurrentMediaTime() - lastCommand > 0.5) {
|
|
+ if (CACurrentMediaTime() - lastCommand > 0.5 ||
|
|
+ [key.input isEqualToString:@"UIKeyInputUpArrow"] || // repeat command if is scroll
|
|
+ [key.input isEqualToString:@"UIKeyInputDownArrow"]) {
|
|
for (RCTKeyCommand *command in [RCTKeyCommands sharedInstance].commands) {
|
|
if ([command.keyCommand.input isEqualToString:key.input] &&
|
|
command.keyCommand.modifierFlags == key.modifierFlags) {
|
|
@@ -178,6 +178,8 @@ - (void)RCT_handleDoublePressKeyCommand:(UIKeyCommand *)key
|
|
|
|
@end
|
|
|
|
+#if RCT_DEV
|
|
+
|
|
@implementation RCTKeyCommands
|
|
|
|
+ (void)initialize
|
|
@@ -220,6 +222,23 @@ - (void)registerKeyCommandWithInput:(NSString *)input
|
|
[_commands addObject:keyCommand];
|
|
}
|
|
|
|
+- (void)registerKeyCommand:(NSString *)input
|
|
+ modifierFlags:(UIKeyModifierFlags)flags
|
|
+ discoverabilityTitle:(NSString *)discoverabilityTitle
|
|
+ action:(void (^)(UIKeyCommand *))block
|
|
+{
|
|
+ RCTAssertMainQueue();
|
|
+
|
|
+ UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:input
|
|
+ modifierFlags:flags
|
|
+ action:@selector(RCT_handleKeyCommand:)
|
|
+ discoverabilityTitle:discoverabilityTitle];
|
|
+
|
|
+ RCTKeyCommand *keyCommand = [[RCTKeyCommand alloc] initWithKeyCommand:command block:block];
|
|
+ [_commands removeObject:keyCommand];
|
|
+ [_commands addObject:keyCommand];
|
|
+}
|
|
+
|
|
- (void)unregisterKeyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags
|
|
{
|
|
RCTAssertMainQueue();
|
|
@@ -289,9 +308,48 @@ - (BOOL)isDoublePressKeyCommandRegisteredForInput:(NSString *)input modifierFlag
|
|
|
|
@implementation RCTKeyCommands
|
|
|
|
++ (void)initialize
|
|
+{
|
|
+ // swizzle UIResponder
|
|
+ RCTSwapInstanceMethods([UIResponder class],
|
|
+ @selector(keyCommands),
|
|
+ @selector(RCT_keyCommands));
|
|
+}
|
|
+
|
|
+ (instancetype)sharedInstance
|
|
{
|
|
- return nil;
|
|
+ static RCTKeyCommands *sharedInstance;
|
|
+ static dispatch_once_t onceToken;
|
|
+ dispatch_once(&onceToken, ^{
|
|
+ sharedInstance = [self new];
|
|
+ });
|
|
+
|
|
+ return sharedInstance;
|
|
+}
|
|
+
|
|
+- (instancetype)init
|
|
+{
|
|
+ if ((self = [super init])) {
|
|
+ _commands = [NSMutableSet new];
|
|
+ }
|
|
+ return self;
|
|
+}
|
|
+
|
|
+- (void)registerKeyCommand:(NSString *)input
|
|
+ modifierFlags:(UIKeyModifierFlags)flags
|
|
+ discoverabilityTitle:(NSString *)discoverabilityTitle
|
|
+ action:(void (^)(UIKeyCommand *))block
|
|
+{
|
|
+ RCTAssertMainQueue();
|
|
+
|
|
+ UIKeyCommand *command = [UIKeyCommand keyCommandWithInput:input
|
|
+ modifierFlags:flags
|
|
+ action:@selector(RCT_handleKeyCommand:)
|
|
+ discoverabilityTitle:discoverabilityTitle];
|
|
+
|
|
+ RCTKeyCommand *keyCommand = [[RCTKeyCommand alloc] initWithKeyCommand:command block:block];
|
|
+ [_commands removeObject:keyCommand];
|
|
+ [_commands addObject:keyCommand];
|
|
}
|
|
|
|
- (void)registerKeyCommandWithInput:(NSString *)input
|
|
@@ -302,6 +360,13 @@ - (void)registerKeyCommandWithInput:(NSString *)input
|
|
|
|
- (void)unregisterKeyCommandWithInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags
|
|
{
|
|
+ RCTAssertMainQueue();
|
|
+ for (RCTKeyCommand *command in _commands.allObjects) {
|
|
+ if ([command matchesInput:input flags:flags]) {
|
|
+ [_commands removeObject:command];
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
}
|
|
|
|
- (BOOL)isKeyCommandRegisteredForInput:(NSString *)input modifierFlags:(UIKeyModifierFlags)flags
|