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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/android/src/fabric/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +7 -0
  2. package/android/src/main/java/com/reactnativekeyboardcontroller/views/ClippingScrollViewDecoratorView.kt +28 -1
  3. package/android/src/paper/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +8 -0
  4. package/ios/animations/KeyboardAnimation.swift +2 -2
  5. package/ios/animations/SpringAnimation.swift +1 -1
  6. package/ios/animations/TimingAnimation.swift +1 -3
  7. package/ios/delegates/KCTextInputCompositeDelegate.swift +2 -2
  8. package/ios/extensions/CGFloat.swift +1 -3
  9. package/ios/interactive/KeyboardAreaExtender.swift +2 -1
  10. package/ios/observers/FocusedInputObserver.swift +4 -2
  11. package/ios/observers/movement/KeyboardTrackingView.swift +4 -1
  12. package/ios/observers/movement/observer/KeyboardMovementObserver+Interactive.swift +2 -0
  13. package/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift +30 -7
  14. package/ios/observers/movement/observer/KeyboardMovementObserver.swift +2 -48
  15. package/ios/protocols/TextInput.swift +1 -1
  16. package/ios/swizzling/UIResponderSwizzle.swift +2 -4
  17. package/ios/traversal/FocusedInputHolder.swift +3 -3
  18. package/ios/traversal/KeyboardView.swift +1 -1
  19. package/ios/traversal/ViewHierarchyNavigator.swift +2 -2
  20. package/ios/views/KeyboardControllerViewManager.swift +5 -5
  21. package/jest/index.js +1 -3
  22. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +43 -11
  23. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  24. package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/hooks.js.map +1 -1
  25. package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/index.js +37 -12
  26. package/lib/commonjs/components/KeyboardChatScrollView/index.js.map +1 -0
  27. package/lib/commonjs/components/KeyboardChatScrollView/types.js.map +1 -0
  28. package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.js +35 -1
  29. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
  30. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +121 -0
  31. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
  32. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js +205 -0
  33. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
  34. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js +6 -0
  35. package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
  36. package/lib/commonjs/components/KeyboardStickyView/index.js +3 -1
  37. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  38. package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js +18 -9
  39. package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js.map +1 -1
  40. package/lib/commonjs/components/hooks/useScrollState.js +20 -1
  41. package/lib/commonjs/components/hooks/useScrollState.js.map +1 -1
  42. package/lib/commonjs/components/index.js +7 -7
  43. package/lib/commonjs/components/index.js.map +1 -1
  44. package/lib/commonjs/index.js +7 -7
  45. package/lib/commonjs/index.js.map +1 -1
  46. package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
  47. package/lib/commonjs/types/views.js.map +1 -1
  48. package/lib/module/components/KeyboardAwareScrollView/index.js +43 -11
  49. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  50. package/lib/module/components/{ChatKit → KeyboardChatScrollView}/hooks.js.map +1 -1
  51. package/lib/module/components/KeyboardChatScrollView/index.js +73 -0
  52. package/lib/module/components/KeyboardChatScrollView/index.js.map +1 -0
  53. package/lib/module/components/KeyboardChatScrollView/types.js.map +1 -0
  54. package/lib/module/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.js +34 -1
  55. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
  56. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +115 -0
  57. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
  58. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js +199 -0
  59. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
  60. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js +2 -0
  61. package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
  62. package/lib/module/components/KeyboardStickyView/index.js +3 -1
  63. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  64. package/lib/module/components/ScrollViewWithBottomPadding/index.js +19 -10
  65. package/lib/module/components/ScrollViewWithBottomPadding/index.js.map +1 -1
  66. package/lib/module/components/hooks/useScrollState.js +21 -2
  67. package/lib/module/components/hooks/useScrollState.js.map +1 -1
  68. package/lib/module/components/index.js +1 -1
  69. package/lib/module/components/index.js.map +1 -1
  70. package/lib/module/index.js +1 -1
  71. package/lib/module/index.js.map +1 -1
  72. package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
  73. package/lib/module/types/views.js.map +1 -1
  74. package/lib/typescript/components/KeyboardChatScrollView/hooks.d.ts +2 -0
  75. package/lib/typescript/components/KeyboardChatScrollView/index.d.ts +12 -0
  76. package/lib/typescript/components/{ChatKit → KeyboardChatScrollView}/types.d.ts +5 -6
  77. package/lib/typescript/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.d.ts +23 -3
  78. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.d.ts +21 -0
  79. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.ios.d.ts +21 -0
  80. package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts +22 -0
  81. package/lib/typescript/components/ScrollViewWithBottomPadding/index.d.ts +2 -4
  82. package/lib/typescript/components/hooks/useScrollState.d.ts +3 -0
  83. package/lib/typescript/components/index.d.ts +2 -2
  84. package/lib/typescript/index.d.ts +2 -2
  85. package/lib/typescript/specs/ClippingScrollViewDecoratorViewNativeComponent.d.ts +1 -0
  86. package/lib/typescript/types/views.d.ts +2 -0
  87. package/package.json +1 -1
  88. package/src/components/KeyboardAwareScrollView/index.tsx +53 -10
  89. package/src/components/KeyboardChatScrollView/hooks.ts +2 -0
  90. package/src/components/KeyboardChatScrollView/index.tsx +106 -0
  91. package/src/components/{ChatKit → KeyboardChatScrollView}/types.ts +5 -6
  92. package/src/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.ts +46 -1
  93. package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts +180 -0
  94. package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ts +300 -0
  95. package/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts +30 -0
  96. package/src/components/KeyboardStickyView/index.tsx +4 -3
  97. package/src/components/ScrollViewWithBottomPadding/index.tsx +22 -25
  98. package/src/components/hooks/useScrollState.ts +24 -2
  99. package/src/components/index.ts +2 -2
  100. package/src/index.ts +2 -2
  101. package/src/specs/ClippingScrollViewDecoratorViewNativeComponent.ts +1 -0
  102. package/src/types/views.ts +2 -0
  103. package/lib/commonjs/components/ChatKit/TODO.md +0 -20
  104. package/lib/commonjs/components/ChatKit/index.js.map +0 -1
  105. package/lib/commonjs/components/ChatKit/types.js.map +0 -1
  106. package/lib/commonjs/components/ChatKit/useChatKeyboard/helpers.js.map +0 -1
  107. package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js +0 -147
  108. package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js.map +0 -1
  109. package/lib/module/components/ChatKit/TODO.md +0 -20
  110. package/lib/module/components/ChatKit/index.js +0 -48
  111. package/lib/module/components/ChatKit/index.js.map +0 -1
  112. package/lib/module/components/ChatKit/types.js.map +0 -1
  113. package/lib/module/components/ChatKit/useChatKeyboard/helpers.js.map +0 -1
  114. package/lib/module/components/ChatKit/useChatKeyboard/index.js +0 -141
  115. package/lib/module/components/ChatKit/useChatKeyboard/index.js.map +0 -1
  116. package/lib/typescript/components/ChatKit/hooks.d.ts +0 -2
  117. package/lib/typescript/components/ChatKit/index.d.ts +0 -14
  118. package/lib/typescript/components/ChatKit/useChatKeyboard/index.d.ts +0 -36
  119. package/src/components/ChatKit/TODO.md +0 -20
  120. package/src/components/ChatKit/hooks.ts +0 -2
  121. package/src/components/ChatKit/index.tsx +0 -63
  122. package/src/components/ChatKit/useChatKeyboard/index.ts +0 -228
  123. /package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/hooks.js +0 -0
  124. /package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/types.js +0 -0
  125. /package/lib/module/components/{ChatKit → KeyboardChatScrollView}/hooks.js +0 -0
  126. /package/lib/module/components/{ChatKit → KeyboardChatScrollView}/types.js +0 -0
@@ -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 };