react-native-keyboard-controller 1.17.1 → 1.17.3
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/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ThemedReactContext.kt +20 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/listeners/KeyboardAnimationCallback.kt +4 -0
- package/ios/KeyboardControllerModule.mm +2 -0
- package/ios/views/KeyboardControllerView.mm +18 -0
- package/ios/views/KeyboardControllerViewManager.swift +19 -0
- 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 +14 -4
- package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +54 -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/hooks/useWindowDimensions/index.js +29 -6
- package/lib/commonjs/hooks/useWindowDimensions/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 +14 -4
- package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +56 -38
- 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/hooks/useWindowDimensions/index.js +28 -1
- package/lib/module/hooks/useWindowDimensions/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/hooks/useWindowDimensions/index.d.ts +2 -1
- 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 +14 -4
- package/src/components/KeyboardAwareScrollView/index.tsx +60 -40
- 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/hooks/useWindowDimensions/index.ts +41 -1
- 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/hooks/useWindowDimensions/index.android.js +0 -34
- package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +0 -1
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/hooks/useWindowDimensions/index.android.js +0 -27
- package/lib/module/hooks/useWindowDimensions/index.android.js.map +0 -1
- package/lib/module/types.js +0 -2
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +0 -2
- package/src/hooks/useWindowDimensions/index.android.ts +0 -38
|
@@ -1,18 +1,175 @@
|
|
|
1
1
|
import type { AnimatedContext, ReanimatedContext } from "../context";
|
|
2
2
|
import type { FocusedInputHandler, KeyboardHandler } from "../types";
|
|
3
3
|
import type { DependencyList } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Hook that sets the Android soft input mode to adjust resize on mount and
|
|
6
|
+
* restores default mode on unmount. This ensures the keyboard behavior is consistent
|
|
7
|
+
* on all Android versions.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#setinputmode-|Documentation} page for more details.
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* function MyComponent() {
|
|
13
|
+
* useResizeMode();
|
|
14
|
+
* return <View />;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
4
18
|
export declare const useResizeMode: () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Hook that provides animated (`height`/`progress`) values for tracking keyboard movement.
|
|
21
|
+
* Automatically sets the resize mode for Android.
|
|
22
|
+
*
|
|
23
|
+
* @returns Object {@link AnimatedContext|containing} animated values for keyboard movement.
|
|
24
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/keyboard/use-keyboard-animation|Documentation} page for more details.
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* function MyComponent() {
|
|
28
|
+
* const { height, progress } = useKeyboardAnimation();
|
|
29
|
+
* return <Animated.View style={{ transform: [{ translateY: height }] }} />;
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
5
33
|
export declare const useKeyboardAnimation: () => AnimatedContext;
|
|
34
|
+
/**
|
|
35
|
+
* Hook that provides reanimated (`height`/`progress`) values for tracking keyboard movement.
|
|
36
|
+
* Automatically sets the resize mode for Android.
|
|
37
|
+
*
|
|
38
|
+
* @returns Object {@link ReanimatedContext|containing} reanimated values for keyboard movement.
|
|
39
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/keyboard/use-reanimated-keyboard-animation|Documentation} page for more details.
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* function MyComponent() {
|
|
43
|
+
* const { height, progress } = useReanimatedKeyboardAnimation();
|
|
44
|
+
* return <Reanimated.View style={{ transform: [{ translateY: height }] }} />;
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
6
48
|
export declare const useReanimatedKeyboardAnimation: () => ReanimatedContext;
|
|
49
|
+
/**
|
|
50
|
+
* An alternative to {@link useKeyboardHandler} that doesn't set resize mode on mount. If your
|
|
51
|
+
* app already uses `adjustResize`, then you can use this hook instead of `useKeyboardHandler`.
|
|
52
|
+
*
|
|
53
|
+
* @param handler - Object containing keyboard event handlers.
|
|
54
|
+
* @param [deps] - Dependencies array for the effect.
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* function MyComponent() {
|
|
58
|
+
* const height = useSharedValue(0);
|
|
59
|
+
* const progress = useSharedValue(0);
|
|
60
|
+
*
|
|
61
|
+
* useGenericKeyboardHandler({
|
|
62
|
+
* onMove: (e) => {
|
|
63
|
+
* "worklet";
|
|
64
|
+
*
|
|
65
|
+
* height.value = e.height;
|
|
66
|
+
* progress.value = e.progress;
|
|
67
|
+
* },
|
|
68
|
+
* onEnd: (e) => {
|
|
69
|
+
* "worklet";
|
|
70
|
+
*
|
|
71
|
+
* height.value = e.height;
|
|
72
|
+
* progress.value = e.progress;
|
|
73
|
+
* },
|
|
74
|
+
* }, []);
|
|
75
|
+
*
|
|
76
|
+
* return <Reanimated.View style={{ height: height }] }} />;
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
7
80
|
export declare function useGenericKeyboardHandler(handler: KeyboardHandler, deps?: DependencyList): void;
|
|
81
|
+
/**
|
|
82
|
+
* Hook that gives an access to each aspect of keyboard movement with workletized `onStart`/`onMove`/`onInteractive`/`onEnd` handlers.
|
|
83
|
+
*
|
|
84
|
+
* @param handler - Object containing keyboard event handlers.
|
|
85
|
+
* @param [deps] - Dependencies array for the effect.
|
|
86
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/keyboard/use-keyboard-handler|Documentation} page for more details.
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* function MyComponent() {
|
|
90
|
+
* const height = useSharedValue(0);
|
|
91
|
+
* const progress = useSharedValue(0);
|
|
92
|
+
*
|
|
93
|
+
* useKeyboardHandler({
|
|
94
|
+
* onMove: (e) => {
|
|
95
|
+
* "worklet";
|
|
96
|
+
*
|
|
97
|
+
* height.value = e.height;
|
|
98
|
+
* progress.value = e.progress;
|
|
99
|
+
* },
|
|
100
|
+
* onEnd: (e) => {
|
|
101
|
+
* "worklet";
|
|
102
|
+
*
|
|
103
|
+
* height.value = e.height;
|
|
104
|
+
* progress.value = e.progress;
|
|
105
|
+
* },
|
|
106
|
+
* }, []);
|
|
107
|
+
*
|
|
108
|
+
* return <Reanimated.View style={{ height: height }] }} />;
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
8
112
|
export declare function useKeyboardHandler(handler: KeyboardHandler, deps?: DependencyList): void;
|
|
113
|
+
/**
|
|
114
|
+
* Hook for controlling keyboard controller module.
|
|
115
|
+
* Allows to disable/enable it and check the actual state (whether it's enabled or not).
|
|
116
|
+
* When disabled it fallbacks to default android keyboard handling and stops tracking all
|
|
117
|
+
* the events that are exposed from this library.
|
|
118
|
+
*
|
|
119
|
+
* @property {Function} setEnabled - Function to enable/disable keyboard handling.
|
|
120
|
+
* @property {boolean} enabled - Current enabled state.
|
|
121
|
+
* @returns Object containing keyboard control functions and state.
|
|
122
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/module/use-keyboard-controller|Documentation} page for more details.
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
* function MyComponent() {
|
|
126
|
+
* const { setEnabled, enabled } = useKeyboardController();
|
|
127
|
+
* return (
|
|
128
|
+
* <Button
|
|
129
|
+
* title={enabled ? 'Disable' : 'Enable'}
|
|
130
|
+
* onPress={() => setEnabled(!enabled)}
|
|
131
|
+
* />
|
|
132
|
+
* );
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
9
136
|
export declare function useKeyboardController(): {
|
|
10
137
|
setEnabled: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
11
138
|
enabled: boolean;
|
|
12
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Hook that provides access to the layout of the currently focused input.
|
|
142
|
+
*
|
|
143
|
+
* @returns Object containing reanimated values for focused input.
|
|
144
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/input/use-reanimated-focused-input|Documentation} page for more details.
|
|
145
|
+
* @example
|
|
146
|
+
* ```tsx
|
|
147
|
+
* function MyComponent() {
|
|
148
|
+
* const { input } = useReanimatedFocusedInput();
|
|
149
|
+
* return <Reanimated.View style={{ height: input.value?.layout.height }} />;
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
13
153
|
export declare function useReanimatedFocusedInput(): {
|
|
14
154
|
input: import("react-native-reanimated").SharedValue<import("../types").FocusedInputLayoutChangedEvent | null>;
|
|
15
155
|
};
|
|
156
|
+
/**
|
|
157
|
+
* Hook for handling focused input events, such as changes of selection, text etc.
|
|
158
|
+
*
|
|
159
|
+
* @param handler - Object containing focused input event handlers.
|
|
160
|
+
* @param [deps] - Dependencies array for the effect.
|
|
161
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/input/use-focused-input-handler|Documentation} page for more details.
|
|
162
|
+
* @example
|
|
163
|
+
* ```tsx
|
|
164
|
+
* function MyComponent() {
|
|
165
|
+
* useFocusedInputHandler({
|
|
166
|
+
* onChangeText: (e) => console.log('Text changed:', e.text),
|
|
167
|
+
* onSelectionChange: (e) => console.log('Selection changed:', e.selection)
|
|
168
|
+
* });
|
|
169
|
+
* return <View />;
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
16
173
|
export declare function useFocusedInputHandler(handler: FocusedInputHandler, deps?: DependencyList): void;
|
|
17
174
|
export * from "./useWindowDimensions";
|
|
18
175
|
export * from "./useKeyboardState";
|
|
@@ -1,2 +1,22 @@
|
|
|
1
1
|
import type { KeyboardState } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* React Hook that represents the current keyboard state on iOS and Android.
|
|
4
|
+
* It tracks keyboard visibility, height, appearance, type and other properties.
|
|
5
|
+
* This hook subscribes to keyboard events and updates the state reactively.
|
|
6
|
+
*
|
|
7
|
+
* @returns Object {@link KeyboardState|containing} keyboard state information.
|
|
8
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/keyboard/use-keyboard-state|Documentation} page for more details.
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function MyComponent() {
|
|
12
|
+
* const { isVisible, height } = useKeyboardState();
|
|
13
|
+
* return (
|
|
14
|
+
* <View>
|
|
15
|
+
* <Text>Keyboard is {isVisible ? 'visible' : 'hidden'}</Text>
|
|
16
|
+
* <Text>Keyboard height: {height}</Text>
|
|
17
|
+
* </View>
|
|
18
|
+
* );
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
2
22
|
export declare const useKeyboardState: () => KeyboardState;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { WindowDimensionsEventData } from "../../types";
|
|
2
|
+
export declare const useWindowDimensions: () => WindowDimensionsEventData;
|
|
@@ -2,6 +2,20 @@ import { Animated } from "react-native";
|
|
|
2
2
|
import { findNodeHandle } from "./utils/findNodeHandle";
|
|
3
3
|
type EventHandler = (event: never) => void;
|
|
4
4
|
type ComponentOrHandle = Parameters<typeof findNodeHandle>[0];
|
|
5
|
+
/**
|
|
6
|
+
* An internal hook that helps to register workletized event handlers.
|
|
7
|
+
*
|
|
8
|
+
* @param map - Map of event handlers and their names.
|
|
9
|
+
* @param viewTagRef - Ref to the view that produces events.
|
|
10
|
+
* @returns A function that registers supplied event handlers.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const setKeyboardHandlers = useEventHandlerRegistration<KeyboardHandler>(
|
|
14
|
+
* keyboardEventsMap,
|
|
15
|
+
* viewTagRef,
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
5
19
|
export declare function useEventHandlerRegistration<H extends Partial<Record<string, EventHandler>>>(map: Map<keyof H, string>, viewTagRef: React.MutableRefObject<ComponentOrHandle>): (handler: H) => () => void;
|
|
6
20
|
/**
|
|
7
21
|
* TS variant of `useAnimatedValue` hook which is added in RN 0.71
|
|
@@ -10,7 +24,14 @@ export declare function useEventHandlerRegistration<H extends Partial<Record<str
|
|
|
10
24
|
* and therefore consumes less memory. We can not use a variant from
|
|
11
25
|
* RN, since this library supports earlier versions of RN.
|
|
12
26
|
*
|
|
27
|
+
* @param initialValue - Initial value of the animated value (numeric).
|
|
28
|
+
* @param config - Additional {@link Animated.AnimatedConfig|configuration} for the animated value.
|
|
29
|
+
* @returns Properly memoized {@link Animated.Value|Animated} value.
|
|
13
30
|
* @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const progress = useAnimatedValue(0);
|
|
34
|
+
* ```
|
|
14
35
|
*/
|
|
15
36
|
export declare function useAnimatedValue(initialValue: number, config?: Animated.AnimatedConfig): Animated.Value;
|
|
16
37
|
export {};
|
|
@@ -1,37 +1,58 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { EmitterSubscription, NativeSyntheticEvent, TextInputProps, ViewProps } from "react-native";
|
|
1
|
+
import type { NativeSyntheticEvent, ViewProps } from "react-native";
|
|
3
2
|
export type NativeEvent = {
|
|
3
|
+
/** A value between `0` and `1` indicating keyboard position, where `0` means keyboard is closed and `1` means keyboard is fully visible. */
|
|
4
4
|
progress: number;
|
|
5
|
+
/** Height of the keyboard. */
|
|
5
6
|
height: number;
|
|
7
|
+
/** Duration of the keyboard animation. */
|
|
6
8
|
duration: number;
|
|
9
|
+
/** Tag of the focused `TextInput`. */
|
|
7
10
|
target: number;
|
|
8
11
|
};
|
|
9
12
|
export type FocusedInputLayoutChangedEvent = {
|
|
13
|
+
/** Tag of the focused `TextInput`. */
|
|
10
14
|
target: number;
|
|
15
|
+
/** Tag of the parent `ScrollView`. */
|
|
11
16
|
parentScrollViewTarget: number;
|
|
12
17
|
layout: {
|
|
18
|
+
/** X coordinate of the focused `TextInput`. */
|
|
13
19
|
x: number;
|
|
20
|
+
/** Y coordinate of the focused `TextInput`. */
|
|
14
21
|
y: number;
|
|
22
|
+
/** Width of the focused `TextInput`. */
|
|
15
23
|
width: number;
|
|
24
|
+
/** Height of the focused `TextInput`. */
|
|
16
25
|
height: number;
|
|
26
|
+
/** X coordinate of the focused `TextInput` relative to the screen. */
|
|
17
27
|
absoluteX: number;
|
|
28
|
+
/** Y coordinate of the focused `TextInput` relative to the screen. */
|
|
18
29
|
absoluteY: number;
|
|
19
30
|
};
|
|
20
31
|
};
|
|
21
32
|
export type FocusedInputTextChangedEvent = {
|
|
33
|
+
/** Text that user typed in the focused `TextInput`. */
|
|
22
34
|
text: string;
|
|
23
35
|
};
|
|
24
36
|
export type FocusedInputSelectionChangedEvent = {
|
|
37
|
+
/** Tag of the focused `TextInput`. */
|
|
25
38
|
target: number;
|
|
26
39
|
selection: {
|
|
40
|
+
/** Start of the selection. Represents top-left point of rectangle. */
|
|
27
41
|
start: {
|
|
42
|
+
/** X coordinate of the selection start (relative to the `TextInput`). */
|
|
28
43
|
x: number;
|
|
44
|
+
/** Y coordinate of the selection start (relative to the `TextInput`). */
|
|
29
45
|
y: number;
|
|
46
|
+
/** The start of selection. */
|
|
30
47
|
position: number;
|
|
31
48
|
};
|
|
49
|
+
/** End of the selection. Represents bottom-right point of rectangle. */
|
|
32
50
|
end: {
|
|
51
|
+
/** X coordinate of the selection end (relative to the `TextInput`). */
|
|
33
52
|
x: number;
|
|
53
|
+
/** Y coordinate of the selection end (relative to the `TextInput`). */
|
|
34
54
|
y: number;
|
|
55
|
+
/** The end of selection. */
|
|
35
56
|
position: number;
|
|
36
57
|
};
|
|
37
58
|
};
|
|
@@ -57,82 +78,6 @@ export type KeyboardControllerProps = {
|
|
|
57
78
|
preserveEdgeToEdge?: boolean;
|
|
58
79
|
enabled?: boolean;
|
|
59
80
|
} & ViewProps;
|
|
60
|
-
export type KeyboardGestureAreaProps = {
|
|
61
|
-
interpolator?: "ios" | "linear";
|
|
62
|
-
/**
|
|
63
|
-
* Whether to allow to show a keyboard from dismissed state by swipe up.
|
|
64
|
-
* Default to `false`.
|
|
65
|
-
*/
|
|
66
|
-
showOnSwipeUp?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Whether to allow to control a keyboard by gestures. The strategy how
|
|
69
|
-
* it should be controlled is determined by `interpolator` property.
|
|
70
|
-
* Defaults to `true`.
|
|
71
|
-
*/
|
|
72
|
-
enableSwipeToDismiss?: boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Extra distance to the keyboard.
|
|
75
|
-
*/
|
|
76
|
-
offset?: number;
|
|
77
|
-
/**
|
|
78
|
-
* A corresponding `nativeID` value from the corresponding `TextInput`.
|
|
79
|
-
*/
|
|
80
|
-
textInputNativeID?: string;
|
|
81
|
-
} & ViewProps;
|
|
82
|
-
export type OverKeyboardViewProps = PropsWithChildren<{
|
|
83
|
-
visible: boolean;
|
|
84
|
-
}>;
|
|
85
|
-
export type Direction = "next" | "prev" | "current";
|
|
86
|
-
export type DismissOptions = {
|
|
87
|
-
keepFocus: boolean;
|
|
88
|
-
};
|
|
89
|
-
export type KeyboardControllerModule = {
|
|
90
|
-
setDefaultMode: () => void;
|
|
91
|
-
setInputMode: (mode: number) => void;
|
|
92
|
-
dismiss: (options?: DismissOptions) => Promise<void>;
|
|
93
|
-
setFocusTo: (direction: Direction) => void;
|
|
94
|
-
isVisible: () => boolean;
|
|
95
|
-
state: () => KeyboardEventData;
|
|
96
|
-
};
|
|
97
|
-
export type KeyboardControllerNativeModule = {
|
|
98
|
-
setDefaultMode: () => void;
|
|
99
|
-
setInputMode: (mode: number) => void;
|
|
100
|
-
dismiss: (keepFocus: boolean) => void;
|
|
101
|
-
setFocusTo: (direction: Direction) => void;
|
|
102
|
-
addListener: (eventName: string) => void;
|
|
103
|
-
removeListeners: (count: number) => void;
|
|
104
|
-
};
|
|
105
|
-
export type KeyboardControllerEvents = "keyboardWillShow" | "keyboardDidShow" | "keyboardWillHide" | "keyboardDidHide";
|
|
106
|
-
export type KeyboardEventData = {
|
|
107
|
-
height: number;
|
|
108
|
-
duration: number;
|
|
109
|
-
timestamp: number;
|
|
110
|
-
target: number;
|
|
111
|
-
type: NonNullable<TextInputProps["keyboardType"]>;
|
|
112
|
-
appearance: NonNullable<TextInputProps["keyboardAppearance"]>;
|
|
113
|
-
};
|
|
114
|
-
export type KeyboardState = {
|
|
115
|
-
isVisible: boolean;
|
|
116
|
-
} & KeyboardEventData;
|
|
117
|
-
export type KeyboardEventsModule = {
|
|
118
|
-
addListener: (name: KeyboardControllerEvents, cb: (e: KeyboardEventData) => void) => EmitterSubscription;
|
|
119
|
-
};
|
|
120
|
-
export type FocusedInputAvailableEvents = "focusDidSet";
|
|
121
|
-
export type FocusedInputEventData = {
|
|
122
|
-
current: number;
|
|
123
|
-
count: number;
|
|
124
|
-
};
|
|
125
|
-
export type FocusedInputEventsModule = {
|
|
126
|
-
addListener: (name: FocusedInputAvailableEvents, cb: (e: FocusedInputEventData) => void) => EmitterSubscription;
|
|
127
|
-
};
|
|
128
|
-
export type WindowDimensionsAvailableEvents = "windowDidResize";
|
|
129
|
-
export type WindowDimensionsEventData = {
|
|
130
|
-
width: number;
|
|
131
|
-
height: number;
|
|
132
|
-
};
|
|
133
|
-
export type WindowDimensionsEventsModule = {
|
|
134
|
-
addListener: (name: WindowDimensionsAvailableEvents, cb: (e: WindowDimensionsEventData) => void) => EmitterSubscription;
|
|
135
|
-
};
|
|
136
81
|
export type KeyboardHandlerHook<TContext, Event> = (handlers: {
|
|
137
82
|
onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;
|
|
138
83
|
onKeyboardMove?: (e: NativeEvent, context: TContext) => void;
|
|
@@ -150,14 +95,63 @@ export type FocusedInputSelectionHandlerHook<TContext, Event> = (handlers: {
|
|
|
150
95
|
}, dependencies?: unknown[]) => (e: NativeSyntheticEvent<Event>) => void;
|
|
151
96
|
export type Handlers<T> = Record<string, T | undefined>;
|
|
152
97
|
export type KeyboardHandler = Partial<{
|
|
98
|
+
/**
|
|
99
|
+
* A callback that gets invoked when keyboard starts its movement.
|
|
100
|
+
* The event contains DESTINATION values.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* onStart: (e) => {
|
|
105
|
+
* "worklet";
|
|
106
|
+
*
|
|
107
|
+
* const willKeyboardAppear = e.progress === 1;
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
153
111
|
onStart: (e: NativeEvent) => void;
|
|
112
|
+
/**
|
|
113
|
+
* A callback that gets involved every frame when keyboard changes its position.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* onMove: (e) => {
|
|
118
|
+
* "worklet";
|
|
119
|
+
*
|
|
120
|
+
* const keyboardHeight = e.height;
|
|
121
|
+
* }
|
|
122
|
+
*/
|
|
154
123
|
onMove: (e: NativeEvent) => void;
|
|
124
|
+
/**
|
|
125
|
+
* A callback that gets invoked when keyboard finished its movement.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* onEnd: (e) => {
|
|
130
|
+
* "worklet";
|
|
131
|
+
*
|
|
132
|
+
* const isKeyboardShown = e.progress === 1;
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
155
136
|
onEnd: (e: NativeEvent) => void;
|
|
137
|
+
/**
|
|
138
|
+
* A callback that gets invoked every frame when keyboard changes its position due to interactive dismissal.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* onInteractive: (e) => {
|
|
143
|
+
* "worklet";
|
|
144
|
+
*
|
|
145
|
+
* const keyboardHeight = e.height;
|
|
146
|
+
* }
|
|
147
|
+
*/
|
|
156
148
|
onInteractive: (e: NativeEvent) => void;
|
|
157
149
|
}>;
|
|
158
150
|
export type KeyboardHandlers = Handlers<KeyboardHandler>;
|
|
159
151
|
export type FocusedInputHandler = Partial<{
|
|
152
|
+
/** A callback that gets invoked every time when the text changes in focused input. */
|
|
160
153
|
onChangeText: (e: FocusedInputTextChangedEvent) => void;
|
|
154
|
+
/** A callback that gets invoked every time when the selection (cursor) coordinates change in focused input. */
|
|
161
155
|
onSelectionChange: (e: FocusedInputSelectionChangedEvent) => void;
|
|
162
156
|
}>;
|
|
163
157
|
export type FocusedInputHandlers = Handlers<FocusedInputHandler>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EmitterSubscription } from "react-native";
|
|
2
|
+
export type FocusedInputAvailableEvents = "focusDidSet";
|
|
3
|
+
export type FocusedInputEventData = {
|
|
4
|
+
current: number;
|
|
5
|
+
count: number;
|
|
6
|
+
};
|
|
7
|
+
export type FocusedInputEventsModule = {
|
|
8
|
+
addListener: (name: FocusedInputAvailableEvents, cb: (e: FocusedInputEventData) => void) => EmitterSubscription;
|
|
9
|
+
};
|
|
10
|
+
export type WindowDimensionsAvailableEvents = "windowDidResize";
|
|
11
|
+
export type WindowDimensionsEventData = {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
};
|
|
15
|
+
export type WindowDimensionsEventsModule = {
|
|
16
|
+
addListener: (name: WindowDimensionsAvailableEvents, cb: (e: WindowDimensionsEventData) => void) => EmitterSubscription;
|
|
17
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { EmitterSubscription, TextInputProps } from "react-native";
|
|
2
|
+
export type KeyboardControllerEvents = "keyboardWillShow" | "keyboardDidShow" | "keyboardWillHide" | "keyboardDidHide";
|
|
3
|
+
export type KeyboardEventData = {
|
|
4
|
+
/** Height of the keyboard. */
|
|
5
|
+
height: number;
|
|
6
|
+
/** Duration of the keyboard animation. */
|
|
7
|
+
duration: number;
|
|
8
|
+
/** Timestamp of the last keyboard event. */
|
|
9
|
+
timestamp: number;
|
|
10
|
+
/** Tag of the focused `TextInput`. */
|
|
11
|
+
target: number;
|
|
12
|
+
/** `keyboardType` property from focused `TextInput`. */
|
|
13
|
+
type: NonNullable<TextInputProps["keyboardType"]>;
|
|
14
|
+
/** Keyboard appearance. Can be one of `default`, `dark` or `light`. */
|
|
15
|
+
appearance: NonNullable<TextInputProps["keyboardAppearance"]>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* An object that represent current keyboard state.
|
|
19
|
+
*/
|
|
20
|
+
export type KeyboardState = {
|
|
21
|
+
/** Whether the keyboard is currently visible. */
|
|
22
|
+
isVisible: boolean;
|
|
23
|
+
} & KeyboardEventData;
|
|
24
|
+
export type KeyboardEventsModule = {
|
|
25
|
+
/**
|
|
26
|
+
* The `addListener` function connects a JavaScript function to an identified native
|
|
27
|
+
* keyboard notification event.
|
|
28
|
+
*
|
|
29
|
+
* This function then returns the reference to the listener.
|
|
30
|
+
*
|
|
31
|
+
* `name` is the string that identifies the event you're listening for. This
|
|
32
|
+
* can be any of the following:
|
|
33
|
+
*
|
|
34
|
+
* - `keyboardWillShow`;
|
|
35
|
+
* - `keyboardDidShow`;
|
|
36
|
+
* - `keyboardWillHide`;
|
|
37
|
+
* - `keyboardDidHide`.
|
|
38
|
+
*/
|
|
39
|
+
addListener: (name: KeyboardControllerEvents, cb: (e: KeyboardEventData) => void) => EmitterSubscription;
|
|
40
|
+
};
|
|
41
|
+
export type Direction = "next" | "prev" | "current";
|
|
42
|
+
export type DismissOptions = {
|
|
43
|
+
/**
|
|
44
|
+
* A boolean property indicating whether focus should be kept on the input after dismissing the keyboard. Default is `false`.
|
|
45
|
+
*/
|
|
46
|
+
keepFocus: boolean;
|
|
47
|
+
};
|
|
48
|
+
export type KeyboardControllerModule = {
|
|
49
|
+
/**
|
|
50
|
+
* Sets default `windowSoftInputMode` (the one that declared in `AndroidManifest.xml`).
|
|
51
|
+
*
|
|
52
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#setdefaultmode-|docs} page for more details.
|
|
53
|
+
*/
|
|
54
|
+
setDefaultMode: () => void;
|
|
55
|
+
/**
|
|
56
|
+
* 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.
|
|
57
|
+
*/
|
|
58
|
+
setInputMode: (mode: number) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Dismisses the active keyboard. Removes a focus by default, but allows to pass `{keepFocus: true}` to keep focus.
|
|
61
|
+
*
|
|
62
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#dismiss|docs} page for more details.
|
|
63
|
+
*/
|
|
64
|
+
dismiss: (options?: DismissOptions) => Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Moves focus to the specified direction (`next`, `prev` or `current` to restore a focus).
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#setfocusto|docs} page for more details.
|
|
69
|
+
*/
|
|
70
|
+
setFocusTo: (direction: Direction) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the keyboard is fully visible.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#isvisible|docs} page for more details.
|
|
75
|
+
*/
|
|
76
|
+
isVisible: () => boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Method that returns current keyboard state.
|
|
79
|
+
*
|
|
80
|
+
* @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller#state|docs} page for more details.
|
|
81
|
+
*/
|
|
82
|
+
state: () => KeyboardEventData;
|
|
83
|
+
};
|
|
84
|
+
export type KeyboardControllerNativeModule = {
|
|
85
|
+
setDefaultMode: () => void;
|
|
86
|
+
setInputMode: (mode: number) => void;
|
|
87
|
+
dismiss: (keepFocus: boolean) => void;
|
|
88
|
+
setFocusTo: (direction: Direction) => void;
|
|
89
|
+
addListener: (eventName: string) => void;
|
|
90
|
+
removeListeners: (count: number) => void;
|
|
91
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
import type { ViewProps } from "react-native";
|
|
3
|
+
export type KeyboardGestureAreaProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Determines how the keyboard position will be controlled:
|
|
6
|
+
* - `ios` - keyboard will be following finger only when finger touches keyboard
|
|
7
|
+
* - `linear` - keyboard will be following finger position linearly.
|
|
8
|
+
*
|
|
9
|
+
* @platform android
|
|
10
|
+
*/
|
|
11
|
+
interpolator?: "ios" | "linear";
|
|
12
|
+
/**
|
|
13
|
+
* Whether to allow to show a keyboard from dismissed state by swipe up.
|
|
14
|
+
* Default to `false`.
|
|
15
|
+
*
|
|
16
|
+
* @platform android
|
|
17
|
+
*/
|
|
18
|
+
showOnSwipeUp?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to allow to control a keyboard by gestures. The strategy how
|
|
21
|
+
* it should be controlled is determined by `interpolator` property.
|
|
22
|
+
* Defaults to `true`.
|
|
23
|
+
*
|
|
24
|
+
* @platform android
|
|
25
|
+
*/
|
|
26
|
+
enableSwipeToDismiss?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Extra distance to the keyboard.
|
|
29
|
+
*/
|
|
30
|
+
offset?: number;
|
|
31
|
+
/**
|
|
32
|
+
* A corresponding `nativeID` value from the associated `TextInput` (a string that links the `KeyboardGestureArea` to one or more `TextInput` components).
|
|
33
|
+
* This is **required on iOS** in order to apply the `offset` when the keyboard is shown. Only the currently focused `TextInput` with a matching `nativeID`
|
|
34
|
+
* will receive offset behavior.
|
|
35
|
+
*
|
|
36
|
+
* @platform ios
|
|
37
|
+
*/
|
|
38
|
+
textInputNativeID?: string;
|
|
39
|
+
} & ViewProps;
|
|
40
|
+
export type OverKeyboardViewProps = PropsWithChildren<{
|
|
41
|
+
/**
|
|
42
|
+
* A boolean prop indicating whether the view is visible or not. If it's true then view is shown on the screen. If it's false then view is hidden.
|
|
43
|
+
*/
|
|
44
|
+
visible: boolean;
|
|
45
|
+
}>;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { OverKeyboardViewProps } from "../../types";
|
|
3
3
|
import type { PropsWithChildren } from "react";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A view component that renders its children over the keyboard without closing the keyboard.
|
|
6
|
+
* Acts similar to modal, but doesn't close the keyboard when it's visible.
|
|
7
|
+
*
|
|
8
|
+
* @param props - Component props.
|
|
9
|
+
* @returns A view component that renders over the keyboard.
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <OverKeyboardView visible={true}>
|
|
13
|
+
* <Text>This will appear over the keyboard</Text>
|
|
14
|
+
* </OverKeyboardView>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare const OverKeyboardView: (props: PropsWithChildren<OverKeyboardViewProps>) => React.JSX.Element;
|
|
5
18
|
export default OverKeyboardView;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-keyboard-controller",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.3",
|
|
4
4
|
"description": "Keyboard manager which works in identical way on both iOS and Android",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -101,6 +101,7 @@
|
|
|
101
101
|
"eslint-plugin-ft-flow": "^3.0.11",
|
|
102
102
|
"eslint-plugin-import": "^2.28.1",
|
|
103
103
|
"eslint-plugin-jest": "^26.5.3",
|
|
104
|
+
"eslint-plugin-jsdoc": "^50.6.17",
|
|
104
105
|
"eslint-plugin-prettier": "^4.2.1",
|
|
105
106
|
"eslint-plugin-react-compiler": "0.0.0-experimental-9ed098e-20240725",
|
|
106
107
|
"eslint-plugin-react-perf": "^3.3.2",
|