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
@@ -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
- declare const OverKeyboardView: ({ children, visible, }: PropsWithChildren<OverKeyboardViewProps>) => React.JSX.Element;
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.1",
3
+ "version": "1.17.2",
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",
package/src/animated.tsx CHANGED
@@ -56,29 +56,29 @@ type KeyboardProviderProps = {
56
56
  * or `StatusBar` component from `react-native`, you can ignore it.
57
57
  * Defaults to `false`.
58
58
  *
59
- * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14
60
59
  * @platform android
60
+ * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14
61
61
  */
62
62
  statusBarTranslucent?: boolean;
63
63
  /**
64
64
  * Set the value to `true`, if you use translucent navigation bar on Android.
65
65
  * Defaults to `false`.
66
66
  *
67
- * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119
68
67
  * @platform android
68
+ * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119
69
69
  */
70
70
  navigationBarTranslucent?: boolean;
71
71
  /**
72
72
  * A boolean property indicating whether to keep edge-to-edge mode always enabled (even when you disable the module).
73
73
  * Defaults to `false`.
74
74
  *
75
- * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/592
76
75
  * @platform android
76
+ * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/592
77
77
  */
78
78
  preserveEdgeToEdge?: boolean;
79
79
  /**
80
- * A boolean prop indicating whether the module is enabled. It indicate only initial state,
81
- * i. e. if you try to change this prop after component mount it will not have any effect.
80
+ * A boolean prop indicating whether the module is enabled. It indicate only initial state
81
+ * (if you try to change this prop after component mount it will not have any effect).
82
82
  * To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.
83
83
  * Defaults to `true`.
84
84
  */
@@ -89,13 +89,28 @@ type KeyboardProviderProps = {
89
89
  // see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details
90
90
  const OS = Platform.OS;
91
91
 
92
- export const KeyboardProvider = ({
93
- children,
94
- statusBarTranslucent,
95
- navigationBarTranslucent,
96
- preserveEdgeToEdge,
97
- enabled: initiallyEnabled = true,
98
- }: KeyboardProviderProps) => {
92
+ /**
93
+ * A component that wrap your app. Under the hood it works with {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller-view|KeyboardControllerView} to receive events during keyboard movements,
94
+ * maps these events to `Animated`/`Reanimated` values and store them in context.
95
+ *
96
+ * @param props - Provider props, such as `statusBarTranslucent`, `navigationBarTranslucent`, etc.
97
+ * @returns A component that should be mounted in root of your App layout.
98
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-provider|Documentation} page for more details.
99
+ * @example
100
+ * ```tsx
101
+ * <KeyboardProvider>
102
+ * <NavigationContainer />
103
+ * </KeyboardProvider>
104
+ * ```
105
+ */
106
+ export const KeyboardProvider = (props: KeyboardProviderProps) => {
107
+ const {
108
+ children,
109
+ statusBarTranslucent,
110
+ navigationBarTranslucent,
111
+ preserveEdgeToEdge,
112
+ enabled: initiallyEnabled = true,
113
+ } = props;
99
114
  // ref
100
115
  const viewTagRef = useRef<React.Component<KeyboardControllerProps>>(null);
101
116
  // state
package/src/bindings.ts CHANGED
@@ -21,6 +21,15 @@ export const KeyboardControllerNative: KeyboardControllerNativeModule = {
21
21
  addListener: NOOP,
22
22
  removeListeners: NOOP,
23
23
  };
24
+ /**
25
+ * An event emitter that provides a way to subscribe to next keyboard events:
26
+ * - `keyboardWillShow`;
27
+ * - `keyboardDidShow`;
28
+ * - `keyboardWillHide`;
29
+ * - `keyboardDidHide`.
30
+ *
31
+ * Use `addListener` function to add your event listener for a specific keyboard event.
32
+ */
24
33
  export const KeyboardEvents: KeyboardEventsModule = {
25
34
  addListener: () => ({ remove: NOOP } as EmitterSubscription),
26
35
  };
@@ -34,8 +43,18 @@ export const FocusedInputEvents: FocusedInputEventsModule = {
34
43
  export const WindowDimensionsEvents: WindowDimensionsEventsModule = {
35
44
  addListener: () => ({ remove: NOOP } as EmitterSubscription),
36
45
  };
46
+ /**
47
+ * A view that sends events whenever keyboard or focused events are happening.
48
+ *
49
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-controller-view|Documentation} page for more details.
50
+ */
37
51
  export const KeyboardControllerView =
38
52
  View as unknown as React.FC<KeyboardControllerProps>;
53
+ /**
54
+ * A view that defines a region on the screen, where gestures will control the keyboard position.
55
+ *
56
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/keyboard-gesture-area|Documentation} page for more details.
57
+ */
39
58
  export const KeyboardGestureArea =
40
59
  View as unknown as React.FC<KeyboardGestureAreaProps>;
41
60
  export const RCTOverKeyboardView =
@@ -62,8 +62,17 @@ const defaultLayout: LayoutRectangle = {
62
62
  };
63
63
 
64
64
  /**
65
- * View that moves out of the way when the keyboard appears by automatically
66
- * adjusting its height, position, or bottom padding.
65
+ * A View component that automatically adjusts its height, position, or bottom padding
66
+ * when the keyboard appears to ensure that the content remains visible.
67
+ *
68
+ * @returns A View component that adjusts to keyboard visibility.
69
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-avoiding-view|Documentation} page for more details.
70
+ * @example
71
+ * ```tsx
72
+ * <KeyboardAvoidingView behavior="padding">
73
+ * <TextInput />
74
+ * </KeyboardAvoidingView>
75
+ * ```
67
76
  */
68
77
  const KeyboardAvoidingView = forwardRef<
69
78
  View,
@@ -35,51 +35,66 @@ export type KeyboardAwareScrollViewProps = {
35
35
  bottomOffset?: number;
36
36
  /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */
37
37
  disableScrollOnKeyboardHide?: boolean;
38
- /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true` */
38
+ /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true`. */
39
39
  enabled?: boolean;
40
- /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0` */
40
+ /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0`. */
41
41
  extraKeyboardSpace?: number;
42
- /** Custom component for `ScrollView`. Default is `ScrollView` */
42
+ /** Custom component for `ScrollView`. Default is `ScrollView`. */
43
43
  ScrollViewComponent?: React.ComponentType<ScrollViewProps>;
44
44
  } & ScrollViewProps;
45
45
 
46
- /*
47
- * Everything begins from `onStart` handler. This handler is called every time,
48
- * when keyboard changes its size or when focused `TextInput` was changed. In
49
- * this handler we are calculating/memoizing values which later will be used
50
- * during layout movement. For that we calculate:
51
- * - layout of focused field (`layout`) - to understand whether there will be overlap
52
- * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation
53
- * - future keyboard height (`keyboardHeight`) - used in scroll interpolation
54
- * - current scroll position (`scrollPosition`) - used to scroll from this point
46
+ // Everything begins from `onStart` handler. This handler is called every time,
47
+ // when keyboard changes its size or when focused `TextInput` was changed. In
48
+ // this handler we are calculating/memoizing values which later will be used
49
+ // during layout movement. For that we calculate:
50
+ // - layout of focused field (`layout`) - to understand whether there will be overlap
51
+ // - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation
52
+ // - future keyboard height (`keyboardHeight`) - used in scroll interpolation
53
+ // - current scroll position (`scrollPosition`) - used to scroll from this point
54
+ //
55
+ // Once we've calculated all necessary variables - we can actually start to use them.
56
+ // It happens in `onMove` handler - this function simply calls `maybeScroll` with
57
+ // current keyboard frame height. This functions makes the smooth transition.
58
+ //
59
+ // When the transition has finished we go to `onEnd` handler. In this handler
60
+ // we verify, that the current field is not overlapped within a keyboard frame.
61
+ // For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,
62
+ // however there could be some cases, when `onMove` is not called:
63
+ // - on iOS when TextInput was changed - keyboard transition is instant
64
+ // - on Android when TextInput was changed and keyboard size wasn't changed
65
+ // So `onEnd` handler handle the case, when `onMove` wasn't triggered.
66
+ //
67
+ // ====================================================================================================================+
68
+ // -----------------------------------------------------Flow chart-----------------------------------------------------+
69
+ // ====================================================================================================================+
70
+ //
71
+ // +============================+ +============================+ +==================================+
72
+ // + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>
73
+ // + + + (run `onStart`) + + `onMove` is getting called +
74
+ // +============================+ +============================+ +==================================+
75
+ //
76
+ // +============================+ +============================+ +=====================================+
77
+ // + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +
78
+ // + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +
79
+ // +============================+ +============================+ +=====================================+
80
+ //
81
+
82
+ /**
83
+ * A ScrollView component that automatically handles keyboard appearance and disappearance
84
+ * by adjusting its content position to ensure the focused input remains visible.
55
85
  *
56
- * Once we've calculated all necessary variables - we can actually start to use them.
57
- * It happens in `onMove` handler - this function simply calls `maybeScroll` with
58
- * current keyboard frame height. This functions makes the smooth transition.
59
- *
60
- * When the transition has finished we go to `onEnd` handler. In this handler
61
- * we verify, that the current field is not overlapped within a keyboard frame.
62
- * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,
63
- * however there could be some cases, when `onMove` is not called:
64
- * - on iOS when TextInput was changed - keyboard transition is instant
65
- * - on Android when TextInput was changed and keyboard size wasn't changed
66
- * So `onEnd` handler handle the case, when `onMove` wasn't triggered.
67
- *
68
- * ====================================================================================================================+
69
- * -----------------------------------------------------Flow chart-----------------------------------------------------+
70
- * ====================================================================================================================+
71
- *
72
- * +============================+ +============================+ +==================================+
73
- * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>
74
- * + + + (run `onStart`) + + `onMove` is getting called +
75
- * +============================+ +============================+ +==================================+
76
- *
77
- *
78
- * +============================+ +============================+ +=====================================+
79
- * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +
80
- * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +
81
- * +============================+ +============================+ +=====================================+
86
+ * The component uses a sophisticated animation system to smoothly handle keyboard transitions
87
+ * and maintain proper scroll position during keyboard interactions.
82
88
  *
89
+ * @returns A ScrollView component that handles keyboard interactions.
90
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-aware-scroll-view|Documentation} page for more details.
91
+ * @example
92
+ * ```tsx
93
+ * <KeyboardAwareScrollView bottomOffset={20}>
94
+ * <TextInput placeholder="Enter text" />
95
+ * <TextInput placeholder="Another input" />
96
+ * </KeyboardAwareScrollView>
97
+ * ```
83
98
  */
84
99
  const KeyboardAwareScrollView = forwardRef<
85
100
  ScrollView,
@@ -133,7 +148,7 @@ const KeyboardAwareScrollView = forwardRef<
133
148
  );
134
149
 
135
150
  /**
136
- * Function that will scroll a ScrollView as keyboard gets moving
151
+ * Function that will scroll a ScrollView as keyboard gets moving.
137
152
  */
138
153
  const maybeScroll = useCallback(
139
154
  (e: number, animated: boolean = false) => {
@@ -28,7 +28,23 @@ const TELEGRAM_ANDROID_TIMING_CONFIG = {
28
28
 
29
29
  /**
30
30
  * Hook that uses default transitions for iOS and Android > 11, and uses
31
- * custom interpolation on Android < 11 to achieve more smooth animation
31
+ * custom interpolation on Android < 11 to achieve more smooth animation.
32
+ *
33
+ * @param handler - Object containing keyboard event handlers.
34
+ * @param [deps] - Dependencies array for the effect.
35
+ * @example
36
+ * ```ts
37
+ * useSmoothKeyboardHandler(
38
+ * {
39
+ * onStart: (e) => {
40
+ * "worklet";
41
+ *
42
+ * // your handler for keyboard start
43
+ * },
44
+ * },
45
+ * [],
46
+ * );
47
+ * ```
32
48
  */
33
49
  export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
34
50
  handler,
@@ -20,10 +20,23 @@ export type KeyboardStickyViewProps = {
20
20
  opened?: number;
21
21
  };
22
22
 
23
- /** Controls whether this `KeyboardStickyView` instance should take effect. Default is `true` */
23
+ /** Controls whether this `KeyboardStickyView` instance should take effect. Default is `true`. */
24
24
  enabled?: boolean;
25
25
  } & ViewProps;
26
26
 
27
+ /**
28
+ * A View component that sticks to the keyboard and moves with it when it appears or disappears.
29
+ * The view can be configured with custom offsets for both closed and open keyboard states.
30
+ *
31
+ * @returns An animated View component that sticks to the keyboard.
32
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-sticky-view|Documentation} page for more details.
33
+ * @example
34
+ * ```tsx
35
+ * <KeyboardStickyView offset={{ closed: 0, opened: 20 }}>
36
+ * <Button title="Submit" />
37
+ * </KeyboardStickyView>
38
+ * ```
39
+ */
27
40
  const KeyboardStickyView = forwardRef<
28
41
  View,
29
42
  React.PropsWithChildren<KeyboardStickyViewProps>
@@ -59,6 +59,9 @@ export type KeyboardToolbarProps = Omit<
59
59
  * A value for container opacity in hexadecimal format (e.g. `ff`). Default value is `ff`.
60
60
  */
61
61
  opacity?: HEX;
62
+ /**
63
+ * A object containing `left`/`right` properties. Used to specify proper container padding in landscape mode.
64
+ */
62
65
  insets?: SafeAreaInsets;
63
66
  } & Pick<KeyboardStickyViewProps, "offset" | "enabled">;
64
67
 
@@ -72,26 +75,35 @@ const KEYBOARD_TOOLBAR_HEIGHT = 42;
72
75
  const DEFAULT_OPACITY: HEX = "FF";
73
76
 
74
77
  /**
75
- * `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` and
76
- * `Done` buttons.
78
+ * `KeyboardToolbar` is a component that is shown above the keyboard with `Prev`/`Next` buttons from left and
79
+ * `Done` button from the right (to dismiss the keyboard). Allows to add customizable content (yours UI elements) in the middle.
80
+ *
81
+ * @param props - Component props.
82
+ * @returns A component that is shown above the keyboard with `Prev`/`Next` and `Done` buttons.
83
+ * @see {@link https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/components/keyboard-toolbar|Documentation} page for more details.
84
+ * @example
85
+ * ```tsx
86
+ * <KeyboardToolbar doneText="Close" />
87
+ * ```
77
88
  */
78
- const KeyboardToolbar: React.FC<KeyboardToolbarProps> = ({
79
- content,
80
- theme = colors,
81
- doneText = "Done",
82
- button,
83
- icon,
84
- showArrows = true,
85
- onNextCallback,
86
- onPrevCallback,
87
- onDoneCallback,
88
- blur = null,
89
- opacity = DEFAULT_OPACITY,
90
- offset: { closed = 0, opened = 0 } = {},
91
- enabled = true,
92
- insets,
93
- ...rest
94
- }) => {
89
+ const KeyboardToolbar: React.FC<KeyboardToolbarProps> = (props) => {
90
+ const {
91
+ content,
92
+ theme = colors,
93
+ doneText = "Done",
94
+ button,
95
+ icon,
96
+ showArrows = true,
97
+ onNextCallback,
98
+ onPrevCallback,
99
+ onDoneCallback,
100
+ blur = null,
101
+ opacity = DEFAULT_OPACITY,
102
+ offset: { closed = 0, opened = 0 } = {},
103
+ enabled = true,
104
+ insets,
105
+ ...rest
106
+ } = props;
95
107
  const colorScheme = useColorScheme();
96
108
  const [inputs, setInputs] = useState({
97
109
  current: 0,
package/src/context.ts CHANGED
@@ -10,20 +10,37 @@ import type React from "react";
10
10
  import type { SharedValue } from "react-native-reanimated";
11
11
 
12
12
  export type AnimatedContext = {
13
+ /**
14
+ * A value between `0` and `1` indicating keyboard position, where `0` means keyboard is closed and `1` means keyboard is fully visible.
15
+ * Represented as `Animated.Value`.
16
+ */
13
17
  progress: Animated.Value;
18
+ /** Height of the keyboard. Represented as `Animated.Value`. */
14
19
  height: Animated.AnimatedMultiplication<number>;
15
20
  };
16
21
  export type ReanimatedContext = {
22
+ /**
23
+ * A value between `0` and `1` indicating keyboard position, where `0` means keyboard is closed and `1` means keyboard is fully visible.
24
+ * Represented as `SharedValue`.
25
+ */
17
26
  progress: SharedValue<number>;
27
+ /** Height of the keyboard. Represented as `SharedValue`. */
18
28
  height: SharedValue<number>;
19
29
  };
20
30
  export type KeyboardAnimationContext = {
31
+ /** Whether KeyboardController library is active or not. */
21
32
  enabled: boolean;
33
+ /** Object that stores animated values that reflect the keyboard’s current position and movement. */
22
34
  animated: AnimatedContext;
35
+ /** Object that stores reanimated values that reflect the keyboard’s current position and movement. */
23
36
  reanimated: ReanimatedContext;
37
+ /** Layout of the focused `TextInput` represented as `SharedValue`. */
24
38
  layout: SharedValue<FocusedInputLayoutChangedEvent | null>;
39
+ /** Method for setting workletized keyboard handlers. */
25
40
  setKeyboardHandlers: (handlers: KeyboardHandler) => () => void;
41
+ /** Method for setting workletized handlers for tracking focused input events. */
26
42
  setInputHandlers: (handlers: FocusedInputHandler) => () => void;
43
+ /** Method to enable/disable KeyboardController library. */
27
44
  setEnabled: React.Dispatch<React.SetStateAction<boolean>>;
28
45
  };
29
46
  const NOOP = () => {};
@@ -57,6 +74,22 @@ const defaultContext: KeyboardAnimationContext = {
57
74
  };
58
75
 
59
76
  export const KeyboardContext = createContext(defaultContext);
77
+
78
+ /**
79
+ * A hook that returns a reference to {@link KeyboardAnimationContext} object.
80
+ *
81
+ * @returns Object {@link KeyboardAnimationContext|containing} keyboard-controller context.
82
+ * @example
83
+ * ```ts
84
+ * const context = useKeyboardContext();
85
+ *
86
+ * useLayoutEffect(() => {
87
+ * const cleanup = context.setInputHandlers(handler);
88
+ *
89
+ * return () => cleanup();
90
+ * }, deps);
91
+ * ```
92
+ */
60
93
  export const useKeyboardContext = () => {
61
94
  const context = useContext(KeyboardContext);
62
95