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.
- package/LICENSE +20 -0
- package/README.md +113 -0
- package/android/Android.mk +45 -0
- package/android/build.gradle +139 -0
- package/android/gradle.properties +5 -0
- package/android/registration.cpp +18 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/externalkeyboard/A11yKeyboardModule.java +46 -0
- package/android/src/main/java/com/externalkeyboard/ExternalKeyboardViewPackage.java +63 -0
- package/android/src/main/java/com/externalkeyboard/events/FocusChangeEvent.java +39 -0
- package/android/src/main/java/com/externalkeyboard/events/KeyPressDownEvent.java +49 -0
- package/android/src/main/java/com/externalkeyboard/events/KeyPressUpEvent.java +49 -0
- package/android/src/main/java/com/externalkeyboard/services/KeyboardKeyPressHandler.java +56 -0
- package/android/src/main/java/com/externalkeyboard/services/KeyboardService.java +52 -0
- package/android/src/main/java/com/externalkeyboard/views/ExternalKeyboardView/ExternalKeyboardView.java +28 -0
- package/android/src/main/java/com/externalkeyboard/views/ExternalKeyboardView/ExternalKeyboardViewManager.java +101 -0
- package/android/src/newarch/A11yKeyboardModuleSpec.java +9 -0
- package/android/src/newarch/ExternalKeyboardViewManagerSpec.java +31 -0
- package/android/src/oldarch/A11yKeyboardModuleSpec.java +15 -0
- package/android/src/oldarch/ExternalKeyboardViewManagerSpec.java +9 -0
- package/ios/ExternalKeyboard.xcodeproj/project.pbxproj +384 -0
- package/ios/ExternalKeyboard.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/ExternalKeyboard.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/ExternalKeyboard.xcodeproj/project.xcworkspace/xcuserdata/Artur_Kalach.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/ExternalKeyboard.xcodeproj/xcuserdata/Artur_Kalach.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +24 -0
- package/ios/ExternalKeyboard.xcodeproj/xcuserdata/Artur_Kalach.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/ios/ExternalKeyboardView/ExternalKeyboardView.h +41 -0
- package/ios/ExternalKeyboardView/ExternalKeyboardView.mm +186 -0
- package/ios/Helpers/FocusWrapper/FocusWrapper.h +32 -0
- package/ios/Helpers/FocusWrapper/FocusWrapper.mm +63 -0
- package/ios/Helpers/KeyboardKeyPressHandler/KeyboardKeyPressHandler.h +27 -0
- package/ios/Helpers/KeyboardKeyPressHandler/KeyboardKeyPressHandler.mm +73 -0
- package/ios/Modules/A11yKeyboardModule/A11yKeyboardModule.h +20 -0
- package/ios/Modules/A11yKeyboardModule/A11yKeyboardModule.mm +86 -0
- package/ios/ViewManagers/ExternalKeyboardViewManager/ExternalKeyboardViewManager.h +16 -0
- package/ios/ViewManagers/ExternalKeyboardViewManager/ExternalKeyboardViewManager.mm +29 -0
- package/lib/commonjs/NativeModules/A11yKeyboardModule/A11yKeyboardModule.js +33 -0
- package/lib/commonjs/NativeModules/A11yKeyboardModule/A11yKeyboardModule.js.map +1 -0
- package/lib/commonjs/NativeModules/A11yKeyboardModule/index.js +13 -0
- package/lib/commonjs/NativeModules/A11yKeyboardModule/index.js.map +1 -0
- package/lib/commonjs/NativeModules/index.js +13 -0
- package/lib/commonjs/NativeModules/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.android.js +41 -0
- package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.android.js.map +1 -0
- package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.d.js +6 -0
- package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.d.js.map +1 -0
- package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.ios.js +46 -0
- package/lib/commonjs/components/KeyboardFocusView/KeyboardFocusView.ios.js.map +1 -0
- package/lib/commonjs/components/KeyboardFocusView/hooks/index.js +13 -0
- package/lib/commonjs/components/KeyboardFocusView/hooks/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardFocusView/hooks/useFocusStyle/index.js +13 -0
- package/lib/commonjs/components/KeyboardFocusView/hooks/useFocusStyle/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.js +33 -0
- package/lib/commonjs/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.js.map +1 -0
- package/lib/commonjs/components/KeyboardFocusView/index.js +13 -0
- package/lib/commonjs/components/KeyboardFocusView/index.js.map +1 -0
- package/lib/commonjs/components/Pressable/Pressable.android.js +76 -0
- package/lib/commonjs/components/Pressable/Pressable.android.js.map +1 -0
- package/lib/commonjs/components/Pressable/Pressable.d.js +6 -0
- package/lib/commonjs/components/Pressable/Pressable.d.js.map +1 -0
- package/lib/commonjs/components/Pressable/Pressable.ios.js +157 -0
- package/lib/commonjs/components/Pressable/Pressable.ios.js.map +1 -0
- package/lib/commonjs/components/Pressable/index.js +13 -0
- package/lib/commonjs/components/Pressable/index.js.map +1 -0
- package/lib/commonjs/components/index.js +20 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/index.js +46 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/nativeSpec/ExternalKeyboardViewNativeComponent.js +11 -0
- package/lib/commonjs/nativeSpec/ExternalKeyboardViewNativeComponent.js.map +1 -0
- package/lib/commonjs/nativeSpec/NativeKeyboardModule.js +10 -0
- package/lib/commonjs/nativeSpec/NativeKeyboardModule.js.map +1 -0
- package/lib/commonjs/nativeSpec/index.js +21 -0
- package/lib/commonjs/nativeSpec/index.js.map +1 -0
- package/lib/commonjs/services/A11yModule/A11yModule.android.js +22 -0
- package/lib/commonjs/services/A11yModule/A11yModule.android.js.map +1 -0
- package/lib/commonjs/services/A11yModule/A11yModule.d.js +6 -0
- package/lib/commonjs/services/A11yModule/A11yModule.d.js.map +1 -0
- package/lib/commonjs/services/A11yModule/A11yModule.ios.js +28 -0
- package/lib/commonjs/services/A11yModule/A11yModule.ios.js.map +1 -0
- package/lib/commonjs/services/A11yModule/A11yModule.types.js +6 -0
- package/lib/commonjs/services/A11yModule/A11yModule.types.js.map +1 -0
- package/lib/commonjs/services/A11yModule/index.js +13 -0
- package/lib/commonjs/services/A11yModule/index.js.map +1 -0
- package/lib/commonjs/services/index.js +13 -0
- package/lib/commonjs/services/index.js.map +1 -0
- package/lib/commonjs/types/FocusStyle.js +6 -0
- package/lib/commonjs/types/FocusStyle.js.map +1 -0
- package/lib/commonjs/types/KeyboardFocusView.types.js +6 -0
- package/lib/commonjs/types/KeyboardFocusView.types.js.map +1 -0
- package/lib/commonjs/types/index.js +38 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/module/NativeModules/A11yKeyboardModule/A11yKeyboardModule.js +26 -0
- package/lib/module/NativeModules/A11yKeyboardModule/A11yKeyboardModule.js.map +1 -0
- package/lib/module/NativeModules/A11yKeyboardModule/index.js +2 -0
- package/lib/module/NativeModules/A11yKeyboardModule/index.js.map +1 -0
- package/lib/module/NativeModules/index.js +2 -0
- package/lib/module/NativeModules/index.js.map +1 -0
- package/lib/module/components/KeyboardFocusView/KeyboardFocusView.android.js +33 -0
- package/lib/module/components/KeyboardFocusView/KeyboardFocusView.android.js.map +1 -0
- package/lib/module/components/KeyboardFocusView/KeyboardFocusView.d.js +2 -0
- package/lib/module/components/KeyboardFocusView/KeyboardFocusView.d.js.map +1 -0
- package/lib/module/components/KeyboardFocusView/KeyboardFocusView.ios.js +37 -0
- package/lib/module/components/KeyboardFocusView/KeyboardFocusView.ios.js.map +1 -0
- package/lib/module/components/KeyboardFocusView/hooks/index.js +2 -0
- package/lib/module/components/KeyboardFocusView/hooks/index.js.map +1 -0
- package/lib/module/components/KeyboardFocusView/hooks/useFocusStyle/index.js +2 -0
- package/lib/module/components/KeyboardFocusView/hooks/useFocusStyle/index.js.map +1 -0
- package/lib/module/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.js +26 -0
- package/lib/module/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.js.map +1 -0
- package/lib/module/components/KeyboardFocusView/index.js +2 -0
- package/lib/module/components/KeyboardFocusView/index.js.map +1 -0
- package/lib/module/components/Pressable/Pressable.android.js +70 -0
- package/lib/module/components/Pressable/Pressable.android.js.map +1 -0
- package/lib/module/components/Pressable/Pressable.d.js +2 -0
- package/lib/module/components/Pressable/Pressable.d.js.map +1 -0
- package/lib/module/components/Pressable/Pressable.ios.js +148 -0
- package/lib/module/components/Pressable/Pressable.ios.js.map +1 -0
- package/lib/module/components/Pressable/index.js +2 -0
- package/lib/module/components/Pressable/index.js.map +1 -0
- package/lib/module/components/index.js +3 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/nativeSpec/ExternalKeyboardViewNativeComponent.js +3 -0
- package/lib/module/nativeSpec/ExternalKeyboardViewNativeComponent.js.map +1 -0
- package/lib/module/nativeSpec/NativeKeyboardModule.js +3 -0
- package/lib/module/nativeSpec/NativeKeyboardModule.js.map +1 -0
- package/lib/module/nativeSpec/index.js +4 -0
- package/lib/module/nativeSpec/index.js.map +1 -0
- package/lib/module/services/A11yModule/A11yModule.android.js +15 -0
- package/lib/module/services/A11yModule/A11yModule.android.js.map +1 -0
- package/lib/module/services/A11yModule/A11yModule.d.js +2 -0
- package/lib/module/services/A11yModule/A11yModule.d.js.map +1 -0
- package/lib/module/services/A11yModule/A11yModule.ios.js +21 -0
- package/lib/module/services/A11yModule/A11yModule.ios.js.map +1 -0
- package/lib/module/services/A11yModule/A11yModule.types.js +2 -0
- package/lib/module/services/A11yModule/A11yModule.types.js.map +1 -0
- package/lib/module/services/A11yModule/index.js +2 -0
- package/lib/module/services/A11yModule/index.js.map +1 -0
- package/lib/module/services/index.js +2 -0
- package/lib/module/services/index.js.map +1 -0
- package/lib/module/types/FocusStyle.js +2 -0
- package/lib/module/types/FocusStyle.js.map +1 -0
- package/lib/module/types/KeyboardFocusView.types.js +2 -0
- package/lib/module/types/KeyboardFocusView.types.js.map +1 -0
- package/lib/module/types/index.js +3 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/typescript/NativeModules/A11yKeyboardModule/A11yKeyboardModule.d.ts +5 -0
- package/lib/typescript/NativeModules/A11yKeyboardModule/A11yKeyboardModule.d.ts.map +1 -0
- package/lib/typescript/NativeModules/A11yKeyboardModule/index.d.ts +2 -0
- package/lib/typescript/NativeModules/A11yKeyboardModule/index.d.ts.map +1 -0
- package/lib/typescript/NativeModules/index.d.ts +2 -0
- package/lib/typescript/NativeModules/index.d.ts.map +1 -0
- package/lib/typescript/components/KeyboardFocusView/KeyboardFocusView.android.d.ts +14 -0
- package/lib/typescript/components/KeyboardFocusView/KeyboardFocusView.android.d.ts.map +1 -0
- package/lib/typescript/components/KeyboardFocusView/KeyboardFocusView.ios.d.ts +14 -0
- package/lib/typescript/components/KeyboardFocusView/KeyboardFocusView.ios.d.ts.map +1 -0
- package/lib/typescript/components/KeyboardFocusView/hooks/index.d.ts +2 -0
- package/lib/typescript/components/KeyboardFocusView/hooks/index.d.ts.map +1 -0
- package/lib/typescript/components/KeyboardFocusView/hooks/useFocusStyle/index.d.ts +2 -0
- package/lib/typescript/components/KeyboardFocusView/hooks/useFocusStyle/index.d.ts.map +1 -0
- package/lib/typescript/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.d.ts +8 -0
- package/lib/typescript/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.d.ts.map +1 -0
- package/lib/typescript/components/KeyboardFocusView/index.d.ts +2 -0
- package/lib/typescript/components/KeyboardFocusView/index.d.ts.map +1 -0
- package/lib/typescript/components/Pressable/Pressable.android.d.ts +24 -0
- package/lib/typescript/components/Pressable/Pressable.android.d.ts.map +1 -0
- package/lib/typescript/components/Pressable/Pressable.ios.d.ts +88 -0
- package/lib/typescript/components/Pressable/Pressable.ios.d.ts.map +1 -0
- package/lib/typescript/components/Pressable/index.d.ts +2 -0
- package/lib/typescript/components/Pressable/index.d.ts.map +1 -0
- package/lib/typescript/components/index.d.ts +3 -0
- package/lib/typescript/components/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/nativeSpec/ExternalKeyboardViewNativeComponent.d.ts +30 -0
- package/lib/typescript/nativeSpec/ExternalKeyboardViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/nativeSpec/NativeKeyboardModule.d.ts +8 -0
- package/lib/typescript/nativeSpec/NativeKeyboardModule.d.ts.map +1 -0
- package/lib/typescript/nativeSpec/index.d.ts +5 -0
- package/lib/typescript/nativeSpec/index.d.ts.map +1 -0
- package/lib/typescript/services/A11yModule/A11yModule.android.d.ts +9 -0
- package/lib/typescript/services/A11yModule/A11yModule.android.d.ts.map +1 -0
- package/lib/typescript/services/A11yModule/A11yModule.ios.d.ts +10 -0
- package/lib/typescript/services/A11yModule/A11yModule.ios.d.ts.map +1 -0
- package/lib/typescript/services/A11yModule/A11yModule.types.d.ts +12 -0
- package/lib/typescript/services/A11yModule/A11yModule.types.d.ts.map +1 -0
- package/lib/typescript/services/A11yModule/index.d.ts +2 -0
- package/lib/typescript/services/A11yModule/index.d.ts.map +1 -0
- package/lib/typescript/services/index.d.ts +2 -0
- package/lib/typescript/services/index.d.ts.map +1 -0
- package/lib/typescript/types/FocusStyle.d.ts +6 -0
- package/lib/typescript/types/FocusStyle.d.ts.map +1 -0
- package/lib/typescript/types/KeyboardFocusView.types.d.ts +36 -0
- package/lib/typescript/types/KeyboardFocusView.types.d.ts.map +1 -0
- package/lib/typescript/types/index.d.ts +3 -0
- package/lib/typescript/types/index.d.ts.map +1 -0
- package/package.json +165 -0
- package/react-native-external-keyboard.podspec +36 -0
- package/src/NativeModules/A11yKeyboardModule/A11yKeyboardModule.ts +37 -0
- package/src/NativeModules/A11yKeyboardModule/index.ts +1 -0
- package/src/NativeModules/index.ts +1 -0
- package/src/components/KeyboardFocusView/KeyboardFocusView.android.tsx +41 -0
- package/src/components/KeyboardFocusView/KeyboardFocusView.d.ts +7 -0
- package/src/components/KeyboardFocusView/KeyboardFocusView.ios.tsx +51 -0
- package/src/components/KeyboardFocusView/hooks/index.ts +1 -0
- package/src/components/KeyboardFocusView/hooks/useFocusStyle/index.ts +1 -0
- package/src/components/KeyboardFocusView/hooks/useFocusStyle/useFocusStyle.ts +31 -0
- package/src/components/KeyboardFocusView/index.ts +1 -0
- package/src/components/Pressable/Pressable.android.tsx +95 -0
- package/src/components/Pressable/Pressable.d.ts +7 -0
- package/src/components/Pressable/Pressable.ios.tsx +282 -0
- package/src/components/Pressable/index.ts +1 -0
- package/src/components/index.ts +2 -0
- package/src/index.tsx +5 -0
- package/src/nativeSpec/ExternalKeyboardViewNativeComponent.ts +37 -0
- package/src/nativeSpec/NativeKeyboardModule.ts +9 -0
- package/src/nativeSpec/index.ts +6 -0
- package/src/services/A11yModule/A11yModule.android.ts +20 -0
- package/src/services/A11yModule/A11yModule.d.ts +3 -0
- package/src/services/A11yModule/A11yModule.ios.ts +33 -0
- package/src/services/A11yModule/A11yModule.types.ts +15 -0
- package/src/services/A11yModule/index.ts +1 -0
- package/src/services/index.ts +1 -0
- package/src/types/FocusStyle.ts +10 -0
- package/src/types/KeyboardFocusView.types.ts +43 -0
- 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,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,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
|
+
}
|