react-native-external-keyboard 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +113 -0
  3. package/android/Android.mk +45 -0
  4. package/android/build.gradle +139 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/registration.cpp +18 -0
  7. package/android/src/main/AndroidManifest.xml +4 -0
  8. package/android/src/main/java/com/externalkeyboard/A11yKeyboardModule.java +46 -0
  9. package/android/src/main/java/com/externalkeyboard/ExternalKeyboardViewPackage.java +63 -0
  10. package/android/src/main/java/com/externalkeyboard/events/FocusChangeEvent.java +39 -0
  11. package/android/src/main/java/com/externalkeyboard/events/KeyPressDownEvent.java +49 -0
  12. package/android/src/main/java/com/externalkeyboard/events/KeyPressUpEvent.java +49 -0
  13. package/android/src/main/java/com/externalkeyboard/services/KeyboardKeyPressHandler.java +56 -0
  14. package/android/src/main/java/com/externalkeyboard/services/KeyboardService.java +52 -0
  15. package/android/src/main/java/com/externalkeyboard/views/ExternalKeyboardView/ExternalKeyboardView.java +28 -0
  16. package/android/src/main/java/com/externalkeyboard/views/ExternalKeyboardView/ExternalKeyboardViewManager.java +101 -0
  17. package/android/src/newarch/A11yKeyboardModuleSpec.java +9 -0
  18. package/android/src/newarch/ExternalKeyboardViewManagerSpec.java +31 -0
  19. package/android/src/oldarch/A11yKeyboardModuleSpec.java +15 -0
  20. package/android/src/oldarch/ExternalKeyboardViewManagerSpec.java +9 -0
  21. package/ios/ExternalKeyboard.xcodeproj/project.pbxproj +384 -0
  22. package/ios/ExternalKeyboard.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  23. package/ios/ExternalKeyboard.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  24. package/ios/ExternalKeyboard.xcodeproj/project.xcworkspace/xcuserdata/Artur_Kalach.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  25. package/ios/ExternalKeyboard.xcodeproj/xcuserdata/Artur_Kalach.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +24 -0
  26. package/ios/ExternalKeyboard.xcodeproj/xcuserdata/Artur_Kalach.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  27. package/ios/ExternalKeyboardView/ExternalKeyboardView.h +41 -0
  28. package/ios/ExternalKeyboardView/ExternalKeyboardView.mm +186 -0
  29. package/ios/Helpers/FocusWrapper/FocusWrapper.h +32 -0
  30. package/ios/Helpers/FocusWrapper/FocusWrapper.mm +63 -0
  31. package/ios/Helpers/KeyboardKeyPressHandler/KeyboardKeyPressHandler.h +27 -0
  32. package/ios/Helpers/KeyboardKeyPressHandler/KeyboardKeyPressHandler.mm +73 -0
  33. package/ios/Modules/A11yKeyboardModule/A11yKeyboardModule.h +20 -0
  34. package/ios/Modules/A11yKeyboardModule/A11yKeyboardModule.mm +86 -0
  35. package/ios/ViewManagers/ExternalKeyboardViewManager/ExternalKeyboardViewManager.h +16 -0
  36. package/ios/ViewManagers/ExternalKeyboardViewManager/ExternalKeyboardViewManager.mm +29 -0
  37. package/lib/commonjs/NativeModules/A11yKeyboardModule/A11yKeyboardModule.js +33 -0
  38. package/lib/commonjs/NativeModules/A11yKeyboardModule/A11yKeyboardModule.js.map +1 -0
  39. package/lib/commonjs/NativeModules/A11yKeyboardModule/index.js +13 -0
  40. package/lib/commonjs/NativeModules/A11yKeyboardModule/index.js.map +1 -0
  41. package/lib/commonjs/NativeModules/index.js +13 -0
  42. package/lib/commonjs/NativeModules/index.js.map +1 -0
  43. package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.android.js +41 -0
  44. package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.android.js.map +1 -0
  45. package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.d.js +6 -0
  46. package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.d.js.map +1 -0
  47. package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.ios.js +46 -0
  48. package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.ios.js.map +1 -0
  49. package/lib/commonjs/components/KeyboardFocusView/hooks/index.js +13 -0
  50. package/lib/commonjs/components/KeyboardFocusView/hooks/index.js.map +1 -0
  51. package/lib/commonjs/components/KeyboardFocusView/hooks/useFocusStyle/index.js +13 -0
  52. package/lib/commonjs/components/KeyboardFocusView/hooks/useFocusStyle/index.js.map +1 -0
  53. package/lib/commonjs/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.js +33 -0
  54. package/lib/commonjs/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.js.map +1 -0
  55. package/lib/commonjs/components/KeyboardFocusView/index.js +13 -0
  56. package/lib/commonjs/components/KeyboardFocusView/index.js.map +1 -0
  57. package/lib/commonjs/components/Pressable/Pressable.android.js +76 -0
  58. package/lib/commonjs/components/Pressable/Pressable.android.js.map +1 -0
  59. package/lib/commonjs/components/Pressable/Pressable.d.js +6 -0
  60. package/lib/commonjs/components/Pressable/Pressable.d.js.map +1 -0
  61. package/lib/commonjs/components/Pressable/Pressable.ios.js +157 -0
  62. package/lib/commonjs/components/Pressable/Pressable.ios.js.map +1 -0
  63. package/lib/commonjs/components/Pressable/index.js +13 -0
  64. package/lib/commonjs/components/Pressable/index.js.map +1 -0
  65. package/lib/commonjs/components/index.js +20 -0
  66. package/lib/commonjs/components/index.js.map +1 -0
  67. package/lib/commonjs/index.js +46 -0
  68. package/lib/commonjs/index.js.map +1 -0
  69. package/lib/commonjs/nativeSpec/ExternalKeyboardViewNativeComponent.js +11 -0
  70. package/lib/commonjs/nativeSpec/ExternalKeyboardViewNativeComponent.js.map +1 -0
  71. package/lib/commonjs/nativeSpec/NativeKeyboardModule.js +10 -0
  72. package/lib/commonjs/nativeSpec/NativeKeyboardModule.js.map +1 -0
  73. package/lib/commonjs/nativeSpec/index.js +21 -0
  74. package/lib/commonjs/nativeSpec/index.js.map +1 -0
  75. package/lib/commonjs/services/A11yModule/A11yModule.android.js +22 -0
  76. package/lib/commonjs/services/A11yModule/A11yModule.android.js.map +1 -0
  77. package/lib/commonjs/services/A11yModule/A11yModule.d.js +6 -0
  78. package/lib/commonjs/services/A11yModule/A11yModule.d.js.map +1 -0
  79. package/lib/commonjs/services/A11yModule/A11yModule.ios.js +28 -0
  80. package/lib/commonjs/services/A11yModule/A11yModule.ios.js.map +1 -0
  81. package/lib/commonjs/services/A11yModule/A11yModule.types.js +6 -0
  82. package/lib/commonjs/services/A11yModule/A11yModule.types.js.map +1 -0
  83. package/lib/commonjs/services/A11yModule/index.js +13 -0
  84. package/lib/commonjs/services/A11yModule/index.js.map +1 -0
  85. package/lib/commonjs/services/index.js +13 -0
  86. package/lib/commonjs/services/index.js.map +1 -0
  87. package/lib/commonjs/types/FocusStyle.js +6 -0
  88. package/lib/commonjs/types/FocusStyle.js.map +1 -0
  89. package/lib/commonjs/types/KeyboardFocusView.types.js +6 -0
  90. package/lib/commonjs/types/KeyboardFocusView.types.js.map +1 -0
  91. package/lib/commonjs/types/index.js +38 -0
  92. package/lib/commonjs/types/index.js.map +1 -0
  93. package/lib/module/NativeModules/A11yKeyboardModule/A11yKeyboardModule.js +26 -0
  94. package/lib/module/NativeModules/A11yKeyboardModule/A11yKeyboardModule.js.map +1 -0
  95. package/lib/module/NativeModules/A11yKeyboardModule/index.js +2 -0
  96. package/lib/module/NativeModules/A11yKeyboardModule/index.js.map +1 -0
  97. package/lib/module/NativeModules/index.js +2 -0
  98. package/lib/module/NativeModules/index.js.map +1 -0
  99. package/lib/module/components/KeyboardFocusView/KeyboardFocusView.android.js +33 -0
  100. package/lib/module/components/KeyboardFocusView/KeyboardFocusView.android.js.map +1 -0
  101. package/lib/module/components/KeyboardFocusView/KeyboardFocusView.d.js +2 -0
  102. package/lib/module/components/KeyboardFocusView/KeyboardFocusView.d.js.map +1 -0
  103. package/lib/module/components/KeyboardFocusView/KeyboardFocusView.ios.js +37 -0
  104. package/lib/module/components/KeyboardFocusView/KeyboardFocusView.ios.js.map +1 -0
  105. package/lib/module/components/KeyboardFocusView/hooks/index.js +2 -0
  106. package/lib/module/components/KeyboardFocusView/hooks/index.js.map +1 -0
  107. package/lib/module/components/KeyboardFocusView/hooks/useFocusStyle/index.js +2 -0
  108. package/lib/module/components/KeyboardFocusView/hooks/useFocusStyle/index.js.map +1 -0
  109. package/lib/module/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.js +26 -0
  110. package/lib/module/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.js.map +1 -0
  111. package/lib/module/components/KeyboardFocusView/index.js +2 -0
  112. package/lib/module/components/KeyboardFocusView/index.js.map +1 -0
  113. package/lib/module/components/Pressable/Pressable.android.js +70 -0
  114. package/lib/module/components/Pressable/Pressable.android.js.map +1 -0
  115. package/lib/module/components/Pressable/Pressable.d.js +2 -0
  116. package/lib/module/components/Pressable/Pressable.d.js.map +1 -0
  117. package/lib/module/components/Pressable/Pressable.ios.js +148 -0
  118. package/lib/module/components/Pressable/Pressable.ios.js.map +1 -0
  119. package/lib/module/components/Pressable/index.js +2 -0
  120. package/lib/module/components/Pressable/index.js.map +1 -0
  121. package/lib/module/components/index.js +3 -0
  122. package/lib/module/components/index.js.map +1 -0
  123. package/lib/module/index.js +5 -0
  124. package/lib/module/index.js.map +1 -0
  125. package/lib/module/nativeSpec/ExternalKeyboardViewNativeComponent.js +3 -0
  126. package/lib/module/nativeSpec/ExternalKeyboardViewNativeComponent.js.map +1 -0
  127. package/lib/module/nativeSpec/NativeKeyboardModule.js +3 -0
  128. package/lib/module/nativeSpec/NativeKeyboardModule.js.map +1 -0
  129. package/lib/module/nativeSpec/index.js +4 -0
  130. package/lib/module/nativeSpec/index.js.map +1 -0
  131. package/lib/module/services/A11yModule/A11yModule.android.js +15 -0
  132. package/lib/module/services/A11yModule/A11yModule.android.js.map +1 -0
  133. package/lib/module/services/A11yModule/A11yModule.d.js +2 -0
  134. package/lib/module/services/A11yModule/A11yModule.d.js.map +1 -0
  135. package/lib/module/services/A11yModule/A11yModule.ios.js +21 -0
  136. package/lib/module/services/A11yModule/A11yModule.ios.js.map +1 -0
  137. package/lib/module/services/A11yModule/A11yModule.types.js +2 -0
  138. package/lib/module/services/A11yModule/A11yModule.types.js.map +1 -0
  139. package/lib/module/services/A11yModule/index.js +2 -0
  140. package/lib/module/services/A11yModule/index.js.map +1 -0
  141. package/lib/module/services/index.js +2 -0
  142. package/lib/module/services/index.js.map +1 -0
  143. package/lib/module/types/FocusStyle.js +2 -0
  144. package/lib/module/types/FocusStyle.js.map +1 -0
  145. package/lib/module/types/KeyboardFocusView.types.js +2 -0
  146. package/lib/module/types/KeyboardFocusView.types.js.map +1 -0
  147. package/lib/module/types/index.js +3 -0
  148. package/lib/module/types/index.js.map +1 -0
  149. package/lib/typescript/NativeModules/A11yKeyboardModule/A11yKeyboardModule.d.ts +5 -0
  150. package/lib/typescript/NativeModules/A11yKeyboardModule/A11yKeyboardModule.d.ts.map +1 -0
  151. package/lib/typescript/NativeModules/A11yKeyboardModule/index.d.ts +2 -0
  152. package/lib/typescript/NativeModules/A11yKeyboardModule/index.d.ts.map +1 -0
  153. package/lib/typescript/NativeModules/index.d.ts +2 -0
  154. package/lib/typescript/NativeModules/index.d.ts.map +1 -0
  155. package/lib/typescript/components/KeyboardFocusView/KeyboardFocusView.android.d.ts +14 -0
  156. package/lib/typescript/components/KeyboardFocusView/KeyboardFocusView.android.d.ts.map +1 -0
  157. package/lib/typescript/components/KeyboardFocusView/KeyboardFocusView.ios.d.ts +14 -0
  158. package/lib/typescript/components/KeyboardFocusView/KeyboardFocusView.ios.d.ts.map +1 -0
  159. package/lib/typescript/components/KeyboardFocusView/hooks/index.d.ts +2 -0
  160. package/lib/typescript/components/KeyboardFocusView/hooks/index.d.ts.map +1 -0
  161. package/lib/typescript/components/KeyboardFocusView/hooks/useFocusStyle/index.d.ts +2 -0
  162. package/lib/typescript/components/KeyboardFocusView/hooks/useFocusStyle/index.d.ts.map +1 -0
  163. package/lib/typescript/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.d.ts +8 -0
  164. package/lib/typescript/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.d.ts.map +1 -0
  165. package/lib/typescript/components/KeyboardFocusView/index.d.ts +2 -0
  166. package/lib/typescript/components/KeyboardFocusView/index.d.ts.map +1 -0
  167. package/lib/typescript/components/Pressable/Pressable.android.d.ts +24 -0
  168. package/lib/typescript/components/Pressable/Pressable.android.d.ts.map +1 -0
  169. package/lib/typescript/components/Pressable/Pressable.ios.d.ts +88 -0
  170. package/lib/typescript/components/Pressable/Pressable.ios.d.ts.map +1 -0
  171. package/lib/typescript/components/Pressable/index.d.ts +2 -0
  172. package/lib/typescript/components/Pressable/index.d.ts.map +1 -0
  173. package/lib/typescript/components/index.d.ts +3 -0
  174. package/lib/typescript/components/index.d.ts.map +1 -0
  175. package/lib/typescript/index.d.ts +5 -0
  176. package/lib/typescript/index.d.ts.map +1 -0
  177. package/lib/typescript/nativeSpec/ExternalKeyboardViewNativeComponent.d.ts +30 -0
  178. package/lib/typescript/nativeSpec/ExternalKeyboardViewNativeComponent.d.ts.map +1 -0
  179. package/lib/typescript/nativeSpec/NativeKeyboardModule.d.ts +8 -0
  180. package/lib/typescript/nativeSpec/NativeKeyboardModule.d.ts.map +1 -0
  181. package/lib/typescript/nativeSpec/index.d.ts +5 -0
  182. package/lib/typescript/nativeSpec/index.d.ts.map +1 -0
  183. package/lib/typescript/services/A11yModule/A11yModule.android.d.ts +9 -0
  184. package/lib/typescript/services/A11yModule/A11yModule.android.d.ts.map +1 -0
  185. package/lib/typescript/services/A11yModule/A11yModule.ios.d.ts +10 -0
  186. package/lib/typescript/services/A11yModule/A11yModule.ios.d.ts.map +1 -0
  187. package/lib/typescript/services/A11yModule/A11yModule.types.d.ts +12 -0
  188. package/lib/typescript/services/A11yModule/A11yModule.types.d.ts.map +1 -0
  189. package/lib/typescript/services/A11yModule/index.d.ts +2 -0
  190. package/lib/typescript/services/A11yModule/index.d.ts.map +1 -0
  191. package/lib/typescript/services/index.d.ts +2 -0
  192. package/lib/typescript/services/index.d.ts.map +1 -0
  193. package/lib/typescript/types/FocusStyle.d.ts +6 -0
  194. package/lib/typescript/types/FocusStyle.d.ts.map +1 -0
  195. package/lib/typescript/types/KeyboardFocusView.types.d.ts +36 -0
  196. package/lib/typescript/types/KeyboardFocusView.types.d.ts.map +1 -0
  197. package/lib/typescript/types/index.d.ts +3 -0
  198. package/lib/typescript/types/index.d.ts.map +1 -0
  199. package/package.json +165 -0
  200. package/react-native-external-keyboard.podspec +36 -0
  201. package/src/NativeModules/A11yKeyboardModule/A11yKeyboardModule.ts +37 -0
  202. package/src/NativeModules/A11yKeyboardModule/index.ts +1 -0
  203. package/src/NativeModules/index.ts +1 -0
  204. package/src/components/KeyboardFocusView/KeyboardFocusView.android.tsx +41 -0
  205. package/src/components/KeyboardFocusView/KeyboardFocusView.d.ts +7 -0
  206. package/src/components/KeyboardFocusView/KeyboardFocusView.ios.tsx +51 -0
  207. package/src/components/KeyboardFocusView/hooks/index.ts +1 -0
  208. package/src/components/KeyboardFocusView/hooks/useFocusStyle/index.ts +1 -0
  209. package/src/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.ts +31 -0
  210. package/src/components/KeyboardFocusView/index.ts +1 -0
  211. package/src/components/Pressable/Pressable.android.tsx +95 -0
  212. package/src/components/Pressable/Pressable.d.ts +7 -0
  213. package/src/components/Pressable/Pressable.ios.tsx +282 -0
  214. package/src/components/Pressable/index.ts +1 -0
  215. package/src/components/index.ts +2 -0
  216. package/src/index.tsx +5 -0
  217. package/src/nativeSpec/ExternalKeyboardViewNativeComponent.ts +37 -0
  218. package/src/nativeSpec/NativeKeyboardModule.ts +9 -0
  219. package/src/nativeSpec/index.ts +6 -0
  220. package/src/services/A11yModule/A11yModule.android.ts +20 -0
  221. package/src/services/A11yModule/A11yModule.d.ts +3 -0
  222. package/src/services/A11yModule/A11yModule.ios.ts +33 -0
  223. package/src/services/A11yModule/A11yModule.types.ts +15 -0
  224. package/src/services/A11yModule/index.ts +1 -0
  225. package/src/services/index.ts +1 -0
  226. package/src/types/FocusStyle.ts +10 -0
  227. package/src/types/KeyboardFocusView.types.ts +43 -0
  228. package/src/types/index.ts +6 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Artur Kalach
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # React Native External Keyboard
2
+ ### react-native-external-keyboard
3
+
4
+ React Native library for extended external keyboard support.
5
+
6
+
7
+
8
+ ## Features
9
+ - Forcing keyboard focus (moving the keyboard focus to the specific element)
10
+ - A key press handling
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ npm install react-native-external-keyboard
16
+ ```
17
+
18
+ iOS:
19
+ ```sh
20
+ cd ios && pod install && cd ..
21
+ ```
22
+
23
+ ## Usage
24
+
25
+
26
+ ### Pressable
27
+ Updated pressable component with handling long press events on a keyboard
28
+ ```js
29
+ import { Pressable, } from "react-native-external-keyboard";
30
+
31
+ // ...
32
+
33
+ <Pressable
34
+ focusStyle={{ backgroundColor: '#cdf2ef' }}
35
+ onPress={() => console.log('onPress')}
36
+ onPressIn={() => console.log('onPressIn')}
37
+ onPressOut={() => console.log('onPressOut')}
38
+ onLongPress={() => console.log('onLongPress')}
39
+ >
40
+ <Text>On Press Check</Text>
41
+ </Pressable>
42
+ ```
43
+
44
+ ### KeyboardFocusView
45
+ The KeyboardFocusView component is core component for keyboard handling, it is used for force focusing and handling `onFocusChange` event
46
+ ```js
47
+ import { KeyboardFocusView } from "react-native-external-keyboard";
48
+ // ...
49
+
50
+ <KeyboardFocusView
51
+ focusStyle={{ backgroundColor: '#a0dcbe' }}
52
+ onFocusChange={(e) => console.log(e.nativeEvent.isFocused)}
53
+ >
54
+ <Text>Focusable</Text>
55
+ </KeyboardFocusView>
56
+ ```
57
+
58
+ If you want to move keyboard focus, you need to have a `ref` for the target component. It is important to use `KeyboardFocusView` as the target component (There can be a problem with moving focus for iOS if you use any component other than `KeyboardFocusView`).
59
+
60
+
61
+ ```js
62
+ import {
63
+ KeyboardFocusView,
64
+ A11yModule,
65
+ Pressable as KPressable,
66
+ } from 'react-native-external-keyboard';
67
+ // ...
68
+ <KPressable onPress={() => A11yModule.setKeyboardFocus(ref)}>
69
+ <Text>On Press Check</Text>
70
+ </KPressable>
71
+ <KeyboardFocusView
72
+ onFocusChange={(e) => console.log(e.nativeEvent.isFocused)}
73
+ >
74
+ <Text>Focusable</Text>
75
+ </KeyboardFocusView>
76
+ ```
77
+
78
+ ### ExternalKeyboardView
79
+ It is a bare `Native` component. It is better to use `KeyboardFocusView` if you don't need your own specific implementation.
80
+
81
+ Important: If you use `KeyboardFocusView` on Android, you need to use a children component with the `accessible` prop.
82
+
83
+
84
+ ```js
85
+ import { ExternalKeyboardView } from 'react-native-external-keyboard';
86
+ // ...
87
+ <ExternalKeyboardView
88
+ onKeyDownPress={...}
89
+ onKeyUpPress={...}
90
+ canBeFocused
91
+ >
92
+ <View accessible>
93
+ <Text>Content</Text>
94
+ </View>
95
+ </ExternalKeyboardView>
96
+ ```
97
+
98
+ # Important
99
+ ## iOS
100
+ New versions of iOS have specific `commands` for `physical keyboards`. If you can't handle a `long press event` on iOS, it may be that the `space` key is bound to an `Activate` command. Clearing the `Activate` command will help with handling of the `long press` event. There is no known way to handle this (if you have any ideas, please share).
101
+
102
+ User can change `Commands` in:
103
+ `Settings` -> `Accessibility` -> `Keyboards` -> `Full Keyboard Access` -> `Commands`
104
+
105
+
106
+
107
+ ## License
108
+
109
+ MIT
110
+
111
+ ---
112
+
113
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,45 @@
1
+ THIS_DIR := $(call my-dir)
2
+
3
+ include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
4
+
5
+ include ${GENERATED_SRC_DIR}/codegen/jni/Android.mk
6
+
7
+ include $(CLEAR_VARS)
8
+
9
+ LOCAL_PATH := $(THIS_DIR)
10
+
11
+ # Define the library name here.
12
+ LOCAL_MODULE := ${CODEGEN_MODULE_NAME}_registration
13
+
14
+ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
15
+
16
+ LOCAL_SHARED_LIBRARIES := \
17
+ libfabricjni \
18
+ libfbjni \
19
+ libglog \
20
+ libjsi \
21
+ libreact_codegen_rncore \
22
+ libreact_codegen_${CODEGEN_MODULE_NAME} \
23
+ libreact_debug \
24
+ libreact_nativemodule_core \
25
+ libreact_render_componentregistry \
26
+ libreact_render_core \
27
+ libreact_render_debug \
28
+ libreact_render_graphics \
29
+ librrc_view \
30
+ libruntimeexecutor \
31
+ libturbomodulejsijni \
32
+ libyoga
33
+
34
+ ifneq ($(filter $(call modules-get-list),folly_runtime),)
35
+ LOCAL_SHARED_LIBRARIES += libfolly_runtime # since react-native@0.69
36
+ else
37
+ LOCAL_SHARED_LIBRARIES += libfolly_futures libfolly_json # react-native@0.68
38
+ endif
39
+
40
+ LOCAL_CFLAGS := \
41
+ -DLOG_TAG=\"ReactNative\" \
42
+ -DCODEGEN_COMPONENT_DESCRIPTOR_H="<react/renderer/components/${CODEGEN_MODULE_NAME}/ComponentDescriptors.h>"
43
+ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
44
+
45
+ include $(BUILD_SHARED_LIBRARY)
@@ -0,0 +1,139 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+
7
+ dependencies {
8
+ classpath "com.android.tools.build:gradle:7.2.1"
9
+ }
10
+ }
11
+
12
+ def isNewArchitectureEnabled() {
13
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
14
+ }
15
+
16
+ apply plugin: "com.android.library"
17
+
18
+ import groovy.json.JsonSlurper
19
+
20
+ // https://github.com/callstack/react-native-builder-bob/discussions/359
21
+ def registrationCompat = {
22
+ def reactNativeManifest = file("$projectDir/../node_modules/react-native/package.json").exists()
23
+ ? file("$projectDir/../node_modules/react-native/package.json") // developer mode, to run example app
24
+ : file("$projectDir/../../react-native/package.json")
25
+ def reactNativeVersion = new JsonSlurper().parseText(reactNativeManifest.text).version as String
26
+ // Fabric was introduced at react-native@0.68, full CMake support were introduced at react-native@0.71
27
+ // Use Android.mk for compatibility with react-native@0.68/0.69
28
+ reactNativeVersion.matches('(0.68.*|0.69.*)')
29
+ }()
30
+
31
+ def codegenViewLibraryName = "ExternalKeyboardView"
32
+ def codegenViewModuleName = {
33
+ // Autolink for Fabric uses codegenConfig.name in package.json since react-native@0.70
34
+ // Use codegenViewLibraryName for compatibility with react-native@0.68/0.69
35
+ def libraryManifestJson = new JsonSlurper().parseText(file("$projectDir/../package.json").text)
36
+ registrationCompat ? codegenViewLibraryName : libraryManifestJson.codegenConfig.name
37
+ }()
38
+
39
+ def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
40
+
41
+ if (isNewArchitectureEnabled()) {
42
+ apply plugin: "com.facebook.react"
43
+ }
44
+
45
+ def getExtOrDefault(name) {
46
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ExternalKeyboard_" + name]
47
+ }
48
+
49
+ def getExtOrIntegerDefault(name) {
50
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ExternalKeyboard_" + name]).toInteger()
51
+ }
52
+
53
+ android {
54
+ ndkVersion getExtOrDefault("ndkVersion")
55
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
56
+
57
+ defaultConfig {
58
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
59
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
60
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
61
+ buildConfigField "String", "CODEGEN_MODULE_REGISTRATION", (isNewArchitectureEnabled() && registrationCompat ? "\"${codegenViewModuleName}_registration\"" : "null")
62
+ if (isNewArchitectureEnabled() && registrationCompat) {
63
+ def reactAndroidProject = project(':ReactAndroid')
64
+ externalNativeBuild {
65
+ ndkBuild {
66
+ arguments "APP_PLATFORM=android-21",
67
+ "APP_STL=c++_shared",
68
+ "NDK_TOOLCHAIN_VERSION=clang",
69
+ "GENERATED_SRC_DIR=$buildDir/generated/source", // for react_codegen_* in this library's codegen/jni
70
+ "PROJECT_BUILD_DIR=${appProject.buildDir}", // for REACT_NDK_EXPORT_DIR in ReactAndroid's Android-prebuilt.mk
71
+ "REACT_ANDROID_DIR=${reactAndroidProject.projectDir}",
72
+ "REACT_ANDROID_BUILD_DIR=${reactAndroidProject.buildDir}",
73
+ "CODEGEN_MODULE_NAME=$codegenViewModuleName"
74
+ cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
75
+ cppFlags "-std=c++17"
76
+ targets "${codegenViewModuleName}_registration"
77
+ }
78
+ }
79
+ }
80
+ }
81
+ if (isNewArchitectureEnabled() && registrationCompat) {
82
+ // We configure the NDK build only if you decide to opt-in for the New Architecture.
83
+ externalNativeBuild {
84
+ ndkBuild {
85
+ path "Android.mk"
86
+ }
87
+ }
88
+ }
89
+ buildTypes {
90
+ release {
91
+ minifyEnabled false
92
+ }
93
+ }
94
+
95
+ lintOptions {
96
+ disable "GradleCompatible"
97
+ }
98
+
99
+ compileOptions {
100
+ sourceCompatibility JavaVersion.VERSION_1_8
101
+ targetCompatibility JavaVersion.VERSION_1_8
102
+ }
103
+
104
+ sourceSets {
105
+ main {
106
+ if (isNewArchitectureEnabled()) {
107
+ java.srcDirs += [
108
+ "src/newarch",
109
+ // This is needed to build Kotlin project with NewArch enabled
110
+ "${project.buildDir}/generated/source/codegen/java"
111
+ ]
112
+ } else {
113
+ java.srcDirs += ["src/oldarch"]
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ repositories {
120
+ mavenCentral()
121
+ google()
122
+ }
123
+
124
+
125
+ dependencies {
126
+ // For < 0.71, this will be from the local maven repo
127
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
128
+ //noinspection GradleDynamicVersion
129
+ implementation "com.facebook.react:react-native:+"
130
+ }
131
+
132
+ if (isNewArchitectureEnabled()) {
133
+ react {
134
+ jsRootDir = file("../src/")
135
+
136
+ libraryName = codegenViewLibraryName
137
+ codegenJavaPackageName = "com.externalkeyboard"
138
+ }
139
+ }
@@ -0,0 +1,5 @@
1
+ ExternalKeyboard_kotlinVersion=1.7.0
2
+ ExternalKeyboard_minSdkVersion=21
3
+ ExternalKeyboard_targetSdkVersion=31
4
+ ExternalKeyboard_compileSdkVersion=31
5
+ ExternalKeyboard_ndkversion=21.4.7075529
@@ -0,0 +1,18 @@
1
+ #include <CoreComponentsRegistry.h>
2
+ #include CODEGEN_COMPONENT_DESCRIPTOR_H
3
+
4
+ namespace facebook {
5
+ namespace react {
6
+
7
+ void registerProviders() {
8
+ auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
9
+ providerRegistry->add(concreteComponentDescriptorProvider<ExternalKeyboardViewComponentDescriptor>());
10
+ }
11
+
12
+ }
13
+ }
14
+
15
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
16
+ facebook::react::registerProviders();
17
+ return JNI_VERSION_1_6;
18
+ }
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.externalkeyboard">
3
+
4
+ </manifest>
@@ -0,0 +1,46 @@
1
+ package com.externalkeyboard;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.externalkeyboard.services.KeyboardService;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.bridge.ReactMethod;
8
+
9
+ public class A11yKeyboardModule extends com.externalkeyboard.A11yKeyboardModuleSpec {
10
+ public static final String NAME = "A11yKeyboardModule";
11
+ private final KeyboardService keyboardService;
12
+
13
+ public A11yKeyboardModule(ReactApplicationContext context) {
14
+ super(context);
15
+ keyboardService = new KeyboardService(context);
16
+ }
17
+
18
+ @ReactMethod
19
+ @Override
20
+ public void setKeyboardFocus(double nativeTag, double _nextTag) {
21
+ this.keyboardService.setKeyboardFocus((int) nativeTag);
22
+ }
23
+
24
+ @Override
25
+ public void setPreferredKeyboardFocus(double nativeTag, double nextTag) {
26
+ //stub
27
+ }
28
+
29
+ @Override
30
+ @NonNull
31
+ public String getName() {
32
+ return NAME;
33
+ }
34
+
35
+
36
+ // Required for rn built in EventEmitter Calls.
37
+ @ReactMethod
38
+ public void addListener(String eventName) {
39
+
40
+ }
41
+
42
+ @ReactMethod
43
+ public void removeListeners(Integer count) {
44
+
45
+ }
46
+ }
@@ -0,0 +1,63 @@
1
+ package com.externalkeyboard;
2
+
3
+
4
+ import androidx.annotation.Nullable;
5
+
6
+ import com.externalkeyboard.views.ExternalKeyboardView.ExternalKeyboardViewManager;
7
+ import com.facebook.react.TurboReactPackage;
8
+ import com.facebook.react.bridge.NativeModule;
9
+ import com.facebook.react.bridge.ReactApplicationContext;
10
+ import com.facebook.react.module.model.ReactModuleInfo;
11
+ import com.facebook.react.module.model.ReactModuleInfoProvider;
12
+ import com.facebook.react.uimanager.ViewManager;
13
+
14
+ import java.util.ArrayList;
15
+ import java.util.Collections;
16
+ import java.util.HashMap;
17
+ import java.util.List;
18
+ import java.util.Map;
19
+
20
+
21
+ public class ExternalKeyboardViewPackage extends TurboReactPackage {
22
+ @Nullable
23
+ @Override
24
+ public NativeModule getModule(String name, ReactApplicationContext reactContext) {
25
+ if (name.equals(A11yKeyboardModule.NAME)) {
26
+ return new A11yKeyboardModule(reactContext);
27
+ } else {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ @Override
33
+ public ReactModuleInfoProvider getReactModuleInfoProvider() {
34
+ return () -> {
35
+ final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
36
+ boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
37
+ moduleInfos.put(
38
+ A11yKeyboardModule.NAME,
39
+ new ReactModuleInfo(
40
+ A11yKeyboardModule.NAME,
41
+ A11yKeyboardModule.NAME,
42
+ false, // canOverrideExistingModule
43
+ false, // needsEagerInit
44
+ true, // hasConstants
45
+ false, // isCxxModule
46
+ isTurboModule // isTurboModule
47
+ ));
48
+ return moduleInfos;
49
+ };
50
+ }
51
+
52
+ @Override
53
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
54
+ List<ViewManager> viewManagers = new ArrayList<>();
55
+ viewManagers.add(new ExternalKeyboardViewManager());
56
+ return viewManagers;
57
+ }
58
+
59
+ @Override
60
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
61
+ return Collections.emptyList();
62
+ }
63
+ }
@@ -0,0 +1,39 @@
1
+ package com.externalkeyboard.events;
2
+
3
+ import com.facebook.react.bridge.Arguments;
4
+ import com.facebook.react.bridge.WritableMap;
5
+ import com.facebook.react.uimanager.events.Event;
6
+ import com.facebook.react.uimanager.events.RCTEventEmitter;
7
+
8
+
9
+ public class FocusChangeEvent extends Event<FocusChangeEvent> {
10
+ public static String EVENT_NAME = "topOnFocusChange";
11
+ public WritableMap mExtraData;
12
+
13
+ public FocusChangeEvent(int id, Boolean hasFocus) {
14
+ super(id);
15
+ WritableMap eventPayload = Arguments.createMap();
16
+ eventPayload.putBoolean("isFocused", hasFocus);
17
+ this.mExtraData = eventPayload;
18
+ }
19
+
20
+ @Override
21
+ public void dispatch(RCTEventEmitter rCTEventEmitter) {
22
+ rCTEventEmitter.receiveEvent(this.getViewTag(), this.getEventName(), this.mExtraData);
23
+ }
24
+
25
+ @Override
26
+ public short getCoalescingKey() {
27
+ return 0;
28
+ }
29
+
30
+ @Override
31
+ public boolean canCoalesce() {
32
+ return false;
33
+ }
34
+
35
+ @Override
36
+ public String getEventName() {
37
+ return EVENT_NAME;
38
+ }
39
+ }
@@ -0,0 +1,49 @@
1
+ package com.externalkeyboard.events;
2
+
3
+ import android.view.KeyEvent;
4
+
5
+ import com.facebook.react.bridge.Arguments;
6
+ import com.facebook.react.bridge.WritableMap;
7
+ import com.facebook.react.uimanager.events.Event;
8
+ import com.facebook.react.uimanager.events.RCTEventEmitter;
9
+
10
+ public class KeyPressDownEvent extends Event<KeyPressDownEvent> {
11
+ public static String EVENT_NAME = "topOnKeyDownPress";
12
+ public WritableMap mExtraData;
13
+
14
+ public KeyPressDownEvent(int id, int keyCode, KeyEvent keyEvent) {
15
+ super(id);
16
+
17
+ WritableMap eventPayload = Arguments.createMap();
18
+ eventPayload.putInt("keyCode", keyCode);
19
+ eventPayload.putBoolean("isLongPress", keyEvent.isLongPress());
20
+ eventPayload.putBoolean("isAltPressed", keyEvent.isAltPressed());
21
+ eventPayload.putBoolean("isShiftPressed", keyEvent.isShiftPressed());
22
+ eventPayload.putBoolean("isCtrlPressed", keyEvent.isCtrlPressed());
23
+ eventPayload.putBoolean("isCapsLockOn", keyEvent.isCapsLockOn());
24
+ eventPayload.putBoolean("hasNoModifiers", keyEvent.hasNoModifiers());
25
+
26
+ this.mExtraData = eventPayload;
27
+ }
28
+
29
+ @Override
30
+ public void dispatch(RCTEventEmitter rCTEventEmitter) {
31
+ rCTEventEmitter.receiveEvent(this.getViewTag(), this.getEventName(), this.mExtraData);
32
+ }
33
+
34
+ @Override
35
+ public short getCoalescingKey() {
36
+ return 0;
37
+ }
38
+
39
+ @Override
40
+ public boolean canCoalesce() {
41
+ return false;
42
+ }
43
+
44
+ @Override
45
+ public String getEventName() {
46
+ return EVENT_NAME;
47
+ }
48
+
49
+ }
@@ -0,0 +1,49 @@
1
+ package com.externalkeyboard.events;
2
+
3
+ import android.view.KeyEvent;
4
+
5
+ import com.facebook.react.bridge.Arguments;
6
+ import com.facebook.react.bridge.WritableMap;
7
+ import com.facebook.react.uimanager.events.Event;
8
+ import com.facebook.react.uimanager.events.RCTEventEmitter;
9
+
10
+ public class KeyPressUpEvent extends Event<KeyPressUpEvent> {
11
+ public static String EVENT_NAME = "topOnKeyUpPress";
12
+ public WritableMap mExtraData;
13
+
14
+ public KeyPressUpEvent(int id, int keyCode, KeyEvent keyEvent, boolean isLongPress) {
15
+ super(id);
16
+
17
+ WritableMap eventPayload = Arguments.createMap();
18
+ eventPayload.putInt("keyCode", keyCode);
19
+ eventPayload.putBoolean("isLongPress", isLongPress);
20
+ eventPayload.putBoolean("isAltPressed", keyEvent.isAltPressed());
21
+ eventPayload.putBoolean("isShiftPressed", keyEvent.isShiftPressed());
22
+ eventPayload.putBoolean("isCtrlPressed", keyEvent.isCtrlPressed());
23
+ eventPayload.putBoolean("isCapsLockOn", keyEvent.isCapsLockOn());
24
+ eventPayload.putBoolean("hasNoModifiers", keyEvent.hasNoModifiers());
25
+
26
+ this.mExtraData = eventPayload;
27
+ }
28
+
29
+ @Override
30
+ public void dispatch(RCTEventEmitter rCTEventEmitter) {
31
+ rCTEventEmitter.receiveEvent(this.getViewTag(), this.getEventName(), this.mExtraData);
32
+ }
33
+
34
+ @Override
35
+ public short getCoalescingKey() {
36
+ return 0;
37
+ }
38
+
39
+ @Override
40
+ public boolean canCoalesce() {
41
+ return false;
42
+ }
43
+
44
+ @Override
45
+ public String getEventName() {
46
+ return EVENT_NAME;
47
+ }
48
+
49
+ }
@@ -0,0 +1,56 @@
1
+ package com.externalkeyboard.services;
2
+
3
+ import android.os.Build;
4
+ import android.view.KeyEvent;
5
+
6
+ import java.util.HashMap;
7
+
8
+ public class KeyboardKeyPressHandler {
9
+ private final HashMap<Integer, Boolean> pressedKeys = new HashMap<Integer, Boolean>();
10
+ private final HashMap<Integer, Boolean> longPress = new HashMap<Integer, Boolean>();
11
+
12
+ private boolean actionDownHandler(int keyCode, KeyEvent keyEvent) {
13
+ boolean wasAlreadyPressed = false;
14
+ if (pressedKeys.containsKey(keyCode)) {
15
+ wasAlreadyPressed = pressedKeys.get(keyCode);
16
+ }
17
+ pressedKeys.put(keyCode, true);
18
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR && keyEvent.isLongPress()) {
19
+ longPress.put(keyCode, keyEvent.isLongPress());
20
+ }
21
+
22
+ return !wasAlreadyPressed;
23
+ }
24
+
25
+ private boolean actionUpHandler(int keyCode, KeyEvent keyEvent) {
26
+ pressedKeys.put(keyCode, false);
27
+
28
+ boolean isLongPress = false;
29
+ if (longPress.containsKey(keyCode)) {
30
+ isLongPress = longPress.get(keyCode);
31
+ }
32
+ longPress.put(keyCode, false);
33
+
34
+ return isLongPress;
35
+ }
36
+
37
+ public PressInfo getEventsFromKeyPress(int keyCode, KeyEvent keyEvent) {
38
+ PressInfo pressInfo = new PressInfo();
39
+
40
+ if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
41
+ pressInfo.firePressDownEvent = actionDownHandler(keyCode, keyEvent);
42
+ }
43
+ if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
44
+ pressInfo.firePressUpEvent = true;
45
+ pressInfo.isLongPress = actionUpHandler(keyCode, keyEvent);
46
+ }
47
+
48
+ return pressInfo;
49
+ }
50
+
51
+ public class PressInfo {
52
+ public boolean firePressDownEvent = false;
53
+ public boolean firePressUpEvent = false;
54
+ public boolean isLongPress = false;
55
+ }
56
+ }