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.
Files changed (118) hide show
  1. package/README.md +24 -23
  2. package/lib/commonjs/animated.js +23 -7
  3. package/lib/commonjs/animated.js.map +1 -1
  4. package/lib/commonjs/bindings.js +19 -0
  5. package/lib/commonjs/bindings.js.map +1 -1
  6. package/lib/commonjs/components/KeyboardAvoidingView/index.js +11 -2
  7. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
  8. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +51 -36
  9. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  10. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +17 -1
  11. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
  12. package/lib/commonjs/components/KeyboardStickyView/index.js +13 -0
  13. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  14. package/lib/commonjs/components/KeyboardToolbar/index.js +31 -22
  15. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
  16. package/lib/commonjs/context.js +16 -0
  17. package/lib/commonjs/context.js.map +1 -1
  18. package/lib/commonjs/hooks/index.js +164 -0
  19. package/lib/commonjs/hooks/index.js.map +1 -1
  20. package/lib/commonjs/hooks/useKeyboardState/index.js +21 -0
  21. package/lib/commonjs/hooks/useKeyboardState/index.js.map +1 -1
  22. package/lib/commonjs/internal.js +21 -0
  23. package/lib/commonjs/internal.js.map +1 -1
  24. package/lib/commonjs/module.js +4 -0
  25. package/lib/commonjs/module.js.map +1 -1
  26. package/lib/commonjs/monkey-patch.android.js +0 -5
  27. package/lib/commonjs/monkey-patch.android.js.map +1 -1
  28. package/lib/commonjs/{types.js → types/hooks.js} +1 -1
  29. package/lib/commonjs/types/hooks.js.map +1 -0
  30. package/lib/commonjs/types/index.js +50 -0
  31. package/lib/commonjs/types/index.js.map +1 -0
  32. package/lib/commonjs/types/internal.js +6 -0
  33. package/lib/commonjs/types/internal.js.map +1 -0
  34. package/lib/commonjs/types/module.js +6 -0
  35. package/lib/commonjs/types/module.js.map +1 -0
  36. package/lib/commonjs/types/views.js +6 -0
  37. package/lib/commonjs/types/views.js.map +1 -0
  38. package/lib/commonjs/views/OverKeyboardView/index.js +18 -4
  39. package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -1
  40. package/lib/module/animated.js +23 -7
  41. package/lib/module/animated.js.map +1 -1
  42. package/lib/module/bindings.js +19 -0
  43. package/lib/module/bindings.js.map +1 -1
  44. package/lib/module/components/KeyboardAvoidingView/index.js +11 -2
  45. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
  46. package/lib/module/components/KeyboardAwareScrollView/index.js +51 -36
  47. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  48. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +17 -1
  49. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
  50. package/lib/module/components/KeyboardStickyView/index.js +13 -0
  51. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  52. package/lib/module/components/KeyboardToolbar/index.js +31 -22
  53. package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
  54. package/lib/module/context.js +16 -0
  55. package/lib/module/context.js.map +1 -1
  56. package/lib/module/hooks/index.js +164 -0
  57. package/lib/module/hooks/index.js.map +1 -1
  58. package/lib/module/hooks/useKeyboardState/index.js +21 -0
  59. package/lib/module/hooks/useKeyboardState/index.js.map +1 -1
  60. package/lib/module/internal.js +21 -0
  61. package/lib/module/internal.js.map +1 -1
  62. package/lib/module/module.js +4 -0
  63. package/lib/module/module.js.map +1 -1
  64. package/lib/module/monkey-patch.android.js +0 -5
  65. package/lib/module/monkey-patch.android.js.map +1 -1
  66. package/lib/module/types/hooks.js +2 -0
  67. package/lib/module/types/hooks.js.map +1 -0
  68. package/lib/module/types/index.js +5 -0
  69. package/lib/module/types/index.js.map +1 -0
  70. package/lib/module/types/internal.js +2 -0
  71. package/lib/module/types/internal.js.map +1 -0
  72. package/lib/module/types/module.js +2 -0
  73. package/lib/module/types/module.js.map +1 -0
  74. package/lib/module/types/views.js +2 -0
  75. package/lib/module/types/views.js.map +1 -0
  76. package/lib/module/views/OverKeyboardView/index.js +18 -4
  77. package/lib/module/views/OverKeyboardView/index.js.map +1 -1
  78. package/lib/typescript/animated.d.ts +20 -6
  79. package/lib/typescript/bindings.d.ts +19 -0
  80. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +11 -2
  81. package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +23 -6
  82. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +17 -1
  83. package/lib/typescript/components/KeyboardStickyView/index.d.ts +15 -2
  84. package/lib/typescript/components/KeyboardToolbar/index.d.ts +13 -2
  85. package/lib/typescript/context.d.ts +32 -0
  86. package/lib/typescript/hooks/index.d.ts +157 -0
  87. package/lib/typescript/hooks/useKeyboardState/index.d.ts +20 -0
  88. package/lib/typescript/internal.d.ts +21 -0
  89. package/lib/typescript/module.d.ts +3 -0
  90. package/lib/typescript/{types.d.ts → types/hooks.d.ts} +72 -78
  91. package/lib/typescript/types/index.d.ts +4 -0
  92. package/lib/typescript/types/internal.d.ts +17 -0
  93. package/lib/typescript/types/module.d.ts +91 -0
  94. package/lib/typescript/types/views.d.ts +45 -0
  95. package/lib/typescript/views/OverKeyboardView/index.d.ts +14 -1
  96. package/package.json +2 -1
  97. package/src/animated.tsx +27 -12
  98. package/src/bindings.ts +19 -0
  99. package/src/components/KeyboardAvoidingView/index.tsx +11 -2
  100. package/src/components/KeyboardAwareScrollView/index.tsx +54 -39
  101. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +17 -1
  102. package/src/components/KeyboardStickyView/index.tsx +14 -1
  103. package/src/components/KeyboardToolbar/index.tsx +31 -19
  104. package/src/context.ts +33 -0
  105. package/src/hooks/index.ts +157 -0
  106. package/src/hooks/useKeyboardState/index.ts +20 -0
  107. package/src/internal.ts +21 -0
  108. package/src/module.ts +3 -0
  109. package/src/monkey-patch.android.ts +3 -6
  110. package/src/{types.ts → types/hooks.ts} +72 -105
  111. package/src/types/index.ts +4 -0
  112. package/src/types/internal.ts +24 -0
  113. package/src/types/module.ts +105 -0
  114. package/src/types/views.ts +46 -0
  115. package/src/views/OverKeyboardView/index.tsx +15 -4
  116. package/lib/commonjs/types.js.map +0 -1
  117. package/lib/module/types.js +0 -2
  118. package/lib/module/types.js.map +0 -1
@@ -33,8 +33,17 @@ export type KeyboardAvoidingViewProps = KeyboardAvoidingViewBaseProps & ({
33
33
  contentContainerStyle?: never;
34
34
  });
35
35
  /**
36
- * View that moves out of the way when the keyboard appears by automatically
37
- * adjusting its height, position, or bottom padding.
36
+ * A View component that automatically adjusts its height, position, or bottom padding
37
+ * when the keyboard appears to ensure that the content remains visible.
38
+ *
39
+ * @returns A View component that adjusts to keyboard visibility.
40
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-avoiding-view|Documentation} page for more details.
41
+ * @example
42
+ * ```tsx
43
+ * <KeyboardAvoidingView behavior="padding">
44
+ * <TextInput />
45
+ * </KeyboardAvoidingView>
46
+ * ```
38
47
  */
39
48
  declare const KeyboardAvoidingView: React.ForwardRefExoticComponent<React.PropsWithChildren<KeyboardAvoidingViewProps> & React.RefAttributes<View>>;
40
49
  export default KeyboardAvoidingView;
@@ -5,23 +5,40 @@ export type KeyboardAwareScrollViewProps = {
5
5
  bottomOffset?: number;
6
6
  /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */
7
7
  disableScrollOnKeyboardHide?: boolean;
8
- /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true` */
8
+ /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true`. */
9
9
  enabled?: boolean;
10
- /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0` */
10
+ /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0`. */
11
11
  extraKeyboardSpace?: number;
12
- /** Custom component for `ScrollView`. Default is `ScrollView` */
12
+ /** Custom component for `ScrollView`. Default is `ScrollView`. */
13
13
  ScrollViewComponent?: React.ComponentType<ScrollViewProps>;
14
14
  } & ScrollViewProps;
15
+ /**
16
+ * A ScrollView component that automatically handles keyboard appearance and disappearance
17
+ * by adjusting its content position to ensure the focused input remains visible.
18
+ *
19
+ * The component uses a sophisticated animation system to smoothly handle keyboard transitions
20
+ * and maintain proper scroll position during keyboard interactions.
21
+ *
22
+ * @returns A ScrollView component that handles keyboard interactions.
23
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-aware-scroll-view|Documentation} page for more details.
24
+ * @example
25
+ * ```tsx
26
+ * <KeyboardAwareScrollView bottomOffset={20}>
27
+ * <TextInput placeholder="Enter text" />
28
+ * <TextInput placeholder="Another input" />
29
+ * </KeyboardAwareScrollView>
30
+ * ```
31
+ */
15
32
  declare const KeyboardAwareScrollView: React.ForwardRefExoticComponent<{
16
33
  /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */
17
34
  bottomOffset?: number;
18
35
  /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */
19
36
  disableScrollOnKeyboardHide?: boolean;
20
- /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true` */
37
+ /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true`. */
21
38
  enabled?: boolean;
22
- /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0` */
39
+ /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0`. */
23
40
  extraKeyboardSpace?: number;
24
- /** Custom component for `ScrollView`. Default is `ScrollView` */
41
+ /** Custom component for `ScrollView`. Default is `ScrollView`. */
25
42
  ScrollViewComponent?: React.ComponentType<ScrollViewProps>;
26
43
  } & ScrollViewProps & {
27
44
  children?: React.ReactNode | undefined;
@@ -1,6 +1,22 @@
1
1
  import { useKeyboardHandler } from "../../hooks";
2
2
  /**
3
3
  * Hook that uses default transitions for iOS and Android > 11, and uses
4
- * custom interpolation on Android < 11 to achieve more smooth animation
4
+ * custom interpolation on Android < 11 to achieve more smooth animation.
5
+ *
6
+ * @param handler - Object containing keyboard event handlers.
7
+ * @param [deps] - Dependencies array for the effect.
8
+ * @example
9
+ * ```ts
10
+ * useSmoothKeyboardHandler(
11
+ * {
12
+ * onStart: (e) => {
13
+ * "worklet";
14
+ *
15
+ * // your handler for keyboard start
16
+ * },
17
+ * },
18
+ * [],
19
+ * );
20
+ * ```
5
21
  */
6
22
  export declare const useSmoothKeyboardHandler: typeof useKeyboardHandler;
@@ -14,9 +14,22 @@ export type KeyboardStickyViewProps = {
14
14
  */
15
15
  opened?: number;
16
16
  };
17
- /** Controls whether this `KeyboardStickyView` instance should take effect. Default is `true` */
17
+ /** Controls whether this `KeyboardStickyView` instance should take effect. Default is `true`. */
18
18
  enabled?: boolean;
19
19
  } & ViewProps;
20
+ /**
21
+ * A View component that sticks to the keyboard and moves with it when it appears or disappears.
22
+ * The view can be configured with custom offsets for both closed and open keyboard states.
23
+ *
24
+ * @returns An animated View component that sticks to the keyboard.
25
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-sticky-view|Documentation} page for more details.
26
+ * @example
27
+ * ```tsx
28
+ * <KeyboardStickyView offset={{ closed: 0, opened: 20 }}>
29
+ * <Button title="Submit" />
30
+ * </KeyboardStickyView>
31
+ * ```
32
+ */
20
33
  declare const KeyboardStickyView: React.ForwardRefExoticComponent<{
21
34
  /**
22
35
  * Specify additional offset to the view for given keyboard state.
@@ -31,7 +44,7 @@ declare const KeyboardStickyView: React.ForwardRefExoticComponent<{
31
44
  */
32
45
  opened?: number;
33
46
  };
34
- /** Controls whether this `KeyboardStickyView` instance should take effect. Default is `true` */
47
+ /** Controls whether this `KeyboardStickyView` instance should take effect. Default is `true`. */
35
48
  enabled?: boolean;
36
49
  } & ViewProps & {
37
50
  children?: React.ReactNode | undefined;
@@ -46,11 +46,22 @@ export type KeyboardToolbarProps = Omit<ViewProps, "style" | "testID" | "childre
46
46
  * A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
47
47
  */
48
48
  opacity?: HEX;
49
+ /**
50
+ * A object containing `left`/`right` properties. Used to specify proper container padding in landscape mode.
51
+ */
49
52
  insets?: SafeAreaInsets;
50
53
  } & Pick<KeyboardStickyViewProps, "offset" | "enabled">;
51
54
  /**
52
- * `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` and
53
- * `Done` buttons.
55
+ * `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` buttons from left and
56
+ * `Done` button from the right (to dismiss the keyboard). Allows to add customizable content (yours UI elements) in the middle.
57
+ *
58
+ * @param props - Component props.
59
+ * @returns A component that is shown above the keyboard with `Prev`/`Next` and `Done` buttons.
60
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-toolbar|Documentation} page for more details.
61
+ * @example
62
+ * ```tsx
63
+ * <KeyboardToolbar doneText="Close" />
64
+ * ```
54
65
  */
55
66
  declare const KeyboardToolbar: React.FC<KeyboardToolbarProps>;
56
67
  export { colors as DefaultKeyboardToolbarTheme };
@@ -3,21 +3,53 @@ import type { FocusedInputHandler, FocusedInputLayoutChangedEvent, KeyboardHandl
3
3
  import type React from "react";
4
4
  import type { SharedValue } from "react-native-reanimated";
5
5
  export type AnimatedContext = {
6
+ /**
7
+ * A value between `0` and `1` indicating keyboard position, where `0` means keyboard is closed and `1` means keyboard is fully visible.
8
+ * Represented as `Animated.Value`.
9
+ */
6
10
  progress: Animated.Value;
11
+ /** Height of the keyboard. Represented as `Animated.Value`. */
7
12
  height: Animated.AnimatedMultiplication<number>;
8
13
  };
9
14
  export type ReanimatedContext = {
15
+ /**
16
+ * A value between `0` and `1` indicating keyboard position, where `0` means keyboard is closed and `1` means keyboard is fully visible.
17
+ * Represented as `SharedValue`.
18
+ */
10
19
  progress: SharedValue<number>;
20
+ /** Height of the keyboard. Represented as `SharedValue`. */
11
21
  height: SharedValue<number>;
12
22
  };
13
23
  export type KeyboardAnimationContext = {
24
+ /** Whether KeyboardController library is active or not. */
14
25
  enabled: boolean;
26
+ /** Object that stores animated values that reflect the keyboard’s current position and movement. */
15
27
  animated: AnimatedContext;
28
+ /** Object that stores reanimated values that reflect the keyboard’s current position and movement. */
16
29
  reanimated: ReanimatedContext;
30
+ /** Layout of the focused `TextInput` represented as `SharedValue`. */
17
31
  layout: SharedValue<FocusedInputLayoutChangedEvent | null>;
32
+ /** Method for setting workletized keyboard handlers. */
18
33
  setKeyboardHandlers: (handlers: KeyboardHandler) => () => void;
34
+ /** Method for setting workletized handlers for tracking focused input events. */
19
35
  setInputHandlers: (handlers: FocusedInputHandler) => () => void;
36
+ /** Method to enable/disable KeyboardController library. */
20
37
  setEnabled: React.Dispatch<React.SetStateAction<boolean>>;
21
38
  };
22
39
  export declare const KeyboardContext: React.Context<KeyboardAnimationContext>;
40
+ /**
41
+ * A hook that returns a reference to {@link KeyboardAnimationContext} object.
42
+ *
43
+ * @returns Object {@link KeyboardAnimationContext|containing} keyboard-controller context.
44
+ * @example
45
+ * ```ts
46
+ * const context = useKeyboardContext();
47
+ *
48
+ * useLayoutEffect(() => {
49
+ * const cleanup = context.setInputHandlers(handler);
50
+ *
51
+ * return () => cleanup();
52
+ * }, deps);
53
+ * ```
54
+ */
23
55
  export declare const useKeyboardContext: () => KeyboardAnimationContext;
@@ -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;
@@ -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,2 +1,5 @@
1
1
  import type { KeyboardControllerModule } from "./types";
2
+ /**
3
+ * KeyboardController module. Helps to perform imperative actions/checks with keyboard.
4
+ */
2
5
  export declare const KeyboardController: KeyboardControllerModule;
@@ -1,37 +1,58 @@
1
- import type { PropsWithChildren } from "react";
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,4 @@
1
+ export * from "./hooks";
2
+ export * from "./views";
3
+ export * from "./module";
4
+ export * from "./internal";