forked from AmazonAppDev/react-native-multi-tv-app-sample
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwithKeyEvent.js
More file actions
68 lines (64 loc) Β· 1.96 KB
/
Copy pathwithKeyEvent.js
File metadata and controls
68 lines (64 loc) Β· 1.96 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
66
67
68
const { withMainActivity } = require("expo/config-plugins");
const {
mergeContents,
} = require("@expo/config-plugins/build/utils/generateCode");
const withAndroidMainActivityImport = (config) => {
return withMainActivity(config, (config) => {
const newSrc = [
"import android.view.KeyEvent",
"import com.github.kevinejohn.keyevent.KeyEventModule",
];
const newConfig = mergeContents({
tag: "react-native-keyevent-import",
src: config.modResults.contents,
newSrc: newSrc.join("\n"),
anchor: `import`,
offset: 1,
comment: "//",
});
return {
...config,
modResults: newConfig,
};
});
};
const withAndroidMainActivityBody = (config) => {
return withMainActivity(config, (config) => {
const newSrc = [
"override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {",
" KeyEventModule.getInstance().onKeyDownEvent(keyCode, event)",
" super.onKeyDown(keyCode, event)",
" return true",
"}",
"",
"override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {",
" KeyEventModule.getInstance().onKeyUpEvent(keyCode, event)",
" super.onKeyUp(keyCode, event)",
" return true",
"}",
"",
"override fun onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent): Boolean {",
" KeyEventModule.getInstance().onKeyMultipleEvent(keyCode, repeatCount, event)",
" return super.onKeyMultiple(keyCode, repeatCount, event)",
"}",
];
const newConfig = mergeContents({
tag: "react-native-keyevent-body",
src: config.modResults.contents,
newSrc: newSrc.join("\n"),
anchor: `class MainActivity`,
offset: 1,
comment: "//",
});
return {
...config,
modResults: newConfig,
};
});
};
function withKeyEvent(config) {
config = withAndroidMainActivityImport(config);
config = withAndroidMainActivityBody(config);
return config;
}
module.exports = withKeyEvent;