react-native-keyboard-controller 1.21.0-beta.2 → 1.21.0

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 (214) hide show
  1. package/README.md +1 -0
  2. package/android/src/base/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +1 -0
  3. package/android/src/fabric/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +14 -0
  4. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +8 -0
  5. package/android/src/fabric/java/com/reactnativekeyboardcontroller/KeyboardToolbarGroupViewManager.kt +23 -0
  6. package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/ReactContext.kt +12 -0
  7. package/android/src/main/java/com/reactnativekeyboardcontroller/listeners/FocusedInputObserver.kt +2 -1
  8. package/android/src/main/java/com/reactnativekeyboardcontroller/listeners/WindowDimensionListener.kt +5 -1
  9. package/android/src/main/java/com/reactnativekeyboardcontroller/managers/KeyboardToolbarGroupViewManagerImpl.kt +13 -0
  10. package/android/src/main/java/com/reactnativekeyboardcontroller/modal/ModalAttachedWatcher.kt +4 -6
  11. package/android/src/main/java/com/reactnativekeyboardcontroller/modules/KeyboardControllerModuleImpl.kt +26 -0
  12. package/android/src/main/java/com/reactnativekeyboardcontroller/traversal/ViewHierarchyNavigator.kt +31 -4
  13. package/android/src/main/java/com/reactnativekeyboardcontroller/views/ClippingScrollViewDecoratorView.kt +33 -1
  14. package/android/src/main/java/com/reactnativekeyboardcontroller/views/KeyboardToolbarGroupReactViewGroup.kt +13 -0
  15. package/android/src/main/jni/RNKC.h +2 -0
  16. package/android/src/paper/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +16 -0
  17. package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardControllerModule.kt +9 -0
  18. package/android/src/paper/java/com/reactnativekeyboardcontroller/KeyboardToolbarGroupViewManager.kt +15 -0
  19. package/android/src/turbo/java/com/reactnativekeyboardcontroller/KeyboardControllerPackage.kt +2 -0
  20. package/common/cpp/react/renderer/components/RNKC/RNKCClippingScrollViewDecoratorViewComponentDescriptor.h +27 -0
  21. package/common/cpp/react/renderer/components/RNKC/RNKCClippingScrollViewDecoratorViewShadowNode.cpp +14 -0
  22. package/common/cpp/react/renderer/components/RNKC/RNKCClippingScrollViewDecoratorViewShadowNode.h +30 -0
  23. package/common/cpp/react/renderer/components/RNKC/RNKCClippingScrollViewDecoratorViewState.h +28 -0
  24. package/common/cpp/react/renderer/components/RNKC/RNKCKeyboardToolbarGroupViewComponentDescriptor.h +20 -0
  25. package/common/cpp/react/renderer/components/RNKC/RNKCKeyboardToolbarGroupViewShadowNode.cpp +7 -0
  26. package/common/cpp/react/renderer/components/RNKC/RNKCKeyboardToolbarGroupViewShadowNode.h +23 -0
  27. package/common/cpp/react/renderer/components/RNKC/RNKCKeyboardToolbarGroupViewState.h +21 -0
  28. package/ios/KeyboardControllerModule.mm +36 -0
  29. package/ios/animations/KeyboardAnimation.swift +2 -2
  30. package/ios/animations/SpringAnimation.swift +1 -1
  31. package/ios/animations/TimingAnimation.swift +1 -3
  32. package/ios/delegates/KCTextInputCompositeDelegate.swift +2 -2
  33. package/ios/extensions/CGFloat.swift +1 -3
  34. package/ios/extensions/UIApplication.swift +1 -1
  35. package/ios/interactive/KeyboardAreaExtender.swift +2 -1
  36. package/ios/observers/FocusedInputObserver.swift +6 -3
  37. package/ios/observers/movement/KeyboardTrackingView.swift +4 -1
  38. package/ios/observers/movement/observer/KeyboardMovementObserver+Interactive.swift +2 -0
  39. package/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift +30 -7
  40. package/ios/observers/movement/observer/KeyboardMovementObserver.swift +2 -48
  41. package/ios/protocols/TextInput.swift +1 -1
  42. package/ios/swizzling/UIResponderSwizzle.swift +2 -4
  43. package/ios/traversal/FocusedInputHolder.swift +3 -3
  44. package/ios/traversal/KeyboardView.swift +1 -1
  45. package/ios/traversal/ViewHierarchyNavigator.swift +51 -5
  46. package/ios/views/ClippingScrollViewDecoratorViewManager.h +26 -0
  47. package/ios/views/ClippingScrollViewDecoratorViewManager.mm +231 -0
  48. package/ios/views/KeyboardControllerViewManager.swift +5 -5
  49. package/ios/views/KeyboardToolbarGroupViewManager.h +28 -0
  50. package/ios/views/KeyboardToolbarGroupViewManager.mm +88 -0
  51. package/jest/index.js +12 -4
  52. package/lib/commonjs/bindings.js +18 -2
  53. package/lib/commonjs/bindings.js.map +1 -1
  54. package/lib/commonjs/bindings.native.js +3 -4
  55. package/lib/commonjs/bindings.native.js.map +1 -1
  56. package/lib/commonjs/components/KeyboardAvoidingView/index.js +30 -4
  57. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
  58. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +55 -14
  59. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  60. package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/hooks.js.map +1 -1
  61. package/lib/commonjs/components/KeyboardChatScrollView/index.js +111 -0
  62. package/lib/commonjs/components/KeyboardChatScrollView/index.js.map +1 -0
  63. package/lib/commonjs/components/KeyboardChatScrollView/types.js.map +1 -0
  64. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js +221 -0
  65. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
  66. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +149 -0
  67. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
  68. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js +240 -0
  69. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
  70. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js +6 -0
  71. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
  72. package/lib/commonjs/components/KeyboardChatScrollView/useExtraContentPadding/index.js +72 -0
  73. package/lib/commonjs/components/KeyboardChatScrollView/useExtraContentPadding/index.js.map +1 -0
  74. package/lib/commonjs/components/KeyboardStickyView/index.js +3 -1
  75. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  76. package/lib/commonjs/components/KeyboardToolbar/index.js +1 -0
  77. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -1
  78. package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js +36 -15
  79. package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js.map +1 -1
  80. package/lib/commonjs/components/hooks/useScrollState.js +20 -1
  81. package/lib/commonjs/components/hooks/useScrollState.js.map +1 -1
  82. package/lib/commonjs/components/index.js +7 -7
  83. package/lib/commonjs/components/index.js.map +1 -1
  84. package/lib/commonjs/index.js +7 -7
  85. package/lib/commonjs/index.js.map +1 -1
  86. package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js +1 -2
  87. package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
  88. package/lib/commonjs/specs/KeyboardToolbarGroupViewNativeComponent.js +12 -0
  89. package/lib/commonjs/specs/KeyboardToolbarGroupViewNativeComponent.js.map +1 -0
  90. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
  91. package/lib/commonjs/types/module.js.map +1 -1
  92. package/lib/commonjs/types/views.js.map +1 -1
  93. package/lib/module/bindings.js +17 -1
  94. package/lib/module/bindings.js.map +1 -1
  95. package/lib/module/bindings.native.js +2 -3
  96. package/lib/module/bindings.native.js.map +1 -1
  97. package/lib/module/components/KeyboardAvoidingView/index.js +29 -4
  98. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
  99. package/lib/module/components/KeyboardAwareScrollView/index.js +55 -14
  100. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  101. package/lib/module/components/{ChatKit → KeyboardChatScrollView}/hooks.js.map +1 -1
  102. package/lib/module/components/KeyboardChatScrollView/index.js +104 -0
  103. package/lib/module/components/KeyboardChatScrollView/index.js.map +1 -0
  104. package/lib/module/components/KeyboardChatScrollView/types.js.map +1 -0
  105. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js +207 -0
  106. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
  107. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +143 -0
  108. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
  109. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js +234 -0
  110. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
  111. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js +2 -0
  112. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
  113. package/lib/module/components/KeyboardChatScrollView/useExtraContentPadding/index.js +67 -0
  114. package/lib/module/components/KeyboardChatScrollView/useExtraContentPadding/index.js.map +1 -0
  115. package/lib/module/components/KeyboardStickyView/index.js +3 -1
  116. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  117. package/lib/module/components/KeyboardToolbar/index.js +2 -1
  118. package/lib/module/components/KeyboardToolbar/index.js.map +1 -1
  119. package/lib/module/components/ScrollViewWithBottomPadding/index.js +38 -17
  120. package/lib/module/components/ScrollViewWithBottomPadding/index.js.map +1 -1
  121. package/lib/module/components/hooks/useScrollState.js +21 -2
  122. package/lib/module/components/hooks/useScrollState.js.map +1 -1
  123. package/lib/module/components/index.js +1 -1
  124. package/lib/module/components/index.js.map +1 -1
  125. package/lib/module/index.js +1 -1
  126. package/lib/module/index.js.map +1 -1
  127. package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js +1 -2
  128. package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
  129. package/lib/module/specs/KeyboardToolbarGroupViewNativeComponent.js +5 -0
  130. package/lib/module/specs/KeyboardToolbarGroupViewNativeComponent.js.map +1 -0
  131. package/lib/module/specs/NativeKeyboardController.js.map +1 -1
  132. package/lib/module/types/module.js.map +1 -1
  133. package/lib/module/types/views.js.map +1 -1
  134. package/lib/typescript/bindings.d.ts +12 -2
  135. package/lib/typescript/bindings.native.d.ts +2 -1
  136. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +44 -13
  137. package/lib/typescript/components/KeyboardChatScrollView/hooks.d.ts +2 -0
  138. package/lib/typescript/components/KeyboardChatScrollView/index.d.ts +15 -0
  139. package/lib/typescript/components/{ChatKit → KeyboardChatScrollView}/types.d.ts +46 -6
  140. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/helpers.d.ts +132 -0
  141. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.d.ts +18 -0
  142. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.ios.d.ts +21 -0
  143. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts +37 -0
  144. package/lib/typescript/components/KeyboardChatScrollView/useExtraContentPadding/index.d.ts +43 -0
  145. package/lib/typescript/components/KeyboardToolbar/index.d.ts +2 -0
  146. package/lib/typescript/components/ScrollViewWithBottomPadding/index.d.ts +5 -4
  147. package/lib/typescript/components/hooks/useScrollState.d.ts +3 -0
  148. package/lib/typescript/components/index.d.ts +2 -2
  149. package/lib/typescript/index.d.ts +2 -2
  150. package/lib/typescript/specs/ClippingScrollViewDecoratorViewNativeComponent.d.ts +2 -0
  151. package/lib/typescript/specs/KeyboardToolbarGroupViewNativeComponent.d.ts +6 -0
  152. package/lib/typescript/specs/NativeKeyboardController.d.ts +1 -0
  153. package/lib/typescript/types/module.d.ts +7 -0
  154. package/lib/typescript/types/views.d.ts +4 -0
  155. package/package.json +6 -2
  156. package/react-native.config.js +2 -0
  157. package/src/bindings.native.ts +4 -4
  158. package/src/bindings.ts +15 -1
  159. package/src/components/KeyboardAvoidingView/index.tsx +56 -29
  160. package/src/components/KeyboardAwareScrollView/index.tsx +68 -13
  161. package/src/components/KeyboardChatScrollView/hooks.ts +2 -0
  162. package/src/components/KeyboardChatScrollView/index.tsx +150 -0
  163. package/src/components/{ChatKit → KeyboardChatScrollView}/types.ts +46 -6
  164. package/src/components/KeyboardChatScrollView/useChatKeyboard/helpers.ts +268 -0
  165. package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts +260 -0
  166. package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ts +376 -0
  167. package/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts +39 -0
  168. package/src/components/KeyboardChatScrollView/useExtraContentPadding/index.ts +123 -0
  169. package/src/components/KeyboardStickyView/index.tsx +4 -3
  170. package/src/components/KeyboardToolbar/index.tsx +6 -1
  171. package/src/components/ScrollViewWithBottomPadding/index.tsx +53 -29
  172. package/src/components/hooks/useScrollState.ts +24 -2
  173. package/src/components/index.ts +2 -2
  174. package/src/index.ts +2 -2
  175. package/src/specs/ClippingScrollViewDecoratorViewNativeComponent.ts +2 -1
  176. package/src/specs/KeyboardToolbarGroupViewNativeComponent.ts +10 -0
  177. package/src/specs/NativeKeyboardController.ts +1 -0
  178. package/src/types/module.ts +9 -0
  179. package/src/types/views.ts +4 -0
  180. package/android/.settings/org.eclipse.buildship.core.prefs +0 -2
  181. package/ios/KeyboardController.xcodeproj/xcuserdata/kirylziusko.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  182. package/ios/Tests/Tests.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  183. package/ios/Tests/Tests.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  184. package/ios/Tests/Tests.xcodeproj/project.xcworkspace/xcuserdata/kirylziusko.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  185. package/ios/Tests/Tests.xcodeproj/xcuserdata/kirylziusko.xcuserdatad/xcschemes/xcschememanagement.plist +0 -32
  186. package/lib/commonjs/components/ChatKit/TODO.md +0 -20
  187. package/lib/commonjs/components/ChatKit/index.js +0 -55
  188. package/lib/commonjs/components/ChatKit/index.js.map +0 -1
  189. package/lib/commonjs/components/ChatKit/types.js.map +0 -1
  190. package/lib/commonjs/components/ChatKit/useChatKeyboard/helpers.js +0 -101
  191. package/lib/commonjs/components/ChatKit/useChatKeyboard/helpers.js.map +0 -1
  192. package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js +0 -147
  193. package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js.map +0 -1
  194. package/lib/module/components/ChatKit/TODO.md +0 -20
  195. package/lib/module/components/ChatKit/index.js +0 -48
  196. package/lib/module/components/ChatKit/index.js.map +0 -1
  197. package/lib/module/components/ChatKit/types.js.map +0 -1
  198. package/lib/module/components/ChatKit/useChatKeyboard/helpers.js +0 -92
  199. package/lib/module/components/ChatKit/useChatKeyboard/helpers.js.map +0 -1
  200. package/lib/module/components/ChatKit/useChatKeyboard/index.js +0 -141
  201. package/lib/module/components/ChatKit/useChatKeyboard/index.js.map +0 -1
  202. package/lib/typescript/components/ChatKit/hooks.d.ts +0 -2
  203. package/lib/typescript/components/ChatKit/index.d.ts +0 -14
  204. package/lib/typescript/components/ChatKit/useChatKeyboard/helpers.d.ts +0 -57
  205. package/lib/typescript/components/ChatKit/useChatKeyboard/index.d.ts +0 -36
  206. package/src/components/ChatKit/TODO.md +0 -20
  207. package/src/components/ChatKit/hooks.ts +0 -2
  208. package/src/components/ChatKit/index.tsx +0 -63
  209. package/src/components/ChatKit/useChatKeyboard/helpers.ts +0 -118
  210. package/src/components/ChatKit/useChatKeyboard/index.ts +0 -228
  211. /package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/hooks.js +0 -0
  212. /package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/types.js +0 -0
  213. /package/lib/module/components/{ChatKit → KeyboardChatScrollView}/hooks.js +0 -0
  214. /package/lib/module/components/{ChatKit → KeyboardChatScrollView}/types.js +0 -0
@@ -1,2 +0,0 @@
1
- export { useChatKeyboard } from "./useChatKeyboard";
2
- export type { KeyboardLiftBehavior } from "./useChatKeyboard";
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import Reanimated from "react-native-reanimated";
3
- declare const ChatKit: {
4
- ScrollView: React.ForwardRefExoticComponent<{
5
- ScrollViewComponent: import("../ScrollViewWithBottomPadding").AnimatedScrollViewComponent;
6
- inverted?: boolean;
7
- offset?: number;
8
- keyboardLiftBehavior?: "always" | "never" | "whenAtEnd" | "persistent";
9
- freeze?: boolean;
10
- } & import("react-native").ScrollViewProps & {
11
- children?: React.ReactNode | undefined;
12
- } & React.RefAttributes<Reanimated.ScrollView>>;
13
- };
14
- export default ChatKit;
@@ -1,57 +0,0 @@
1
- type KeyboardLiftBehavior = "always" | "whenAtEnd" | "persistent" | "never";
2
- /**
3
- * Check whether the scroll view is at the end of its content.
4
- *
5
- * @param scrollOffset - Current vertical scroll offset.
6
- * @param layoutHeight - Visible height of the scroll view.
7
- * @param contentHeight - Total height of the scrollable content.
8
- * @returns `true` if the scroll position is within the threshold of the content end.
9
- * @example
10
- * ```ts
11
- * const atEnd = isScrollAtEnd(100, 800, 920); // true (100 + 800 >= 920 - 20)
12
- * ```
13
- */
14
- export declare function isScrollAtEnd(scrollOffset: number, layoutHeight: number, contentHeight: number): boolean;
15
- /**
16
- * Decide whether content should be shifted based on the keyboard lift behavior.
17
- *
18
- * @param behavior - The configured keyboard lift behavior.
19
- * @param isAtEnd - Whether the scroll view is currently at the end.
20
- * @returns `true` if content should be shifted.
21
- * @example
22
- * ```ts
23
- * shouldShiftContent("always", false); // true
24
- * shouldShiftContent("whenAtEnd", false); // false
25
- * ```
26
- */
27
- export declare function shouldShiftContent(behavior: KeyboardLiftBehavior, isAtEnd: boolean): boolean;
28
- /**
29
- * Compute the clamped scroll target for non-inverted lists.
30
- *
31
- * @param offsetBeforeScroll - Scroll position before keyboard appeared.
32
- * @param keyboardHeight - Current keyboard height.
33
- * @param contentHeight - Total height of the scrollable content.
34
- * @param layoutHeight - Visible height of the scroll view.
35
- * @returns Clamped scroll target between 0 and maxScroll.
36
- * @example
37
- * ```ts
38
- * clampedScrollTarget(100, 300, 1000, 800); // 400
39
- * ```
40
- */
41
- export declare function clampedScrollTarget(offsetBeforeScroll: number, keyboardHeight: number, contentHeight: number, layoutHeight: number): number;
42
- /**
43
- * Compute contentOffset.y for iOS lists.
44
- *
45
- * @param relativeScroll - Scroll position relative to current inset.
46
- * @param keyboardHeight - Target keyboard height.
47
- * @param contentHeight - Total height of the scrollable content.
48
- * @param layoutHeight - Visible height of the scroll view.
49
- * @param inverted - Whether the list is inverted.
50
- * @returns The absolute contentOffset.y to set.
51
- * @example
52
- * ```ts
53
- * computeIOSContentOffset(100, 300, 1000, 800, false); // 400
54
- * ```
55
- */
56
- export declare function computeIOSContentOffset(relativeScroll: number, keyboardHeight: number, contentHeight: number, layoutHeight: number, inverted: boolean): number;
57
- export {};
@@ -1,36 +0,0 @@
1
- import type { AnimatedRef, SharedValue } from "react-native-reanimated";
2
- import type Reanimated from "react-native-reanimated";
3
- type KeyboardLiftBehavior = "always" | "whenAtEnd" | "persistent" | "never";
4
- type UseChatKeyboardOptions = {
5
- inverted: boolean;
6
- keyboardLiftBehavior: KeyboardLiftBehavior;
7
- freeze: boolean;
8
- offset: number;
9
- };
10
- type UseChatKeyboardReturn = {
11
- /** Extra scrollable space (= keyboard height). Used as contentInset on iOS, contentInsetBottom on Android. */
12
- padding: SharedValue<number>;
13
- /** Absolute Y content offset for iOS (set once in onStart). `undefined` on Android. */
14
- contentOffsetY: SharedValue<number> | undefined;
15
- /** TranslateY for the container wrapper on Android inverted lists. 0 otherwise. */
16
- containerTranslateY: SharedValue<number>;
17
- };
18
- /**
19
- * Hook that manages keyboard-driven scrolling for chat-style scroll views.
20
- * Calculates padding (extra scrollable space) and content shift values,
21
- * using the optimal strategy per platform.
22
- *
23
- * @param scrollViewRef - Animated ref to the scroll view.
24
- * @param options - Configuration for inverted and keyboardLiftBehavior.
25
- * @returns Shared values for padding, contentOffsetY (iOS), and containerTranslateY (Android inverted).
26
- * @example
27
- * ```tsx
28
- * const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(ref, {
29
- * inverted: false,
30
- * keyboardLiftBehavior: "always",
31
- * });
32
- * ```
33
- */
34
- declare function useChatKeyboard(scrollViewRef: AnimatedRef<Reanimated.ScrollView>, options: UseChatKeyboardOptions): UseChatKeyboardReturn;
35
- export { useChatKeyboard };
36
- export type { KeyboardLiftBehavior };
@@ -1,20 +0,0 @@
1
- # Findings
2
-
3
- 1. We can not translate whole `ScrollView` because interactive dismissal will have double scroll if we move it by `translateY` or content will be truncated if we don't do it (same with external container).
4
- 2. So we need to move only content inside `ScrollView`.
5
- 3. If we use a separate `scrollTo` we still may have a random jump. The only one way is to use `contentOffset` + `padding` on `ScrollView`.
6
- 4. Input must be always in `KeyboardStickyView` because it's always pushing above the keyboard (unlike content, which may stay in place).
7
- 5. Changing `contentOffset` on `ScrollView` will not work. On iOS it works, but on Android sometimes it doesn't scroll to correct position (when you scroll list to the end) and on paper architecture it is flickering.
8
- 6. Next idea is to use `contentInset` on iOS and create custom `ClippingScrollView` on Android (with polyfill `contentInsetBottom` prop).
9
-
10
- ## To Do
11
-
12
- - [x] check how `ClippingScrollView` works in `KeyboardAwareScrollView` on Android (seems to be working well)
13
- - [x] introduce `useCombinedRef` hook in separate PR
14
- - [x] make sure, that style property doesn't affect the behavior with/without `ClippingScrollView` (test on a ScrollView that doesn't tke full screen?) <-- tested by comparing iOS with Android + `ClippingScrollView` (`contentInsetBottom` never override `paddingBottom` from `style`/`contentContainerStyle` even if ScrollView has `maxHeight=150` and we have only 2 inputs limitation + also tested `ScrollView` without height restrictions, in this case `paddingBottom` on `style` is not getting applied (it doesn't have an effect on both iOS/Android), but `contentContainerStyle` + `paddingBottom` works as expected and if I add `contentInsetBottom` to `ClippingScrollView` it doesn't overwrite a padding and increases scrollable area)
15
- - [x] `ClippingScrollView` + `KeyboardAwareScrollView` check by e2e tests (seems to be working, though on Android emulator + e2e tests sometimes when keyboard disappear we still have keyboard space)
16
- - [x] introduce `ClippingScrollView` in separate PR
17
- - [x] create a polyfill-version of ScrollView `that` can add scrollable padding in the bottom of the content? How to wrap custom `ScrollView` with it (cause we may pass one from react-native-gesture-handler)? Should just adjust `contentInset` (scroll management should belong to `KeyboardAwareScrollView`) (ScrollViewWithKeyboardPadding/ScrollViewWithKeyboardSpace)
18
- - [x] use `ClippingScrollView` in `KeyboardAwareScrollView` in separate PR
19
- - [-] introduce `ChatKit`
20
- - [] create issue in reanimated repo about `scrollTo` performance regression
@@ -1,2 +0,0 @@
1
- export { useChatKeyboard } from "./useChatKeyboard";
2
- export type { KeyboardLiftBehavior } from "./useChatKeyboard";
@@ -1,63 +0,0 @@
1
- import React, { forwardRef } from "react";
2
- import { useAnimatedRef, useAnimatedStyle } from "react-native-reanimated";
3
- import Reanimated from "react-native-reanimated";
4
-
5
- import useCombinedRef from "../hooks/useCombinedRef";
6
- import ScrollViewWithBottomPadding from "../ScrollViewWithBottomPadding";
7
-
8
- import { useChatKeyboard } from "./useChatKeyboard";
9
-
10
- import type { ChatKitScrollViewProps } from "./types";
11
-
12
- const ChatScrollView = forwardRef<
13
- Reanimated.ScrollView,
14
- React.PropsWithChildren<ChatKitScrollViewProps>
15
- >(
16
- (
17
- {
18
- children,
19
- ScrollViewComponent = Reanimated.ScrollView,
20
- inverted = false,
21
- keyboardLiftBehavior = "always",
22
- freeze = false,
23
- offset = 0,
24
- ...rest
25
- },
26
- ref,
27
- ) => {
28
- const scrollViewRef = useAnimatedRef<Reanimated.ScrollView>();
29
- const onRef = useCombinedRef(ref, scrollViewRef);
30
-
31
- const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(
32
- scrollViewRef,
33
- { inverted, keyboardLiftBehavior, freeze, offset },
34
- );
35
-
36
- const containerStyle = useAnimatedStyle(
37
- () => ({
38
- transform: [{ translateY: containerTranslateY.value }],
39
- }),
40
- [],
41
- );
42
-
43
- return (
44
- <ScrollViewWithBottomPadding
45
- ref={onRef}
46
- {...rest}
47
- bottomPadding={padding}
48
- containerStyle={containerStyle}
49
- contentOffsetY={contentOffsetY}
50
- inverted={inverted}
51
- ScrollViewComponent={ScrollViewComponent}
52
- >
53
- {children}
54
- </ScrollViewWithBottomPadding>
55
- );
56
- },
57
- );
58
-
59
- const ChatKit = {
60
- ScrollView: ChatScrollView,
61
- };
62
-
63
- export default ChatKit;
@@ -1,118 +0,0 @@
1
- type KeyboardLiftBehavior = "always" | "whenAtEnd" | "persistent" | "never";
2
-
3
- const AT_END_THRESHOLD = 20;
4
-
5
- /**
6
- * Check whether the scroll view is at the end of its content.
7
- *
8
- * @param scrollOffset - Current vertical scroll offset.
9
- * @param layoutHeight - Visible height of the scroll view.
10
- * @param contentHeight - Total height of the scrollable content.
11
- * @returns `true` if the scroll position is within the threshold of the content end.
12
- * @example
13
- * ```ts
14
- * const atEnd = isScrollAtEnd(100, 800, 920); // true (100 + 800 >= 920 - 20)
15
- * ```
16
- */
17
- export function isScrollAtEnd(
18
- scrollOffset: number,
19
- layoutHeight: number,
20
- contentHeight: number,
21
- ): boolean {
22
- "worklet";
23
-
24
- return scrollOffset + layoutHeight >= contentHeight - AT_END_THRESHOLD;
25
- }
26
-
27
- /**
28
- * Decide whether content should be shifted based on the keyboard lift behavior.
29
- *
30
- * @param behavior - The configured keyboard lift behavior.
31
- * @param isAtEnd - Whether the scroll view is currently at the end.
32
- * @returns `true` if content should be shifted.
33
- * @example
34
- * ```ts
35
- * shouldShiftContent("always", false); // true
36
- * shouldShiftContent("whenAtEnd", false); // false
37
- * ```
38
- */
39
- export function shouldShiftContent(
40
- behavior: KeyboardLiftBehavior,
41
- isAtEnd: boolean,
42
- ): boolean {
43
- "worklet";
44
-
45
- switch (behavior) {
46
- case "always":
47
- return true;
48
- case "never":
49
- return false;
50
- case "whenAtEnd":
51
- return isAtEnd;
52
- case "persistent":
53
- return true;
54
- }
55
- }
56
-
57
- /**
58
- * Compute the clamped scroll target for non-inverted lists.
59
- *
60
- * @param offsetBeforeScroll - Scroll position before keyboard appeared.
61
- * @param keyboardHeight - Current keyboard height.
62
- * @param contentHeight - Total height of the scrollable content.
63
- * @param layoutHeight - Visible height of the scroll view.
64
- * @returns Clamped scroll target between 0 and maxScroll.
65
- * @example
66
- * ```ts
67
- * clampedScrollTarget(100, 300, 1000, 800); // 400
68
- * ```
69
- */
70
- export function clampedScrollTarget(
71
- offsetBeforeScroll: number,
72
- keyboardHeight: number,
73
- contentHeight: number,
74
- layoutHeight: number,
75
- ): number {
76
- "worklet";
77
-
78
- const maxScroll = Math.max(contentHeight - layoutHeight + keyboardHeight, 0);
79
-
80
- return Math.min(Math.max(offsetBeforeScroll + keyboardHeight, 0), maxScroll);
81
- }
82
-
83
- /**
84
- * Compute contentOffset.y for iOS lists.
85
- *
86
- * @param relativeScroll - Scroll position relative to current inset.
87
- * @param keyboardHeight - Target keyboard height.
88
- * @param contentHeight - Total height of the scrollable content.
89
- * @param layoutHeight - Visible height of the scroll view.
90
- * @param inverted - Whether the list is inverted.
91
- * @returns The absolute contentOffset.y to set.
92
- * @example
93
- * ```ts
94
- * computeIOSContentOffset(100, 300, 1000, 800, false); // 400
95
- * ```
96
- */
97
- export function computeIOSContentOffset(
98
- relativeScroll: number,
99
- keyboardHeight: number,
100
- contentHeight: number,
101
- layoutHeight: number,
102
- inverted: boolean,
103
- ): number {
104
- "worklet";
105
-
106
- if (inverted) {
107
- const maxScroll = Math.max(contentHeight - layoutHeight, 0);
108
-
109
- return Math.max(
110
- Math.min(relativeScroll - keyboardHeight, maxScroll),
111
- -keyboardHeight,
112
- );
113
- }
114
-
115
- const maxScroll = Math.max(contentHeight - layoutHeight + keyboardHeight, 0);
116
-
117
- return Math.min(Math.max(keyboardHeight + relativeScroll, 0), maxScroll);
118
- }
@@ -1,228 +0,0 @@
1
- import { Platform } from "react-native";
2
- import { interpolate, scrollTo, useSharedValue } from "react-native-reanimated";
3
-
4
- import { useKeyboardHandler } from "../../../hooks";
5
- import useScrollState from "../../hooks/useScrollState";
6
-
7
- import {
8
- clampedScrollTarget,
9
- computeIOSContentOffset,
10
- isScrollAtEnd,
11
- shouldShiftContent,
12
- } from "./helpers";
13
-
14
- import type { AnimatedRef, SharedValue } from "react-native-reanimated";
15
- import type Reanimated from "react-native-reanimated";
16
-
17
- const OS = Platform.OS;
18
-
19
- type KeyboardLiftBehavior = "always" | "whenAtEnd" | "persistent" | "never";
20
-
21
- type UseChatKeyboardOptions = {
22
- inverted: boolean;
23
- keyboardLiftBehavior: KeyboardLiftBehavior;
24
- freeze: boolean;
25
- offset: number;
26
- };
27
-
28
- type UseChatKeyboardReturn = {
29
- /** Extra scrollable space (= keyboard height). Used as contentInset on iOS, contentInsetBottom on Android. */
30
- padding: SharedValue<number>;
31
- /** Absolute Y content offset for iOS (set once in onStart). `undefined` on Android. */
32
- contentOffsetY: SharedValue<number> | undefined;
33
- /** TranslateY for the container wrapper on Android inverted lists. 0 otherwise. */
34
- containerTranslateY: SharedValue<number>;
35
- };
36
-
37
- /**
38
- * Hook that manages keyboard-driven scrolling for chat-style scroll views.
39
- * Calculates padding (extra scrollable space) and content shift values,
40
- * using the optimal strategy per platform.
41
- *
42
- * @param scrollViewRef - Animated ref to the scroll view.
43
- * @param options - Configuration for inverted and keyboardLiftBehavior.
44
- * @returns Shared values for padding, contentOffsetY (iOS), and containerTranslateY (Android inverted).
45
- * @example
46
- * ```tsx
47
- * const { padding, contentOffsetY, containerTranslateY } = useChatKeyboard(ref, {
48
- * inverted: false,
49
- * keyboardLiftBehavior: "always",
50
- * });
51
- * ```
52
- */
53
- function useChatKeyboard(
54
- scrollViewRef: AnimatedRef<Reanimated.ScrollView>,
55
- options: UseChatKeyboardOptions,
56
- ): UseChatKeyboardReturn {
57
- const { inverted, keyboardLiftBehavior, freeze, offset } = options;
58
-
59
- const padding = useSharedValue(0);
60
- const contentOffsetY = useSharedValue(0);
61
- const containerTranslateY = useSharedValue(0);
62
- const offsetBeforeScroll = useSharedValue(0);
63
- const targetKeyboardHeight = useSharedValue(0);
64
-
65
- const { layout, size, offset: scroll } = useScrollState(scrollViewRef);
66
-
67
- const getEffectiveHeight = (height: number): number => {
68
- "worklet";
69
-
70
- if (offset === 0 || targetKeyboardHeight.value === 0) {
71
- return height;
72
- }
73
-
74
- return interpolate(
75
- height,
76
- [0, targetKeyboardHeight.value],
77
- [0, Math.max(targetKeyboardHeight.value - offset, 0)],
78
- );
79
- };
80
-
81
- useKeyboardHandler(
82
- {
83
- onStart: (e) => {
84
- "worklet";
85
-
86
- if (freeze) {
87
- return;
88
- }
89
-
90
- if (e.height > 0) {
91
- // eslint-disable-next-line react-compiler/react-compiler
92
- targetKeyboardHeight.value = e.height;
93
- }
94
-
95
- const effective = getEffectiveHeight(e.height);
96
-
97
- const atEnd = isScrollAtEnd(
98
- scroll.value,
99
- layout.value.height,
100
- size.value.height,
101
- );
102
-
103
- if (OS === "ios") {
104
- // iOS: set padding + contentOffset once in onStart
105
- const relativeScroll = inverted
106
- ? scroll.value + padding.value
107
- : scroll.value - padding.value;
108
-
109
- padding.value = effective;
110
-
111
- if (!shouldShiftContent(keyboardLiftBehavior, atEnd)) {
112
- return;
113
- }
114
-
115
- if (
116
- keyboardLiftBehavior === "persistent" &&
117
- effective < padding.value
118
- ) {
119
- return;
120
- }
121
-
122
- contentOffsetY.value = computeIOSContentOffset(
123
- relativeScroll,
124
- effective,
125
- size.value.height,
126
- layout.value.height,
127
- inverted,
128
- );
129
- } else if (e.height > 0) {
130
- // Android: keyboard opening — set padding + capture scroll position
131
- padding.value = effective;
132
- offsetBeforeScroll.value = scroll.value;
133
-
134
- if (keyboardLiftBehavior === "whenAtEnd" && !atEnd) {
135
- // Sentinel: don't scroll in onMove
136
- offsetBeforeScroll.value = -1;
137
- }
138
- } else {
139
- // Android: keyboard closing — re-capture from current position
140
- // so onMove smoothly scrolls back from where the user is now
141
- offsetBeforeScroll.value = scroll.value - padding.value;
142
- }
143
- },
144
- onMove: (e) => {
145
- "worklet";
146
-
147
- if (freeze) {
148
- return;
149
- }
150
-
151
- // iOS doesn't need per-frame updates (contentOffset handles it)
152
- if (OS === "ios") {
153
- return;
154
- }
155
-
156
- if (!shouldShiftContent(keyboardLiftBehavior, true)) {
157
- return;
158
- }
159
-
160
- // "whenAtEnd" sentinel check
161
- if (offsetBeforeScroll.value === -1) {
162
- return;
163
- }
164
-
165
- const effective = getEffectiveHeight(e.height);
166
-
167
- if (inverted) {
168
- // Android inverted: translateY on container
169
- if (
170
- keyboardLiftBehavior === "persistent" &&
171
- effective < Math.abs(containerTranslateY.value)
172
- ) {
173
- return;
174
- }
175
-
176
- containerTranslateY.value = -effective;
177
- } else {
178
- // Android non-inverted: scrollTo per-frame
179
- if (
180
- keyboardLiftBehavior === "persistent" &&
181
- effective < scroll.value - offsetBeforeScroll.value
182
- ) {
183
- return;
184
- }
185
-
186
- const target = clampedScrollTarget(
187
- offsetBeforeScroll.value,
188
- effective,
189
- size.value.height,
190
- layout.value.height,
191
- );
192
-
193
- scrollTo(scrollViewRef, 0, target, false);
194
- }
195
- },
196
- onEnd: (e) => {
197
- "worklet";
198
-
199
- if (freeze) {
200
- return;
201
- }
202
-
203
- const effective = getEffectiveHeight(e.height);
204
-
205
- padding.value = effective;
206
-
207
- if (
208
- OS !== "ios" &&
209
- inverted &&
210
- e.height === 0 &&
211
- keyboardLiftBehavior !== "persistent"
212
- ) {
213
- containerTranslateY.value = 0;
214
- }
215
- },
216
- },
217
- [inverted, keyboardLiftBehavior, freeze, offset],
218
- );
219
-
220
- return {
221
- padding,
222
- contentOffsetY: OS === "ios" ? contentOffsetY : undefined,
223
- containerTranslateY,
224
- };
225
- }
226
-
227
- export { useChatKeyboard };
228
- export type { KeyboardLiftBehavior };