@react-native-ohos/react-native-keyboard-controller 1.12.8 → 1.12.9
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 +21 -21
- package/README.OpenSource +10 -10
- package/README.md +603 -19
- package/harmony/keyboard_controller/BuildProfile.ets +16 -16
- package/harmony/keyboard_controller/Index.ets +8 -29
- package/harmony/keyboard_controller/ResourceTable.txt +8 -8
- package/harmony/keyboard_controller/build-profile.json5 +31 -31
- package/harmony/keyboard_controller/hvigorfile.ts +6 -6
- package/harmony/keyboard_controller/obfuscation-rules.txt +17 -17
- package/harmony/keyboard_controller/oh-package-lock.json5 +28 -18
- package/harmony/keyboard_controller/oh-package.json5 +11 -11
- package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -7
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +119 -96
- package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +90 -111
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +77 -98
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +816 -274
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +147 -101
- package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +43 -64
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +64 -85
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +88 -109
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +63 -84
- package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -60
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -46
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -48
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +43 -64
- package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +56 -77
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -45
- package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -49
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +186 -186
- package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +112 -112
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -64
- package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -77
- package/harmony/keyboard_controller/src/main/ets/Logger.ts +45 -66
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +49 -70
- package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +405 -245
- package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +107 -119
- package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -62
- package/harmony/keyboard_controller/src/main/module.json +29 -29
- package/harmony/keyboard_controller/src/main/module.json5 +11 -11
- package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -8
- package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -8
- package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -8
- package/harmony/keyboard_controller/ts.ets +8 -29
- package/harmony/keyboard_controller.har +0 -0
- package/lib/commonjs/animated.js +4 -16
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/bindings.js +3 -3
- package/lib/commonjs/bindings.js.map +1 -1
- package/lib/commonjs/bindings.native.js +3 -3
- package/lib/commonjs/bindings.native.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +3 -3
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +43 -41
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +3 -3
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/index.js +3 -3
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -1
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/context.js.map +1 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -1
- package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +18 -18
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/commonjs/monkey-patch.android.js +4 -4
- package/lib/commonjs/monkey-patch.android.js.map +1 -1
- package/lib/commonjs/monkey-patch.js.map +1 -1
- package/lib/commonjs/reanimated.js.map +1 -1
- package/lib/commonjs/reanimated.native.js.map +1 -1
- package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
- package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/animated.js +5 -17
- package/lib/module/animated.js.map +1 -1
- package/lib/module/bindings.js +3 -3
- package/lib/module/bindings.js.map +1 -1
- package/lib/module/bindings.native.js +3 -3
- package/lib/module/bindings.native.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +3 -3
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +44 -42
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +3 -3
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -1
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/Button.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/colors.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/index.js +3 -3
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/types.js.map +1 -1
- package/lib/module/components/hooks/useColorScheme.js.map +1 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -1
- package/lib/module/hooks/useWindowDimensions/index.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +18 -18
- package/lib/module/internal.js.map +1 -1
- package/lib/module/monkey-patch.android.js +4 -4
- package/lib/module/monkey-patch.android.js.map +1 -1
- package/lib/module/monkey-patch.js.map +1 -1
- package/lib/module/reanimated.js.map +1 -1
- package/lib/module/reanimated.native.js.map +1 -1
- package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
- package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
- package/lib/module/specs/NativeKeyboardController.js.map +1 -1
- package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/types.d.ts +1 -0
- package/package.json +181 -178
- package/src/animated.tsx +246 -253
- package/src/bindings.native.ts +57 -57
- package/src/bindings.ts +38 -38
- package/src/components/KeyboardAvoidingView/hooks.ts +58 -58
- package/src/components/KeyboardAvoidingView/index.tsx +156 -156
- package/src/components/KeyboardAwareScrollView/index.tsx +381 -373
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -133
- package/src/components/KeyboardAwareScrollView/utils.ts +41 -41
- package/src/components/KeyboardStickyView/index.tsx +57 -57
- package/src/components/KeyboardToolbar/Arrow.tsx +80 -80
- package/src/components/KeyboardToolbar/Button.tsx +98 -98
- package/src/components/KeyboardToolbar/colors.native.ts +37 -37
- package/src/components/KeyboardToolbar/colors.ts +16 -16
- package/src/components/KeyboardToolbar/index.tsx +211 -211
- package/src/components/KeyboardToolbar/types.ts +40 -40
- package/src/components/hooks/useColorScheme.ts +5 -5
- package/src/components/index.ts +11 -11
- package/src/constants.ts +19 -19
- package/src/context.ts +65 -65
- package/src/hooks/index.ts +90 -90
- package/src/hooks/useWindowDimensions/index.android.ts +33 -33
- package/src/hooks/useWindowDimensions/index.ts +1 -1
- package/src/index.ts +21 -21
- package/src/internal.ts +84 -84
- package/src/monkey-patch.android.ts +44 -44
- package/src/monkey-patch.ts +4 -4
- package/src/reanimated.native.ts +132 -132
- package/src/reanimated.ts +29 -29
- package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -70
- package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -15
- package/src/specs/NativeKeyboardController.ts +19 -19
- package/src/specs/NativeStatusBarManagerCompat.ts +14 -14
- package/src/types.ts +212 -211
- package/src/utils.ts +1 -1
package/src/animated.tsx
CHANGED
|
@@ -1,253 +1,246 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { Animated, Platform, StyleSheet } from "react-native";
|
|
3
|
-
import Reanimated, { useSharedValue
|
|
4
|
-
|
|
5
|
-
import { KeyboardControllerView } from "./bindings";
|
|
6
|
-
import { KeyboardContext } from "./context";
|
|
7
|
-
import { useAnimatedValue, useSharedHandlers } from "./internal";
|
|
8
|
-
import { applyMonkeyPatch, revertMonkeyPatch } from "./monkey-patch";
|
|
9
|
-
import {
|
|
10
|
-
useAnimatedKeyboardHandler,
|
|
11
|
-
useFocusedInputLayoutHandler,
|
|
12
|
-
useFocusedInputSelectionHandler,
|
|
13
|
-
useFocusedInputTextHandler,
|
|
14
|
-
} from "./reanimated";
|
|
15
|
-
|
|
16
|
-
import type { KeyboardAnimationContext } from "./context";
|
|
17
|
-
import type {
|
|
18
|
-
FocusedInputHandler,
|
|
19
|
-
FocusedInputLayoutChangedEvent,
|
|
20
|
-
KeyboardControllerProps,
|
|
21
|
-
KeyboardHandler,
|
|
22
|
-
NativeEvent,
|
|
23
|
-
} from "./types";
|
|
24
|
-
import type { ViewStyle } from "react-native";
|
|
25
|
-
|
|
26
|
-
const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
|
|
27
|
-
Animated.createAnimatedComponent(
|
|
28
|
-
KeyboardControllerView,
|
|
29
|
-
) as React.FC<KeyboardControllerProps>,
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
type Styles = {
|
|
33
|
-
container: ViewStyle;
|
|
34
|
-
hidden: ViewStyle;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const styles = StyleSheet.create<Styles>({
|
|
38
|
-
container: {
|
|
39
|
-
flex: 1,
|
|
40
|
-
},
|
|
41
|
-
hidden: {
|
|
42
|
-
display: "none",
|
|
43
|
-
position: "absolute",
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
type KeyboardProviderProps = {
|
|
48
|
-
children: React.ReactNode;
|
|
49
|
-
/**
|
|
50
|
-
* Set the value to `true`, if you use translucent status bar on Android.
|
|
51
|
-
* If you already control status bar translucency via `react-native-screens`
|
|
52
|
-
* or `StatusBar` component from `react-native`, you can ignore it.
|
|
53
|
-
* Defaults to `false`.
|
|
54
|
-
*
|
|
55
|
-
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14
|
|
56
|
-
* @platform android
|
|
57
|
-
*/
|
|
58
|
-
statusBarTranslucent?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Set the value to `true`, if you use translucent navigation bar on Android.
|
|
61
|
-
* Defaults to `false`.
|
|
62
|
-
*
|
|
63
|
-
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119
|
|
64
|
-
* @platform android
|
|
65
|
-
*/
|
|
66
|
-
navigationBarTranslucent?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* A boolean prop indicating whether the module is enabled. It indicate only initial state,
|
|
69
|
-
* i. e. if you try to change this prop after component mount it will not have any effect.
|
|
70
|
-
* To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.
|
|
71
|
-
* Defaults to `true`.
|
|
72
|
-
*/
|
|
73
|
-
enabled?: boolean;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package
|
|
77
|
-
// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details
|
|
78
|
-
const OS = Platform.OS;
|
|
79
|
-
|
|
80
|
-
export const KeyboardProvider = ({
|
|
81
|
-
children,
|
|
82
|
-
statusBarTranslucent,
|
|
83
|
-
navigationBarTranslucent,
|
|
84
|
-
enabled: initiallyEnabled = true,
|
|
85
|
-
}: KeyboardProviderProps) => {
|
|
86
|
-
// state
|
|
87
|
-
const [enabled, setEnabled] = useState(initiallyEnabled);
|
|
88
|
-
// animated values
|
|
89
|
-
const progress = useAnimatedValue(0);
|
|
90
|
-
const height = useAnimatedValue(0);
|
|
91
|
-
// shared values
|
|
92
|
-
const progressSV = useSharedValue(0);
|
|
93
|
-
const heightSV = useSharedValue(0);
|
|
94
|
-
const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);
|
|
95
|
-
const [setKeyboardHandlers, broadcastKeyboardEvents] =
|
|
96
|
-
useSharedHandlers<KeyboardHandler>();
|
|
97
|
-
const [setInputHandlers, broadcastInputEvents] =
|
|
98
|
-
useSharedHandlers<FocusedInputHandler>();
|
|
99
|
-
// memo
|
|
100
|
-
const context = useMemo<KeyboardAnimationContext>(
|
|
101
|
-
() => ({
|
|
102
|
-
enabled,
|
|
103
|
-
animated: { progress: progress, height: Animated.multiply(height, -1) },
|
|
104
|
-
reanimated: { progress: progressSV, height: heightSV },
|
|
105
|
-
layout,
|
|
106
|
-
setKeyboardHandlers,
|
|
107
|
-
setInputHandlers,
|
|
108
|
-
setEnabled,
|
|
109
|
-
}),
|
|
110
|
-
[enabled],
|
|
111
|
-
);
|
|
112
|
-
const style = useMemo(
|
|
113
|
-
() => [
|
|
114
|
-
styles.hidden,
|
|
115
|
-
{ transform: [{ translateX: height }, { translateY: progress }] },
|
|
116
|
-
],
|
|
117
|
-
[],
|
|
118
|
-
);
|
|
119
|
-
const onKeyboardMove = useMemo(
|
|
120
|
-
() =>
|
|
121
|
-
Animated.event(
|
|
122
|
-
[
|
|
123
|
-
{
|
|
124
|
-
nativeEvent: {
|
|
125
|
-
progress,
|
|
126
|
-
height,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
{ useNativeDriver: Platform.OS as string == 'harmony' ? false : true },
|
|
131
|
-
),
|
|
132
|
-
[],
|
|
133
|
-
);
|
|
134
|
-
// handlers
|
|
135
|
-
const updateSharedValues = (event: NativeEvent, platforms: string[]) => {
|
|
136
|
-
"worklet";
|
|
137
|
-
|
|
138
|
-
if (platforms.includes(OS)) {
|
|
139
|
-
// eslint-disable-next-line react-compiler/react-compiler
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
"
|
|
167
|
-
broadcastKeyboardEvents("
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// To test why it's needed, try to open screen which consumes Animated.Value
|
|
248
|
-
// then close it and open it again (for example 'Animated transition').
|
|
249
|
-
style={style}
|
|
250
|
-
/>
|
|
251
|
-
</KeyboardContext.Provider>
|
|
252
|
-
);
|
|
253
|
-
};
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { Animated, Platform, StyleSheet } from "react-native";
|
|
3
|
+
import Reanimated, { useSharedValue } from "react-native-reanimated";
|
|
4
|
+
|
|
5
|
+
import { KeyboardControllerView } from "./bindings";
|
|
6
|
+
import { KeyboardContext } from "./context";
|
|
7
|
+
import { useAnimatedValue, useSharedHandlers } from "./internal";
|
|
8
|
+
import { applyMonkeyPatch, revertMonkeyPatch } from "./monkey-patch";
|
|
9
|
+
import {
|
|
10
|
+
useAnimatedKeyboardHandler,
|
|
11
|
+
useFocusedInputLayoutHandler,
|
|
12
|
+
useFocusedInputSelectionHandler,
|
|
13
|
+
useFocusedInputTextHandler,
|
|
14
|
+
} from "./reanimated";
|
|
15
|
+
|
|
16
|
+
import type { KeyboardAnimationContext } from "./context";
|
|
17
|
+
import type {
|
|
18
|
+
FocusedInputHandler,
|
|
19
|
+
FocusedInputLayoutChangedEvent,
|
|
20
|
+
KeyboardControllerProps,
|
|
21
|
+
KeyboardHandler,
|
|
22
|
+
NativeEvent,
|
|
23
|
+
} from "./types";
|
|
24
|
+
import type { ViewStyle } from "react-native";
|
|
25
|
+
|
|
26
|
+
const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
|
|
27
|
+
Animated.createAnimatedComponent(
|
|
28
|
+
KeyboardControllerView,
|
|
29
|
+
) as React.FC<KeyboardControllerProps>,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
type Styles = {
|
|
33
|
+
container: ViewStyle;
|
|
34
|
+
hidden: ViewStyle;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const styles = StyleSheet.create<Styles>({
|
|
38
|
+
container: {
|
|
39
|
+
flex: 1,
|
|
40
|
+
},
|
|
41
|
+
hidden: {
|
|
42
|
+
display: "none",
|
|
43
|
+
position: "absolute",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
type KeyboardProviderProps = {
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* Set the value to `true`, if you use translucent status bar on Android.
|
|
51
|
+
* If you already control status bar translucency via `react-native-screens`
|
|
52
|
+
* or `StatusBar` component from `react-native`, you can ignore it.
|
|
53
|
+
* Defaults to `false`.
|
|
54
|
+
*
|
|
55
|
+
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14
|
|
56
|
+
* @platform android
|
|
57
|
+
*/
|
|
58
|
+
statusBarTranslucent?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Set the value to `true`, if you use translucent navigation bar on Android.
|
|
61
|
+
* Defaults to `false`.
|
|
62
|
+
*
|
|
63
|
+
* @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119
|
|
64
|
+
* @platform android
|
|
65
|
+
*/
|
|
66
|
+
navigationBarTranslucent?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* A boolean prop indicating whether the module is enabled. It indicate only initial state,
|
|
69
|
+
* i. e. if you try to change this prop after component mount it will not have any effect.
|
|
70
|
+
* To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.
|
|
71
|
+
* Defaults to `true`.
|
|
72
|
+
*/
|
|
73
|
+
enabled?: boolean;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package
|
|
77
|
+
// see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details
|
|
78
|
+
const OS = Platform.OS;
|
|
79
|
+
|
|
80
|
+
export const KeyboardProvider = ({
|
|
81
|
+
children,
|
|
82
|
+
statusBarTranslucent,
|
|
83
|
+
navigationBarTranslucent,
|
|
84
|
+
enabled: initiallyEnabled = true,
|
|
85
|
+
}: KeyboardProviderProps) => {
|
|
86
|
+
// state
|
|
87
|
+
const [enabled, setEnabled] = useState(initiallyEnabled);
|
|
88
|
+
// animated values
|
|
89
|
+
const progress = useAnimatedValue(0);
|
|
90
|
+
const height = useAnimatedValue(0);
|
|
91
|
+
// shared values
|
|
92
|
+
const progressSV = useSharedValue(0);
|
|
93
|
+
const heightSV = useSharedValue(0);
|
|
94
|
+
const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);
|
|
95
|
+
const [setKeyboardHandlers, broadcastKeyboardEvents] =
|
|
96
|
+
useSharedHandlers<KeyboardHandler>();
|
|
97
|
+
const [setInputHandlers, broadcastInputEvents] =
|
|
98
|
+
useSharedHandlers<FocusedInputHandler>();
|
|
99
|
+
// memo
|
|
100
|
+
const context = useMemo<KeyboardAnimationContext>(
|
|
101
|
+
() => ({
|
|
102
|
+
enabled,
|
|
103
|
+
animated: { progress: progress, height: Animated.multiply(height, -1) },
|
|
104
|
+
reanimated: { progress: progressSV, height: heightSV },
|
|
105
|
+
layout,
|
|
106
|
+
setKeyboardHandlers,
|
|
107
|
+
setInputHandlers,
|
|
108
|
+
setEnabled,
|
|
109
|
+
}),
|
|
110
|
+
[enabled],
|
|
111
|
+
);
|
|
112
|
+
const style = useMemo(
|
|
113
|
+
() => [
|
|
114
|
+
styles.hidden,
|
|
115
|
+
{ transform: [{ translateX: height }, { translateY: progress }] },
|
|
116
|
+
],
|
|
117
|
+
[],
|
|
118
|
+
);
|
|
119
|
+
const onKeyboardMove = useMemo(
|
|
120
|
+
() =>
|
|
121
|
+
Animated.event(
|
|
122
|
+
[
|
|
123
|
+
{
|
|
124
|
+
nativeEvent: {
|
|
125
|
+
progress,
|
|
126
|
+
height,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
{ useNativeDriver: Platform.OS as string == 'harmony' ? false : true },
|
|
131
|
+
),
|
|
132
|
+
[],
|
|
133
|
+
);
|
|
134
|
+
// handlers
|
|
135
|
+
const updateSharedValues = (event: NativeEvent, platforms: string[]) => {
|
|
136
|
+
"worklet";
|
|
137
|
+
|
|
138
|
+
if (platforms.includes(OS)) {
|
|
139
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
140
|
+
progressSV.value = event.progress;
|
|
141
|
+
heightSV.value = -event.height;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const keyboardHandler = useAnimatedKeyboardHandler(
|
|
145
|
+
{
|
|
146
|
+
onKeyboardMoveStart: (event: NativeEvent) => {
|
|
147
|
+
"worklet";
|
|
148
|
+
|
|
149
|
+
broadcastKeyboardEvents("onStart", event);
|
|
150
|
+
updateSharedValues(event, ["ios"]);
|
|
151
|
+
},
|
|
152
|
+
onKeyboardMove: (event: NativeEvent) => {
|
|
153
|
+
"worklet";
|
|
154
|
+
|
|
155
|
+
broadcastKeyboardEvents("onMove", event);
|
|
156
|
+
updateSharedValues(event, ["android", "harmony"]);
|
|
157
|
+
},
|
|
158
|
+
onKeyboardMoveEnd: (event: NativeEvent) => {
|
|
159
|
+
"worklet";
|
|
160
|
+
broadcastKeyboardEvents("onEnd", event);
|
|
161
|
+
updateSharedValues(event, ["android", "harmony"]);
|
|
162
|
+
},
|
|
163
|
+
onKeyboardMoveInteractive: (event: NativeEvent) => {
|
|
164
|
+
"worklet";
|
|
165
|
+
|
|
166
|
+
updateSharedValues(event, ["android", "ios"]);
|
|
167
|
+
broadcastKeyboardEvents("onInteractive", event);
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
[],
|
|
171
|
+
);
|
|
172
|
+
const inputLayoutHandler = useFocusedInputLayoutHandler(
|
|
173
|
+
{
|
|
174
|
+
onFocusedInputLayoutChanged: (e) => {
|
|
175
|
+
"worklet";
|
|
176
|
+
|
|
177
|
+
if (e.target !== -1) {
|
|
178
|
+
layout.value = e;
|
|
179
|
+
} else {
|
|
180
|
+
layout.value = null;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
[],
|
|
185
|
+
);
|
|
186
|
+
const inputTextHandler = useFocusedInputTextHandler(
|
|
187
|
+
{
|
|
188
|
+
onFocusedInputTextChanged: (e) => {
|
|
189
|
+
"worklet";
|
|
190
|
+
|
|
191
|
+
broadcastInputEvents("onChangeText", e);
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
[],
|
|
195
|
+
);
|
|
196
|
+
const inputSelectionHandler = useFocusedInputSelectionHandler(
|
|
197
|
+
{
|
|
198
|
+
onFocusedInputSelectionChanged: (e) => {
|
|
199
|
+
"worklet";
|
|
200
|
+
broadcastInputEvents("onSelectionChange", e);
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
[],
|
|
204
|
+
);
|
|
205
|
+
// effects
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
if (enabled) {
|
|
208
|
+
applyMonkeyPatch();
|
|
209
|
+
} else {
|
|
210
|
+
revertMonkeyPatch();
|
|
211
|
+
}
|
|
212
|
+
}, [enabled]);
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<KeyboardContext.Provider value={context}>
|
|
216
|
+
<KeyboardControllerViewAnimated
|
|
217
|
+
enabled={enabled}
|
|
218
|
+
onKeyboardMoveReanimated={keyboardHandler}
|
|
219
|
+
onKeyboardMoveStart={OS === "ios" ? onKeyboardMove : undefined}
|
|
220
|
+
onKeyboardMove={OS === "android" ? onKeyboardMove : undefined}
|
|
221
|
+
onKeyboardMoveInteractive={onKeyboardMove}
|
|
222
|
+
onKeyboardMoveEnd={OS as string === "harmony" ? onKeyboardMove : undefined}
|
|
223
|
+
onFocusedInputLayoutChangedReanimated={inputLayoutHandler}
|
|
224
|
+
onFocusedInputTextChangedReanimated={inputTextHandler}
|
|
225
|
+
onFocusedInputSelectionChangedReanimated={inputSelectionHandler}
|
|
226
|
+
navigationBarTranslucent={navigationBarTranslucent}
|
|
227
|
+
statusBarTranslucent={statusBarTranslucent}
|
|
228
|
+
style={styles.container}
|
|
229
|
+
>
|
|
230
|
+
<Reanimated.View style={styles.container}>{children}</Reanimated.View>
|
|
231
|
+
{/* {children} */}
|
|
232
|
+
</KeyboardControllerViewAnimated>
|
|
233
|
+
<Animated.View
|
|
234
|
+
// we are using this small hack, because if the component (where
|
|
235
|
+
// animated value has been used) is unmounted, then animation will
|
|
236
|
+
// stop receiving events (seems like it's react-native optimization).
|
|
237
|
+
// So we need to keep a reference to the animated value, to keep it's
|
|
238
|
+
// always mounted (keep a reference to an animated value).
|
|
239
|
+
//
|
|
240
|
+
// To test why it's needed, try to open screen which consumes Animated.Value
|
|
241
|
+
// then close it and open it again (for example 'Animated transition').
|
|
242
|
+
style={style}
|
|
243
|
+
/>
|
|
244
|
+
</KeyboardContext.Provider>
|
|
245
|
+
);
|
|
246
|
+
};
|
package/src/bindings.native.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { NativeEventEmitter, Platform } from "react-native";
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
FocusedInputEventsModule,
|
|
5
|
-
KeyboardControllerModule,
|
|
6
|
-
KeyboardControllerProps,
|
|
7
|
-
KeyboardEventsModule,
|
|
8
|
-
KeyboardGestureAreaProps,
|
|
9
|
-
WindowDimensionsEventsModule,
|
|
10
|
-
} from "./types";
|
|
11
|
-
|
|
12
|
-
const LINKING_ERROR =
|
|
13
|
-
`The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
|
|
14
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
15
|
-
"- You rebuilt the app after installing the package\n" +
|
|
16
|
-
"- You are not using Expo Go\n";
|
|
17
|
-
|
|
18
|
-
const RCTKeyboardController =
|
|
19
|
-
require("./specs/NativeKeyboardController").default;
|
|
20
|
-
export const KeyboardController = (
|
|
21
|
-
RCTKeyboardController
|
|
22
|
-
? RCTKeyboardController
|
|
23
|
-
: new Proxy(
|
|
24
|
-
{},
|
|
25
|
-
{
|
|
26
|
-
get() {
|
|
27
|
-
throw new Error(LINKING_ERROR);
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
)
|
|
31
|
-
) as KeyboardControllerModule;
|
|
32
|
-
|
|
33
|
-
const KEYBOARD_CONTROLLER_NAMESPACE = "KeyboardController::";
|
|
34
|
-
const eventEmitter = new NativeEventEmitter(KeyboardController);
|
|
35
|
-
|
|
36
|
-
export const KeyboardEvents: KeyboardEventsModule = {
|
|
37
|
-
addListener: (name, cb) =>
|
|
38
|
-
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
|
|
42
|
-
* Use it with cautious.
|
|
43
|
-
*/
|
|
44
|
-
export const FocusedInputEvents: FocusedInputEventsModule = {
|
|
45
|
-
addListener: (name, cb) =>
|
|
46
|
-
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
47
|
-
};
|
|
48
|
-
export const WindowDimensionsEvents: WindowDimensionsEventsModule = {
|
|
49
|
-
addListener: (name, cb) =>
|
|
50
|
-
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
51
|
-
};
|
|
52
|
-
export const KeyboardControllerView: React.FC<KeyboardControllerProps> =
|
|
53
|
-
require("./specs/KeyboardControllerViewNativeComponent").default;
|
|
54
|
-
export const KeyboardGestureArea: React.FC<KeyboardGestureAreaProps> =
|
|
55
|
-
Platform.OS === "android" && Platform.Version >= 30
|
|
56
|
-
? require("./specs/KeyboardGestureAreaNativeComponent").default
|
|
57
|
-
: ({ children }: KeyboardGestureAreaProps) => children;
|
|
1
|
+
import { NativeEventEmitter, Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
FocusedInputEventsModule,
|
|
5
|
+
KeyboardControllerModule,
|
|
6
|
+
KeyboardControllerProps,
|
|
7
|
+
KeyboardEventsModule,
|
|
8
|
+
KeyboardGestureAreaProps,
|
|
9
|
+
WindowDimensionsEventsModule,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
const LINKING_ERROR =
|
|
13
|
+
`The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
|
|
14
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
15
|
+
"- You rebuilt the app after installing the package\n" +
|
|
16
|
+
"- You are not using Expo Go\n";
|
|
17
|
+
|
|
18
|
+
const RCTKeyboardController =
|
|
19
|
+
require("./specs/NativeKeyboardController").default;
|
|
20
|
+
export const KeyboardController = (
|
|
21
|
+
RCTKeyboardController
|
|
22
|
+
? RCTKeyboardController
|
|
23
|
+
: new Proxy(
|
|
24
|
+
{},
|
|
25
|
+
{
|
|
26
|
+
get() {
|
|
27
|
+
throw new Error(LINKING_ERROR);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
)
|
|
31
|
+
) as KeyboardControllerModule;
|
|
32
|
+
|
|
33
|
+
const KEYBOARD_CONTROLLER_NAMESPACE = "KeyboardController::";
|
|
34
|
+
const eventEmitter = new NativeEventEmitter(KeyboardController);
|
|
35
|
+
|
|
36
|
+
export const KeyboardEvents: KeyboardEventsModule = {
|
|
37
|
+
addListener: (name, cb) =>
|
|
38
|
+
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
|
|
42
|
+
* Use it with cautious.
|
|
43
|
+
*/
|
|
44
|
+
export const FocusedInputEvents: FocusedInputEventsModule = {
|
|
45
|
+
addListener: (name, cb) =>
|
|
46
|
+
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
47
|
+
};
|
|
48
|
+
export const WindowDimensionsEvents: WindowDimensionsEventsModule = {
|
|
49
|
+
addListener: (name, cb) =>
|
|
50
|
+
eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
|
|
51
|
+
};
|
|
52
|
+
export const KeyboardControllerView: React.FC<KeyboardControllerProps> =
|
|
53
|
+
require("./specs/KeyboardControllerViewNativeComponent").default;
|
|
54
|
+
export const KeyboardGestureArea: React.FC<KeyboardGestureAreaProps> =
|
|
55
|
+
Platform.OS === "android" && Platform.Version >= 30
|
|
56
|
+
? require("./specs/KeyboardGestureAreaNativeComponent").default
|
|
57
|
+
: ({ children }: KeyboardGestureAreaProps) => children;
|