react-native-keyboard-controller 1.17.1 → 1.17.2
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/README.md +24 -23
- package/lib/commonjs/animated.js +23 -7
- package/lib/commonjs/animated.js.map +1 -1
- package/lib/commonjs/bindings.js +19 -0
- package/lib/commonjs/bindings.js.map +1 -1
- package/lib/commonjs/components/KeyboardAvoidingView/index.js +11 -2
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +51 -36
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +17 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js +13 -0
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardToolbar/index.js +31 -22
- package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/commonjs/context.js +16 -0
- package/lib/commonjs/context.js.map +1 -1
- package/lib/commonjs/hooks/index.js +164 -0
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useKeyboardState/index.js +21 -0
- package/lib/commonjs/hooks/useKeyboardState/index.js.map +1 -1
- package/lib/commonjs/internal.js +21 -0
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/commonjs/module.js +4 -0
- package/lib/commonjs/module.js.map +1 -1
- package/lib/commonjs/monkey-patch.android.js +0 -5
- package/lib/commonjs/monkey-patch.android.js.map +1 -1
- package/lib/commonjs/{types.js → types/hooks.js} +1 -1
- package/lib/commonjs/types/hooks.js.map +1 -0
- package/lib/commonjs/types/index.js +50 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/types/internal.js +6 -0
- package/lib/commonjs/types/internal.js.map +1 -0
- package/lib/commonjs/types/module.js +6 -0
- package/lib/commonjs/types/module.js.map +1 -0
- package/lib/commonjs/types/views.js +6 -0
- package/lib/commonjs/types/views.js.map +1 -0
- package/lib/commonjs/views/OverKeyboardView/index.js +18 -4
- package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -1
- package/lib/module/animated.js +23 -7
- package/lib/module/animated.js.map +1 -1
- package/lib/module/bindings.js +19 -0
- package/lib/module/bindings.js.map +1 -1
- package/lib/module/components/KeyboardAvoidingView/index.js +11 -2
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +51 -36
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +17 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/module/components/KeyboardStickyView/index.js +13 -0
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/KeyboardToolbar/index.js +31 -22
- package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
- package/lib/module/context.js +16 -0
- package/lib/module/context.js.map +1 -1
- package/lib/module/hooks/index.js +164 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useKeyboardState/index.js +21 -0
- package/lib/module/hooks/useKeyboardState/index.js.map +1 -1
- package/lib/module/internal.js +21 -0
- package/lib/module/internal.js.map +1 -1
- package/lib/module/module.js +4 -0
- package/lib/module/module.js.map +1 -1
- package/lib/module/monkey-patch.android.js +0 -5
- package/lib/module/monkey-patch.android.js.map +1 -1
- package/lib/module/types/hooks.js +2 -0
- package/lib/module/types/hooks.js.map +1 -0
- package/lib/module/types/index.js +5 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/internal.js +2 -0
- package/lib/module/types/internal.js.map +1 -0
- package/lib/module/types/module.js +2 -0
- package/lib/module/types/module.js.map +1 -0
- package/lib/module/types/views.js +2 -0
- package/lib/module/types/views.js.map +1 -0
- package/lib/module/views/OverKeyboardView/index.js +18 -4
- package/lib/module/views/OverKeyboardView/index.js.map +1 -1
- package/lib/typescript/animated.d.ts +20 -6
- package/lib/typescript/bindings.d.ts +19 -0
- package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +11 -2
- package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +23 -6
- package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +17 -1
- package/lib/typescript/components/KeyboardStickyView/index.d.ts +15 -2
- package/lib/typescript/components/KeyboardToolbar/index.d.ts +13 -2
- package/lib/typescript/context.d.ts +32 -0
- package/lib/typescript/hooks/index.d.ts +157 -0
- package/lib/typescript/hooks/useKeyboardState/index.d.ts +20 -0
- package/lib/typescript/internal.d.ts +21 -0
- package/lib/typescript/module.d.ts +3 -0
- package/lib/typescript/{types.d.ts → types/hooks.d.ts} +72 -78
- package/lib/typescript/types/index.d.ts +4 -0
- package/lib/typescript/types/internal.d.ts +17 -0
- package/lib/typescript/types/module.d.ts +91 -0
- package/lib/typescript/types/views.d.ts +45 -0
- package/lib/typescript/views/OverKeyboardView/index.d.ts +14 -1
- package/package.json +2 -1
- package/src/animated.tsx +27 -12
- package/src/bindings.ts +19 -0
- package/src/components/KeyboardAvoidingView/index.tsx +11 -2
- package/src/components/KeyboardAwareScrollView/index.tsx +54 -39
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +17 -1
- package/src/components/KeyboardStickyView/index.tsx +14 -1
- package/src/components/KeyboardToolbar/index.tsx +31 -19
- package/src/context.ts +33 -0
- package/src/hooks/index.ts +157 -0
- package/src/hooks/useKeyboardState/index.ts +20 -0
- package/src/internal.ts +21 -0
- package/src/module.ts +3 -0
- package/src/monkey-patch.android.ts +3 -6
- package/src/{types.ts → types/hooks.ts} +72 -105
- package/src/types/index.ts +4 -0
- package/src/types/internal.ts +24 -0
- package/src/types/module.ts +105 -0
- package/src/types/views.ts +46 -0
- package/src/views/OverKeyboardView/index.tsx +15 -4
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/types.js +0 -2
- package/lib/module/types.js.map +0 -1
package/src/hooks/index.ts
CHANGED
|
@@ -8,6 +8,20 @@ import type { AnimatedContext, ReanimatedContext } from "../context";
|
|
|
8
8
|
import type { FocusedInputHandler, KeyboardHandler } from "../types";
|
|
9
9
|
import type { DependencyList } from "react";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Hook that sets the Android soft input mode to adjust resize on mount and
|
|
13
|
+
* restores default mode on unmount. This ensures the keyboard behavior is consistent
|
|
14
|
+
* on all Android versions.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#setinputmode-|Documentation} page for more details.
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* function MyComponent() {
|
|
20
|
+
* useResizeMode();
|
|
21
|
+
* return <View />;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
11
25
|
export const useResizeMode = () => {
|
|
12
26
|
useEffect(() => {
|
|
13
27
|
KeyboardController.setInputMode(
|
|
@@ -18,6 +32,20 @@ export const useResizeMode = () => {
|
|
|
18
32
|
}, []);
|
|
19
33
|
};
|
|
20
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Hook that provides animated (`height`/`progress`) values for tracking keyboard movement.
|
|
37
|
+
* Automatically sets the resize mode for Android.
|
|
38
|
+
*
|
|
39
|
+
* @returns Object {@link AnimatedContext|containing} animated values for keyboard movement.
|
|
40
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/keyboard/use-keyboard-animation|Documentation} page for more details.
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* function MyComponent() {
|
|
44
|
+
* const { height, progress } = useKeyboardAnimation();
|
|
45
|
+
* return <Animated.View style={{ transform: [{ translateY: height }] }} />;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
21
49
|
export const useKeyboardAnimation = (): AnimatedContext => {
|
|
22
50
|
useResizeMode();
|
|
23
51
|
const context = useKeyboardContext();
|
|
@@ -25,6 +53,20 @@ export const useKeyboardAnimation = (): AnimatedContext => {
|
|
|
25
53
|
return context.animated;
|
|
26
54
|
};
|
|
27
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Hook that provides reanimated (`height`/`progress`) values for tracking keyboard movement.
|
|
58
|
+
* Automatically sets the resize mode for Android.
|
|
59
|
+
*
|
|
60
|
+
* @returns Object {@link ReanimatedContext|containing} reanimated values for keyboard movement.
|
|
61
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/keyboard/use-reanimated-keyboard-animation|Documentation} page for more details.
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* function MyComponent() {
|
|
65
|
+
* const { height, progress } = useReanimatedKeyboardAnimation();
|
|
66
|
+
* return <Reanimated.View style={{ transform: [{ translateY: height }] }} />;
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
28
70
|
export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
|
|
29
71
|
useResizeMode();
|
|
30
72
|
const context = useKeyboardContext();
|
|
@@ -32,6 +74,37 @@ export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
|
|
|
32
74
|
return context.reanimated;
|
|
33
75
|
};
|
|
34
76
|
|
|
77
|
+
/**
|
|
78
|
+
* An alternative to {@link useKeyboardHandler} that doesn't set resize mode on mount. If your
|
|
79
|
+
* app already uses `adjustResize`, then you can use this hook instead of `useKeyboardHandler`.
|
|
80
|
+
*
|
|
81
|
+
* @param handler - Object containing keyboard event handlers.
|
|
82
|
+
* @param [deps] - Dependencies array for the effect.
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* function MyComponent() {
|
|
86
|
+
* const height = useSharedValue(0);
|
|
87
|
+
* const progress = useSharedValue(0);
|
|
88
|
+
*
|
|
89
|
+
* useGenericKeyboardHandler({
|
|
90
|
+
* onMove: (e) => {
|
|
91
|
+
* "worklet";
|
|
92
|
+
*
|
|
93
|
+
* height.value = e.height;
|
|
94
|
+
* progress.value = e.progress;
|
|
95
|
+
* },
|
|
96
|
+
* onEnd: (e) => {
|
|
97
|
+
* "worklet";
|
|
98
|
+
*
|
|
99
|
+
* height.value = e.height;
|
|
100
|
+
* progress.value = e.progress;
|
|
101
|
+
* },
|
|
102
|
+
* }, []);
|
|
103
|
+
*
|
|
104
|
+
* return <Reanimated.View style={{ height: height }] }} />;
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
35
108
|
export function useGenericKeyboardHandler(
|
|
36
109
|
handler: KeyboardHandler,
|
|
37
110
|
deps?: DependencyList,
|
|
@@ -45,6 +118,37 @@ export function useGenericKeyboardHandler(
|
|
|
45
118
|
}, deps);
|
|
46
119
|
}
|
|
47
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Hook that gives an access to each aspect of keyboard movement with workletized `onStart`/`onMove`/`onInteractive`/`onEnd` handlers.
|
|
123
|
+
*
|
|
124
|
+
* @param handler - Object containing keyboard event handlers.
|
|
125
|
+
* @param [deps] - Dependencies array for the effect.
|
|
126
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/keyboard/use-keyboard-handler|Documentation} page for more details.
|
|
127
|
+
* @example
|
|
128
|
+
* ```tsx
|
|
129
|
+
* function MyComponent() {
|
|
130
|
+
* const height = useSharedValue(0);
|
|
131
|
+
* const progress = useSharedValue(0);
|
|
132
|
+
*
|
|
133
|
+
* useKeyboardHandler({
|
|
134
|
+
* onMove: (e) => {
|
|
135
|
+
* "worklet";
|
|
136
|
+
*
|
|
137
|
+
* height.value = e.height;
|
|
138
|
+
* progress.value = e.progress;
|
|
139
|
+
* },
|
|
140
|
+
* onEnd: (e) => {
|
|
141
|
+
* "worklet";
|
|
142
|
+
*
|
|
143
|
+
* height.value = e.height;
|
|
144
|
+
* progress.value = e.progress;
|
|
145
|
+
* },
|
|
146
|
+
* }, []);
|
|
147
|
+
*
|
|
148
|
+
* return <Reanimated.View style={{ height: height }] }} />;
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
48
152
|
export function useKeyboardHandler(
|
|
49
153
|
handler: KeyboardHandler,
|
|
50
154
|
deps?: DependencyList,
|
|
@@ -53,18 +157,71 @@ export function useKeyboardHandler(
|
|
|
53
157
|
useGenericKeyboardHandler(handler, deps);
|
|
54
158
|
}
|
|
55
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Hook for controlling keyboard controller module.
|
|
162
|
+
* Allows to disable/enable it and check the actual state (whether it's enabled or not).
|
|
163
|
+
* When disabled it fallbacks to default android keyboard handling and stops tracking all
|
|
164
|
+
* the events that are exposed from this library.
|
|
165
|
+
*
|
|
166
|
+
* @property {Function} setEnabled - Function to enable/disable keyboard handling.
|
|
167
|
+
* @property {boolean} enabled - Current enabled state.
|
|
168
|
+
* @returns Object containing keyboard control functions and state.
|
|
169
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/module/use-keyboard-controller|Documentation} page for more details.
|
|
170
|
+
* @example
|
|
171
|
+
* ```tsx
|
|
172
|
+
* function MyComponent() {
|
|
173
|
+
* const { setEnabled, enabled } = useKeyboardController();
|
|
174
|
+
* return (
|
|
175
|
+
* <Button
|
|
176
|
+
* title={enabled ? 'Disable' : 'Enable'}
|
|
177
|
+
* onPress={() => setEnabled(!enabled)}
|
|
178
|
+
* />
|
|
179
|
+
* );
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
56
183
|
export function useKeyboardController() {
|
|
57
184
|
const context = useKeyboardContext();
|
|
58
185
|
|
|
59
186
|
return { setEnabled: context.setEnabled, enabled: context.enabled };
|
|
60
187
|
}
|
|
61
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Hook that provides access to the layout of the currently focused input.
|
|
191
|
+
*
|
|
192
|
+
* @returns Object containing reanimated values for focused input.
|
|
193
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/input/use-reanimated-focused-input|Documentation} page for more details.
|
|
194
|
+
* @example
|
|
195
|
+
* ```tsx
|
|
196
|
+
* function MyComponent() {
|
|
197
|
+
* const { input } = useReanimatedFocusedInput();
|
|
198
|
+
* return <Reanimated.View style={{ height: input.value?.layout.height }} />;
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
62
202
|
export function useReanimatedFocusedInput() {
|
|
63
203
|
const context = useKeyboardContext();
|
|
64
204
|
|
|
65
205
|
return { input: context.layout };
|
|
66
206
|
}
|
|
67
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Hook for handling focused input events, such as changes of selection, text etc.
|
|
210
|
+
*
|
|
211
|
+
* @param handler - Object containing focused input event handlers.
|
|
212
|
+
* @param [deps] - Dependencies array for the effect.
|
|
213
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/input/use-focused-input-handler|Documentation} page for more details.
|
|
214
|
+
* @example
|
|
215
|
+
* ```tsx
|
|
216
|
+
* function MyComponent() {
|
|
217
|
+
* useFocusedInputHandler({
|
|
218
|
+
* onChangeText: (e) => console.log('Text changed:', e.text),
|
|
219
|
+
* onSelectionChange: (e) => console.log('Selection changed:', e.selection)
|
|
220
|
+
* });
|
|
221
|
+
* return <View />;
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
68
225
|
export function useFocusedInputHandler(
|
|
69
226
|
handler: FocusedInputHandler,
|
|
70
227
|
deps?: DependencyList,
|
|
@@ -12,6 +12,26 @@ const getLatestState = () => ({
|
|
|
12
12
|
isVisible: KeyboardController.isVisible(),
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* React Hook that represents the current keyboard state on iOS and Android.
|
|
17
|
+
* It tracks keyboard visibility, height, appearance, type and other properties.
|
|
18
|
+
* This hook subscribes to keyboard events and updates the state reactively.
|
|
19
|
+
*
|
|
20
|
+
* @returns Object {@link KeyboardState|containing} keyboard state information.
|
|
21
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/keyboard/use-keyboard-state|Documentation} page for more details.
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* function MyComponent() {
|
|
25
|
+
* const { isVisible, height } = useKeyboardState();
|
|
26
|
+
* return (
|
|
27
|
+
* <View>
|
|
28
|
+
* <Text>Keyboard is {isVisible ? 'visible' : 'hidden'}</Text>
|
|
29
|
+
* <Text>Keyboard height: {height}</Text>
|
|
30
|
+
* </View>
|
|
31
|
+
* );
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
15
35
|
export const useKeyboardState = (): KeyboardState => {
|
|
16
36
|
const [state, setState] = useState(getLatestState);
|
|
17
37
|
|
package/src/internal.ts
CHANGED
|
@@ -7,6 +7,20 @@ import { findNodeHandle } from "./utils/findNodeHandle";
|
|
|
7
7
|
type EventHandler = (event: never) => void;
|
|
8
8
|
type ComponentOrHandle = Parameters<typeof findNodeHandle>[0];
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* An internal hook that helps to register workletized event handlers.
|
|
12
|
+
*
|
|
13
|
+
* @param map - Map of event handlers and their names.
|
|
14
|
+
* @param viewTagRef - Ref to the view that produces events.
|
|
15
|
+
* @returns A function that registers supplied event handlers.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const setKeyboardHandlers = useEventHandlerRegistration<KeyboardHandler>(
|
|
19
|
+
* keyboardEventsMap,
|
|
20
|
+
* viewTagRef,
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
10
24
|
export function useEventHandlerRegistration<
|
|
11
25
|
H extends Partial<Record<string, EventHandler>>,
|
|
12
26
|
>(
|
|
@@ -68,7 +82,14 @@ export function useEventHandlerRegistration<
|
|
|
68
82
|
* and therefore consumes less memory. We can not use a variant from
|
|
69
83
|
* RN, since this library supports earlier versions of RN.
|
|
70
84
|
*
|
|
85
|
+
* @param initialValue - Initial value of the animated value (numeric).
|
|
86
|
+
* @param config - Additional {@link Animated.AnimatedConfig|configuration} for the animated value.
|
|
87
|
+
* @returns Properly memoized {@link Animated.Value|Animated} value.
|
|
71
88
|
* @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const progress = useAnimatedValue(0);
|
|
92
|
+
* ```
|
|
72
93
|
*/
|
|
73
94
|
export function useAnimatedValue(
|
|
74
95
|
initialValue: number,
|
package/src/module.ts
CHANGED
|
@@ -47,6 +47,9 @@ const dismiss = async (options?: DismissOptions): Promise<void> => {
|
|
|
47
47
|
const isVisible = () => !isClosed;
|
|
48
48
|
const state = () => lastState;
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* KeyboardController module. Helps to perform imperative actions/checks with keyboard.
|
|
52
|
+
*/
|
|
50
53
|
export const KeyboardController: KeyboardControllerModule = {
|
|
51
54
|
setDefaultMode: KeyboardControllerNative.setDefaultMode,
|
|
52
55
|
setInputMode: KeyboardControllerNative.setInputMode,
|
|
@@ -20,12 +20,9 @@ const ModifiedNativeAndroidManager = {
|
|
|
20
20
|
setTranslucent: (translucent: boolean): void => {
|
|
21
21
|
RCTStatusBarManagerCompat.setTranslucent(translucent);
|
|
22
22
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* - 'dark-content'
|
|
27
|
-
*/
|
|
28
|
-
setStyle: (statusBarStyle?: string): void => {
|
|
23
|
+
setStyle: (
|
|
24
|
+
statusBarStyle?: "default" | "dark-content" | "light-content",
|
|
25
|
+
): void => {
|
|
29
26
|
RCTStatusBarManagerCompat.setStyle(statusBarStyle);
|
|
30
27
|
},
|
|
31
28
|
setHidden: (hidden: boolean): void => {
|
|
@@ -1,44 +1,60 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
EmitterSubscription,
|
|
4
|
-
NativeSyntheticEvent,
|
|
5
|
-
TextInputProps,
|
|
6
|
-
ViewProps,
|
|
7
|
-
} from "react-native";
|
|
1
|
+
import type { NativeSyntheticEvent, ViewProps } from "react-native";
|
|
8
2
|
|
|
9
3
|
// DirectEventHandler events declaration
|
|
10
4
|
export type NativeEvent = {
|
|
5
|
+
/** A value between `0` and `1` indicating keyboard position, where `0` means keyboard is closed and `1` means keyboard is fully visible. */
|
|
11
6
|
progress: number;
|
|
7
|
+
/** Height of the keyboard. */
|
|
12
8
|
height: number;
|
|
9
|
+
/** Duration of the keyboard animation. */
|
|
13
10
|
duration: number;
|
|
11
|
+
/** Tag of the focused `TextInput`. */
|
|
14
12
|
target: number;
|
|
15
13
|
};
|
|
16
14
|
export type FocusedInputLayoutChangedEvent = {
|
|
15
|
+
/** Tag of the focused `TextInput`. */
|
|
17
16
|
target: number;
|
|
17
|
+
/** Tag of the parent `ScrollView`. */
|
|
18
18
|
parentScrollViewTarget: number;
|
|
19
19
|
layout: {
|
|
20
|
+
/** X coordinate of the focused `TextInput`. */
|
|
20
21
|
x: number;
|
|
22
|
+
/** Y coordinate of the focused `TextInput`. */
|
|
21
23
|
y: number;
|
|
24
|
+
/** Width of the focused `TextInput`. */
|
|
22
25
|
width: number;
|
|
26
|
+
/** Height of the focused `TextInput`. */
|
|
23
27
|
height: number;
|
|
28
|
+
/** X coordinate of the focused `TextInput` relative to the screen. */
|
|
24
29
|
absoluteX: number;
|
|
30
|
+
/** Y coordinate of the focused `TextInput` relative to the screen. */
|
|
25
31
|
absoluteY: number;
|
|
26
32
|
};
|
|
27
33
|
};
|
|
28
34
|
export type FocusedInputTextChangedEvent = {
|
|
35
|
+
/** Text that user typed in the focused `TextInput`. */
|
|
29
36
|
text: string;
|
|
30
37
|
};
|
|
31
38
|
export type FocusedInputSelectionChangedEvent = {
|
|
39
|
+
/** Tag of the focused `TextInput`. */
|
|
32
40
|
target: number;
|
|
33
41
|
selection: {
|
|
42
|
+
/** Start of the selection. Represents top-left point of rectangle. */
|
|
34
43
|
start: {
|
|
44
|
+
/** X coordinate of the selection start (relative to the `TextInput`). */
|
|
35
45
|
x: number;
|
|
46
|
+
/** Y coordinate of the selection start (relative to the `TextInput`). */
|
|
36
47
|
y: number;
|
|
48
|
+
/** The start of selection. */
|
|
37
49
|
position: number;
|
|
38
50
|
};
|
|
51
|
+
/** End of the selection. Represents bottom-right point of rectangle. */
|
|
39
52
|
end: {
|
|
53
|
+
/** X coordinate of the selection end (relative to the `TextInput`). */
|
|
40
54
|
x: number;
|
|
55
|
+
/** Y coordinate of the selection end (relative to the `TextInput`). */
|
|
41
56
|
y: number;
|
|
57
|
+
/** The end of selection. */
|
|
42
58
|
position: number;
|
|
43
59
|
};
|
|
44
60
|
};
|
|
@@ -93,104 +109,6 @@ export type KeyboardControllerProps = {
|
|
|
93
109
|
enabled?: boolean;
|
|
94
110
|
} & ViewProps;
|
|
95
111
|
|
|
96
|
-
export type KeyboardGestureAreaProps = {
|
|
97
|
-
interpolator?: "ios" | "linear";
|
|
98
|
-
/**
|
|
99
|
-
* Whether to allow to show a keyboard from dismissed state by swipe up.
|
|
100
|
-
* Default to `false`.
|
|
101
|
-
*/
|
|
102
|
-
showOnSwipeUp?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Whether to allow to control a keyboard by gestures. The strategy how
|
|
105
|
-
* it should be controlled is determined by `interpolator` property.
|
|
106
|
-
* Defaults to `true`.
|
|
107
|
-
*/
|
|
108
|
-
enableSwipeToDismiss?: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Extra distance to the keyboard.
|
|
111
|
-
*/
|
|
112
|
-
offset?: number;
|
|
113
|
-
/**
|
|
114
|
-
* A corresponding `nativeID` value from the corresponding `TextInput`.
|
|
115
|
-
*/
|
|
116
|
-
textInputNativeID?: string;
|
|
117
|
-
} & ViewProps;
|
|
118
|
-
export type OverKeyboardViewProps = PropsWithChildren<{
|
|
119
|
-
visible: boolean;
|
|
120
|
-
}>;
|
|
121
|
-
|
|
122
|
-
export type Direction = "next" | "prev" | "current";
|
|
123
|
-
export type DismissOptions = {
|
|
124
|
-
keepFocus: boolean;
|
|
125
|
-
};
|
|
126
|
-
export type KeyboardControllerModule = {
|
|
127
|
-
// android only
|
|
128
|
-
setDefaultMode: () => void;
|
|
129
|
-
setInputMode: (mode: number) => void;
|
|
130
|
-
// all platforms
|
|
131
|
-
dismiss: (options?: DismissOptions) => Promise<void>;
|
|
132
|
-
setFocusTo: (direction: Direction) => void;
|
|
133
|
-
isVisible: () => boolean;
|
|
134
|
-
state: () => KeyboardEventData;
|
|
135
|
-
};
|
|
136
|
-
export type KeyboardControllerNativeModule = {
|
|
137
|
-
// android only
|
|
138
|
-
setDefaultMode: () => void;
|
|
139
|
-
setInputMode: (mode: number) => void;
|
|
140
|
-
// all platforms
|
|
141
|
-
dismiss: (keepFocus: boolean) => void;
|
|
142
|
-
setFocusTo: (direction: Direction) => void;
|
|
143
|
-
// native event module stuff
|
|
144
|
-
addListener: (eventName: string) => void;
|
|
145
|
-
removeListeners: (count: number) => void;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// Event module declarations
|
|
149
|
-
export type KeyboardControllerEvents =
|
|
150
|
-
| "keyboardWillShow"
|
|
151
|
-
| "keyboardDidShow"
|
|
152
|
-
| "keyboardWillHide"
|
|
153
|
-
| "keyboardDidHide";
|
|
154
|
-
export type KeyboardEventData = {
|
|
155
|
-
height: number;
|
|
156
|
-
duration: number;
|
|
157
|
-
timestamp: number;
|
|
158
|
-
target: number;
|
|
159
|
-
type: NonNullable<TextInputProps["keyboardType"]>;
|
|
160
|
-
appearance: NonNullable<TextInputProps["keyboardAppearance"]>;
|
|
161
|
-
};
|
|
162
|
-
export type KeyboardState = {
|
|
163
|
-
isVisible: boolean;
|
|
164
|
-
} & KeyboardEventData;
|
|
165
|
-
export type KeyboardEventsModule = {
|
|
166
|
-
addListener: (
|
|
167
|
-
name: KeyboardControllerEvents,
|
|
168
|
-
cb: (e: KeyboardEventData) => void,
|
|
169
|
-
) => EmitterSubscription;
|
|
170
|
-
};
|
|
171
|
-
export type FocusedInputAvailableEvents = "focusDidSet";
|
|
172
|
-
export type FocusedInputEventData = {
|
|
173
|
-
current: number;
|
|
174
|
-
count: number;
|
|
175
|
-
};
|
|
176
|
-
export type FocusedInputEventsModule = {
|
|
177
|
-
addListener: (
|
|
178
|
-
name: FocusedInputAvailableEvents,
|
|
179
|
-
cb: (e: FocusedInputEventData) => void,
|
|
180
|
-
) => EmitterSubscription;
|
|
181
|
-
};
|
|
182
|
-
export type WindowDimensionsAvailableEvents = "windowDidResize";
|
|
183
|
-
export type WindowDimensionsEventData = {
|
|
184
|
-
width: number;
|
|
185
|
-
height: number;
|
|
186
|
-
};
|
|
187
|
-
export type WindowDimensionsEventsModule = {
|
|
188
|
-
addListener: (
|
|
189
|
-
name: WindowDimensionsAvailableEvents,
|
|
190
|
-
cb: (e: WindowDimensionsEventData) => void,
|
|
191
|
-
) => EmitterSubscription;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
112
|
// reanimated hook declaration
|
|
195
113
|
export type KeyboardHandlerHook<TContext, Event> = (
|
|
196
114
|
handlers: {
|
|
@@ -232,14 +150,63 @@ export type FocusedInputSelectionHandlerHook<TContext, Event> = (
|
|
|
232
150
|
// package types
|
|
233
151
|
export type Handlers<T> = Record<string, T | undefined>;
|
|
234
152
|
export type KeyboardHandler = Partial<{
|
|
153
|
+
/**
|
|
154
|
+
* A callback that gets invoked when keyboard starts its movement.
|
|
155
|
+
* The event contains DESTINATION values.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* onStart: (e) => {
|
|
160
|
+
* "worklet";
|
|
161
|
+
*
|
|
162
|
+
* const willKeyboardAppear = e.progress === 1;
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
235
166
|
onStart: (e: NativeEvent) => void;
|
|
167
|
+
/**
|
|
168
|
+
* A callback that gets involved every frame when keyboard changes its position.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* onMove: (e) => {
|
|
173
|
+
* "worklet";
|
|
174
|
+
*
|
|
175
|
+
* const keyboardHeight = e.height;
|
|
176
|
+
* }
|
|
177
|
+
*/
|
|
236
178
|
onMove: (e: NativeEvent) => void;
|
|
179
|
+
/**
|
|
180
|
+
* A callback that gets invoked when keyboard finished its movement.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* onEnd: (e) => {
|
|
185
|
+
* "worklet";
|
|
186
|
+
*
|
|
187
|
+
* const isKeyboardShown = e.progress === 1;
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
237
191
|
onEnd: (e: NativeEvent) => void;
|
|
192
|
+
/**
|
|
193
|
+
* A callback that gets invoked every frame when keyboard changes its position due to interactive dismissal.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* onInteractive: (e) => {
|
|
198
|
+
* "worklet";
|
|
199
|
+
*
|
|
200
|
+
* const keyboardHeight = e.height;
|
|
201
|
+
* }
|
|
202
|
+
*/
|
|
238
203
|
onInteractive: (e: NativeEvent) => void;
|
|
239
204
|
}>;
|
|
240
205
|
export type KeyboardHandlers = Handlers<KeyboardHandler>;
|
|
241
206
|
export type FocusedInputHandler = Partial<{
|
|
207
|
+
/** A callback that gets invoked every time when the text changes in focused input. */
|
|
242
208
|
onChangeText: (e: FocusedInputTextChangedEvent) => void;
|
|
209
|
+
/** A callback that gets invoked every time when the selection (cursor) coordinates change in focused input. */
|
|
243
210
|
onSelectionChange: (e: FocusedInputSelectionChangedEvent) => void;
|
|
244
211
|
}>;
|
|
245
212
|
export type FocusedInputHandlers = Handlers<FocusedInputHandler>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { EmitterSubscription } from "react-native";
|
|
2
|
+
|
|
3
|
+
export type FocusedInputAvailableEvents = "focusDidSet";
|
|
4
|
+
export type FocusedInputEventData = {
|
|
5
|
+
current: number;
|
|
6
|
+
count: number;
|
|
7
|
+
};
|
|
8
|
+
export type FocusedInputEventsModule = {
|
|
9
|
+
addListener: (
|
|
10
|
+
name: FocusedInputAvailableEvents,
|
|
11
|
+
cb: (e: FocusedInputEventData) => void,
|
|
12
|
+
) => EmitterSubscription;
|
|
13
|
+
};
|
|
14
|
+
export type WindowDimensionsAvailableEvents = "windowDidResize";
|
|
15
|
+
export type WindowDimensionsEventData = {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
};
|
|
19
|
+
export type WindowDimensionsEventsModule = {
|
|
20
|
+
addListener: (
|
|
21
|
+
name: WindowDimensionsAvailableEvents,
|
|
22
|
+
cb: (e: WindowDimensionsEventData) => void,
|
|
23
|
+
) => EmitterSubscription;
|
|
24
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { EmitterSubscription, TextInputProps } from "react-native";
|
|
2
|
+
|
|
3
|
+
// Event module declarations
|
|
4
|
+
export type KeyboardControllerEvents =
|
|
5
|
+
| "keyboardWillShow"
|
|
6
|
+
| "keyboardDidShow"
|
|
7
|
+
| "keyboardWillHide"
|
|
8
|
+
| "keyboardDidHide";
|
|
9
|
+
export type KeyboardEventData = {
|
|
10
|
+
/** Height of the keyboard. */
|
|
11
|
+
height: number;
|
|
12
|
+
/** Duration of the keyboard animation. */
|
|
13
|
+
duration: number;
|
|
14
|
+
/** Timestamp of the last keyboard event. */
|
|
15
|
+
timestamp: number;
|
|
16
|
+
/** Tag of the focused `TextInput`. */
|
|
17
|
+
target: number;
|
|
18
|
+
/** `keyboardType` property from focused `TextInput`. */
|
|
19
|
+
type: NonNullable<TextInputProps["keyboardType"]>;
|
|
20
|
+
/** Keyboard appearance. Can be one of `default`, `dark` or `light`. */
|
|
21
|
+
appearance: NonNullable<TextInputProps["keyboardAppearance"]>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* An object that represent current keyboard state.
|
|
25
|
+
*/
|
|
26
|
+
export type KeyboardState = {
|
|
27
|
+
/** Whether the keyboard is currently visible. */
|
|
28
|
+
isVisible: boolean;
|
|
29
|
+
} & KeyboardEventData;
|
|
30
|
+
export type KeyboardEventsModule = {
|
|
31
|
+
/**
|
|
32
|
+
* The `addListener` function connects a JavaScript function to an identified native
|
|
33
|
+
* keyboard notification event.
|
|
34
|
+
*
|
|
35
|
+
* This function then returns the reference to the listener.
|
|
36
|
+
*
|
|
37
|
+
* `name` is the string that identifies the event you're listening for. This
|
|
38
|
+
* can be any of the following:
|
|
39
|
+
*
|
|
40
|
+
* - `keyboardWillShow`;
|
|
41
|
+
* - `keyboardDidShow`;
|
|
42
|
+
* - `keyboardWillHide`;
|
|
43
|
+
* - `keyboardDidHide`.
|
|
44
|
+
*/
|
|
45
|
+
addListener: (
|
|
46
|
+
name: KeyboardControllerEvents,
|
|
47
|
+
cb: (e: KeyboardEventData) => void,
|
|
48
|
+
) => EmitterSubscription;
|
|
49
|
+
};
|
|
50
|
+
export type Direction = "next" | "prev" | "current";
|
|
51
|
+
export type DismissOptions = {
|
|
52
|
+
/**
|
|
53
|
+
* A boolean property indicating whether focus should be kept on the input after dismissing the keyboard. Default is `false`.
|
|
54
|
+
*/
|
|
55
|
+
keepFocus: boolean;
|
|
56
|
+
};
|
|
57
|
+
export type KeyboardControllerModule = {
|
|
58
|
+
// android only
|
|
59
|
+
/**
|
|
60
|
+
* Sets default `windowSoftInputMode` (the one that declared in `AndroidManifest.xml`).
|
|
61
|
+
*
|
|
62
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#setdefaultmode-|docs} page for more details.
|
|
63
|
+
*/
|
|
64
|
+
setDefaultMode: () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Changes `windowSoftInputMode` on Android. @see AndroidSoftInputModes for all possible values and {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#setinputmode-|docs} page for more details.
|
|
67
|
+
*/
|
|
68
|
+
setInputMode: (mode: number) => void;
|
|
69
|
+
// all platforms
|
|
70
|
+
/**
|
|
71
|
+
* Dismisses the active keyboard. Removes a focus by default, but allows to pass `{keepFocus: true}` to keep focus.
|
|
72
|
+
*
|
|
73
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#dismiss|docs} page for more details.
|
|
74
|
+
*/
|
|
75
|
+
dismiss: (options?: DismissOptions) => Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Moves focus to the specified direction (`next`, `prev` or `current` to restore a focus).
|
|
78
|
+
*
|
|
79
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#setfocusto|docs} page for more details.
|
|
80
|
+
*/
|
|
81
|
+
setFocusTo: (direction: Direction) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Whether the keyboard is fully visible.
|
|
84
|
+
*
|
|
85
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#isvisible|docs} page for more details.
|
|
86
|
+
*/
|
|
87
|
+
isVisible: () => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Method that returns current keyboard state.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#state|docs} page for more details.
|
|
92
|
+
*/
|
|
93
|
+
state: () => KeyboardEventData;
|
|
94
|
+
};
|
|
95
|
+
export type KeyboardControllerNativeModule = {
|
|
96
|
+
// android only
|
|
97
|
+
setDefaultMode: () => void;
|
|
98
|
+
setInputMode: (mode: number) => void;
|
|
99
|
+
// all platforms
|
|
100
|
+
dismiss: (keepFocus: boolean) => void;
|
|
101
|
+
setFocusTo: (direction: Direction) => void;
|
|
102
|
+
// native event module stuff
|
|
103
|
+
addListener: (eventName: string) => void;
|
|
104
|
+
removeListeners: (count: number) => void;
|
|
105
|
+
};
|