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.
- package/android/src/fabric/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +7 -0
- package/android/src/main/java/com/reactnativekeyboardcontroller/views/ClippingScrollViewDecoratorView.kt +28 -1
- package/android/src/paper/java/com/reactnativekeyboardcontroller/ClippingScrollViewDecoratorViewManager.kt +8 -0
- package/ios/animations/KeyboardAnimation.swift +2 -2
- package/ios/animations/SpringAnimation.swift +1 -1
- package/ios/animations/TimingAnimation.swift +1 -3
- package/ios/delegates/KCTextInputCompositeDelegate.swift +2 -2
- package/ios/extensions/CGFloat.swift +1 -3
- package/ios/interactive/KeyboardAreaExtender.swift +2 -1
- package/ios/observers/FocusedInputObserver.swift +4 -2
- package/ios/observers/movement/KeyboardTrackingView.swift +4 -1
- package/ios/observers/movement/observer/KeyboardMovementObserver+Interactive.swift +2 -0
- package/ios/observers/movement/observer/KeyboardMovementObserver+Listeners.swift +30 -7
- package/ios/observers/movement/observer/KeyboardMovementObserver.swift +2 -48
- package/ios/protocols/TextInput.swift +1 -1
- package/ios/swizzling/UIResponderSwizzle.swift +2 -4
- package/ios/traversal/FocusedInputHolder.swift +3 -3
- package/ios/traversal/KeyboardView.swift +1 -1
- package/ios/traversal/ViewHierarchyNavigator.swift +2 -2
- package/ios/views/KeyboardControllerViewManager.swift +5 -5
- package/jest/index.js +1 -3
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +43 -11
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/hooks.js.map +1 -1
- package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/index.js +37 -12
- package/lib/commonjs/components/KeyboardChatScrollView/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/types.js.map +1 -0
- package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.js +35 -1
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +121 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js +205 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js +6 -0
- package/lib/commonjs/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
- package/lib/commonjs/components/KeyboardStickyView/index.js +3 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js +18 -9
- package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js.map +1 -1
- package/lib/commonjs/components/hooks/useScrollState.js +20 -1
- package/lib/commonjs/components/hooks/useScrollState.js.map +1 -1
- package/lib/commonjs/components/index.js +7 -7
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/index.js +7 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
- package/lib/commonjs/types/views.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +43 -11
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/{ChatKit → KeyboardChatScrollView}/hooks.js.map +1 -1
- package/lib/module/components/KeyboardChatScrollView/index.js +73 -0
- package/lib/module/components/KeyboardChatScrollView/index.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/types.js.map +1 -0
- package/lib/module/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.js +34 -1
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/helpers.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js +115 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.ios.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js +199 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/index.js.map +1 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js +2 -0
- package/lib/module/components/KeyboardChatScrollView/useChatKeyboard/types.js.map +1 -0
- package/lib/module/components/KeyboardStickyView/index.js +3 -1
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/ScrollViewWithBottomPadding/index.js +19 -10
- package/lib/module/components/ScrollViewWithBottomPadding/index.js.map +1 -1
- package/lib/module/components/hooks/useScrollState.js +21 -2
- package/lib/module/components/hooks/useScrollState.js.map +1 -1
- package/lib/module/components/index.js +1 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/ClippingScrollViewDecoratorViewNativeComponent.js.map +1 -1
- package/lib/module/types/views.js.map +1 -1
- package/lib/typescript/components/KeyboardChatScrollView/hooks.d.ts +2 -0
- package/lib/typescript/components/KeyboardChatScrollView/index.d.ts +12 -0
- package/lib/typescript/components/{ChatKit → KeyboardChatScrollView}/types.d.ts +5 -6
- package/lib/typescript/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.d.ts +23 -3
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.d.ts +21 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/index.ios.d.ts +21 -0
- package/lib/typescript/components/KeyboardChatScrollView/useChatKeyboard/types.d.ts +22 -0
- package/lib/typescript/components/ScrollViewWithBottomPadding/index.d.ts +2 -4
- package/lib/typescript/components/hooks/useScrollState.d.ts +3 -0
- package/lib/typescript/components/index.d.ts +2 -2
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/specs/ClippingScrollViewDecoratorViewNativeComponent.d.ts +1 -0
- package/lib/typescript/types/views.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/KeyboardAwareScrollView/index.tsx +53 -10
- package/src/components/KeyboardChatScrollView/hooks.ts +2 -0
- package/src/components/KeyboardChatScrollView/index.tsx +106 -0
- package/src/components/{ChatKit → KeyboardChatScrollView}/types.ts +5 -6
- package/src/components/{ChatKit → KeyboardChatScrollView}/useChatKeyboard/helpers.ts +46 -1
- package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ios.ts +180 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/index.ts +300 -0
- package/src/components/KeyboardChatScrollView/useChatKeyboard/types.ts +30 -0
- package/src/components/KeyboardStickyView/index.tsx +4 -3
- package/src/components/ScrollViewWithBottomPadding/index.tsx +22 -25
- package/src/components/hooks/useScrollState.ts +24 -2
- package/src/components/index.ts +2 -2
- package/src/index.ts +2 -2
- package/src/specs/ClippingScrollViewDecoratorViewNativeComponent.ts +1 -0
- package/src/types/views.ts +2 -0
- package/lib/commonjs/components/ChatKit/TODO.md +0 -20
- package/lib/commonjs/components/ChatKit/index.js.map +0 -1
- package/lib/commonjs/components/ChatKit/types.js.map +0 -1
- package/lib/commonjs/components/ChatKit/useChatKeyboard/helpers.js.map +0 -1
- package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js +0 -147
- package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js.map +0 -1
- package/lib/module/components/ChatKit/TODO.md +0 -20
- package/lib/module/components/ChatKit/index.js +0 -48
- package/lib/module/components/ChatKit/index.js.map +0 -1
- package/lib/module/components/ChatKit/types.js.map +0 -1
- package/lib/module/components/ChatKit/useChatKeyboard/helpers.js.map +0 -1
- package/lib/module/components/ChatKit/useChatKeyboard/index.js +0 -141
- package/lib/module/components/ChatKit/useChatKeyboard/index.js.map +0 -1
- package/lib/typescript/components/ChatKit/hooks.d.ts +0 -2
- package/lib/typescript/components/ChatKit/index.d.ts +0 -14
- package/lib/typescript/components/ChatKit/useChatKeyboard/index.d.ts +0 -36
- package/src/components/ChatKit/TODO.md +0 -20
- package/src/components/ChatKit/hooks.ts +0 -2
- package/src/components/ChatKit/index.tsx +0 -63
- package/src/components/ChatKit/useChatKeyboard/index.ts +0 -228
- /package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/hooks.js +0 -0
- /package/lib/commonjs/components/{ChatKit → KeyboardChatScrollView}/types.js +0 -0
- /package/lib/module/components/{ChatKit → KeyboardChatScrollView}/hooks.js +0 -0
- /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 };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|