-
Notifications
You must be signed in to change notification settings - Fork 2
/
RNGlobalKeyEventViewController.m
68 lines (57 loc) · 1.96 KB
/
RNGlobalKeyEventViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#import "RNGlobalKeyEventViewController.h"
#import "RNGlobalKeyEvent.h"
@implementation RNGlobalKeyEventViewController
- (void) pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
if (@available(iOS 13.4, tvOS 13.4, *)) {
} else {
[super pressesBegan:presses withEvent: event];
return;
}
RNGlobalKeyEvent *keyEvent = [RNGlobalKeyEvent getSingletonInstance];
if (keyEvent == nil || ![keyEvent isListening]) {
[super pressesBegan:presses withEvent: event];
return;
}
UIPress *press = [presses anyObject];
if (press == nil) {
[super pressesBegan:presses withEvent: event];
return;
}
UIKey *key = press.key;
[keyEvent sendKeyDown:key.characters modifierFlags:key.modifierFlags];
[super pressesBegan:presses withEvent: event];
}
- (void) pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
if (@available(iOS 13.4, tvOS 13.4, *)) {
} else {
[super pressesEnded:presses withEvent: event];
return;
}
RNGlobalKeyEvent *keyEvent = [RNGlobalKeyEvent getSingletonInstance];
if (keyEvent == nil || ![keyEvent isListening]) {
[super pressesEnded:presses withEvent: event];
return;
}
UIPress *press = [presses anyObject];
if (press == nil) {
[super pressesEnded:presses withEvent: event];
return;
}
UIKey *key = press.key;
[keyEvent sendKeyUp:key.characters modifierFlags:key.modifierFlags];
[super pressesEnded:presses withEvent: event];
}
#pragma mark - iOS < 13.4 supports
- (NSMutableArray<UIKeyCommand *> *)keyCommands {
if (@available(iOS 13.4, tvOS 13.4, *)) {
return @[];
}
RNGlobalKeyEvent *keyEvent = [RNGlobalKeyEvent getSingletonInstance];
return [keyEvent keyCommands:@selector(rnGlobalKeyInput:)];
}
- (void)rnGlobalKeyInput:(UIKeyCommand *)sender {
RNGlobalKeyEvent *keyEvent = [RNGlobalKeyEvent getSingletonInstance];
NSString *selected = sender.input;
[keyEvent sendKeyUp:selected modifierFlags:sender.modifierFlags];
}
@end