-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRCTKeyCommandsManager.m
More file actions
65 lines (56 loc) · 1.98 KB
/
RCTKeyCommandsManager.m
File metadata and controls
65 lines (56 loc) · 1.98 KB
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
#import "RCTKeyCommandsManager.h"
#import "RCTKeyCommands.h"
#import "RCTLog.h"
@implementation RCTKeyCommandsManager
RCT_EXPORT_MODULE();
- (NSArray<NSString *> *)supportedEvents
{
return @[@"onKeyCommand"];
}
- (void)onKeyCommand:(UIKeyCommand *)keyCommand
{
[self sendEventWithName:@"onKeyCommand" body:@{
@"input": keyCommand.input,
@"modifierFlags": [NSNumber numberWithInteger:keyCommand.modifierFlags]
}];
}
RCT_EXPORT_METHOD(setKeyCommands:(NSArray *)json
resolve:(RCTPromiseResolveBlock)resolve
reject:(__unused RCTPromiseRejectBlock)reject) {
NSArray<NSDictionary *> *commandsArray = json;
for (NSDictionary *commandJSON in commandsArray) {
NSString *input = commandJSON[@"input"];
NSNumber *flags = commandJSON[@"modifierFlags"];
NSString *discoverabilityTitle = commandJSON[@"discoverabilityTitle"];
if (!flags) {
flags = @0;
}
dispatch_async(dispatch_get_main_queue(), ^{
[[RCTKeyCommands sharedInstance]
registerKeyCommandWithInput:input modifierFlags:[flags integerValue] action:^(__unused UIKeyCommand *command) {
[self onKeyCommand:command];
}];
});
}
resolve([NSNull null]);
}
RCT_EXPORT_METHOD(deleteKeyCommands:(NSArray *)json
resolve:(RCTPromiseResolveBlock)resolve
reject:(__unused RCTPromiseRejectBlock)reject)
{
NSArray<NSDictionary *> *commandsArray = json;
for (NSDictionary *commandJSON in commandsArray) {
NSString *input = commandJSON[@"input"];
NSNumber *flags = commandJSON[@"modifierFlags"];
if (!flags) {
flags = @0;
}
dispatch_async(dispatch_get_main_queue(), ^{
[[RCTKeyCommands sharedInstance]
unregisterKeyCommandWithInput:input
modifierFlags:[flags integerValue]];
});
}
resolve([NSNull null]);
}
@end