-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathExternalInputModule.m
More file actions
62 lines (52 loc) · 1.73 KB
/
Copy pathExternalInputModule.m
File metadata and controls
62 lines (52 loc) · 1.73 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
#import "ExternalInputModule.h"
#import <GameController/GameController.h>
#import <stdarg.h>
@implementation ExternalInputModule
{
BOOL _hasExternalKeyboard;
BOOL _hasInitializedKeyboardState;
}
RCT_EXPORT_MODULE(ExternalInput);
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (instancetype)init
{
self = [super init];
if (self) {
GCKeyboard *coalescedKeyboard = [GCKeyboard coalescedKeyboard];
_hasExternalKeyboard = coalescedKeyboard != nil;
_hasInitializedKeyboardState = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleKeyboardDidConnect:)
name:GCKeyboardDidConnectNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleKeyboardDidDisconnect:)
name:GCKeyboardDidDisconnectNotification
object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)handleKeyboardDidConnect:(NSNotification *)notification
{
_hasExternalKeyboard = YES;
_hasInitializedKeyboardState = YES;
}
- (void)handleKeyboardDidDisconnect:(NSNotification *)notification
{
_hasExternalKeyboard = NO;
_hasInitializedKeyboardState = YES;
}
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isExternalKeyboardConnected)
{
BOOL fallbackFromCoalesced = [GCKeyboard coalescedKeyboard] != nil;
BOOL hasExternalKeyboard = _hasInitializedKeyboardState ? _hasExternalKeyboard : fallbackFromCoalesced;
return @(hasExternalKeyboard);
}
@end