react-native-keyboard-controller 1.21.0-beta.0 → 1.21.0-beta.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.
- package/ios/animations/KeyboardAnimation.swift +2 -2
- package/ios/animations/SpringAnimation.swift +1 -1
- package/ios/animations/TimingAnimation.swift +3 -1
- package/ios/delegates/KCTextInputCompositeDelegate.swift +2 -2
- package/ios/extensions/CGFloat.swift +3 -1
- package/ios/interactive/KeyboardAreaExtender.swift +1 -2
- package/ios/observers/FocusedInputObserver.swift +2 -4
- package/ios/observers/movement/KeyboardTrackingView.swift +1 -4
- package/ios/protocols/TextInput.swift +1 -1
- package/ios/swizzling/UIResponderSwizzle.swift +4 -2
- 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 +3 -0
- package/lib/commonjs/components/ChatKit/TODO.md +20 -0
- package/lib/commonjs/components/ChatKit/hooks.js +13 -0
- package/lib/commonjs/components/ChatKit/hooks.js.map +1 -0
- package/lib/commonjs/components/ChatKit/index.js +55 -0
- package/lib/commonjs/components/ChatKit/index.js.map +1 -0
- package/lib/commonjs/components/ChatKit/types.js +6 -0
- package/lib/commonjs/components/ChatKit/types.js.map +1 -0
- package/lib/commonjs/components/ChatKit/useChatKeyboard/helpers.js +101 -0
- package/lib/commonjs/components/ChatKit/useChatKeyboard/helpers.js.map +1 -0
- package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js +147 -0
- package/lib/commonjs/components/ChatKit/useChatKeyboard/index.js.map +1 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +7 -36
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardStickyView/index.js +7 -5
- package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js +38 -14
- package/lib/commonjs/components/ScrollViewWithBottomPadding/index.js.map +1 -1
- package/lib/commonjs/components/index.js +7 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/ChatKit/TODO.md +20 -0
- package/lib/module/components/ChatKit/hooks.js +2 -0
- package/lib/module/components/ChatKit/hooks.js.map +1 -0
- package/lib/module/components/ChatKit/index.js +48 -0
- package/lib/module/components/ChatKit/index.js.map +1 -0
- package/lib/module/components/ChatKit/types.js +2 -0
- package/lib/module/components/ChatKit/types.js.map +1 -0
- package/lib/module/components/ChatKit/useChatKeyboard/helpers.js +92 -0
- package/lib/module/components/ChatKit/useChatKeyboard/helpers.js.map +1 -0
- package/lib/module/components/ChatKit/useChatKeyboard/index.js +141 -0
- package/lib/module/components/ChatKit/useChatKeyboard/index.js.map +1 -0
- package/lib/module/components/KeyboardAwareScrollView/index.js +7 -36
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardStickyView/index.js +7 -5
- package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
- package/lib/module/components/ScrollViewWithBottomPadding/index.js +38 -14
- package/lib/module/components/ScrollViewWithBottomPadding/index.js.map +1 -1
- package/lib/module/components/index.js +1 -0
- 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/typescript/components/ChatKit/hooks.d.ts +2 -0
- package/lib/typescript/components/ChatKit/index.d.ts +14 -0
- package/lib/typescript/components/ChatKit/types.d.ts +49 -0
- package/lib/typescript/components/ChatKit/useChatKeyboard/helpers.d.ts +57 -0
- package/lib/typescript/components/ChatKit/useChatKeyboard/index.d.ts +36 -0
- package/lib/typescript/components/ScrollViewWithBottomPadding/index.d.ts +6 -1
- package/lib/typescript/components/index.d.ts +2 -0
- package/lib/typescript/index.d.ts +2 -2
- package/package.json +10 -3
- package/src/components/ChatKit/TODO.md +20 -0
- package/src/components/ChatKit/hooks.ts +2 -0
- package/src/components/ChatKit/index.tsx +63 -0
- package/src/components/ChatKit/types.ts +50 -0
- package/src/components/ChatKit/useChatKeyboard/helpers.ts +118 -0
- package/src/components/ChatKit/useChatKeyboard/index.ts +228 -0
- package/src/components/KeyboardAwareScrollView/index.tsx +7 -43
- package/src/components/KeyboardStickyView/index.tsx +4 -5
- package/src/components/ScrollViewWithBottomPadding/index.tsx +66 -17
- package/src/components/index.ts +2 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
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 };
|
|
@@ -149,7 +149,6 @@ const KeyboardAwareScrollView = forwardRef<
|
|
|
149
149
|
const lastSelection =
|
|
150
150
|
useSharedValue<FocusedInputSelectionChangedEvent | null>(null);
|
|
151
151
|
const ghostViewSpace = useSharedValue(-1);
|
|
152
|
-
const pendingSelectionForFocus = useSharedValue(false);
|
|
153
152
|
|
|
154
153
|
const { height } = useWindowDimensions();
|
|
155
154
|
|
|
@@ -325,18 +324,7 @@ const KeyboardAwareScrollView = forwardRef<
|
|
|
325
324
|
lastSelection.value = e;
|
|
326
325
|
|
|
327
326
|
if (e.target !== lastTarget) {
|
|
328
|
-
|
|
329
|
-
// selection arrived after onStart - complete the deferred setup
|
|
330
|
-
pendingSelectionForFocus.value = false;
|
|
331
|
-
updateLayoutFromSelection();
|
|
332
|
-
|
|
333
|
-
// if keyboard was already visible (focus change, no onMove expected),
|
|
334
|
-
// perform the deferred scroll now
|
|
335
|
-
if (!keyboardWillAppear.value && keyboardHeight.value > 0) {
|
|
336
|
-
position.value += maybeScroll(keyboardHeight.value, true);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
327
|
+
// ignore this event, because "focus changed" event handled in `useSmoothKeyboardHandler`
|
|
340
328
|
return;
|
|
341
329
|
}
|
|
342
330
|
// caret in the end + end coordinates has been changed -> we moved to a new line
|
|
@@ -354,12 +342,7 @@ const KeyboardAwareScrollView = forwardRef<
|
|
|
354
342
|
|
|
355
343
|
onChangeTextHandler();
|
|
356
344
|
},
|
|
357
|
-
[
|
|
358
|
-
scrollFromCurrentPosition,
|
|
359
|
-
onChangeTextHandler,
|
|
360
|
-
updateLayoutFromSelection,
|
|
361
|
-
maybeScroll,
|
|
362
|
-
],
|
|
345
|
+
[scrollFromCurrentPosition, onChangeTextHandler],
|
|
363
346
|
);
|
|
364
347
|
|
|
365
348
|
useFocusedInputHandler(
|
|
@@ -392,7 +375,6 @@ const KeyboardAwareScrollView = forwardRef<
|
|
|
392
375
|
// on back transition need to interpolate as [0, keyboardHeight]
|
|
393
376
|
initialKeyboardSize.value = 0;
|
|
394
377
|
scrollPosition.value = scrollBeforeKeyboardMovement.value;
|
|
395
|
-
pendingSelectionForFocus.value = false;
|
|
396
378
|
}
|
|
397
379
|
|
|
398
380
|
if (
|
|
@@ -409,31 +391,17 @@ const KeyboardAwareScrollView = forwardRef<
|
|
|
409
391
|
// focus was changed
|
|
410
392
|
if (focusWasChanged) {
|
|
411
393
|
tag.value = e.target;
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
// selection arrived before onStart - use it to update layout
|
|
415
|
-
updateLayoutFromSelection();
|
|
416
|
-
pendingSelectionForFocus.value = false;
|
|
417
|
-
} else {
|
|
418
|
-
// selection hasn't arrived yet for the new target.
|
|
419
|
-
// use input layout as-is; will be refined when selection arrives.
|
|
420
|
-
if (input.value) {
|
|
421
|
-
layout.value = input.value;
|
|
422
|
-
}
|
|
423
|
-
pendingSelectionForFocus.value = true;
|
|
424
|
-
}
|
|
425
|
-
|
|
394
|
+
// save position of focused text input when keyboard starts to move
|
|
395
|
+
updateLayoutFromSelection();
|
|
426
396
|
// save current scroll position - when keyboard will hide we'll reuse
|
|
427
397
|
// this value to achieve smooth hide effect
|
|
428
398
|
scrollBeforeKeyboardMovement.value = position.value;
|
|
429
399
|
}
|
|
430
400
|
|
|
431
401
|
if (focusWasChanged && !keyboardWillAppear.value) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
position.value += maybeScroll(e.height, true);
|
|
436
|
-
}
|
|
402
|
+
// update position on scroll value, so `onEnd` handler
|
|
403
|
+
// will pick up correct values
|
|
404
|
+
position.value += maybeScroll(e.height, true);
|
|
437
405
|
}
|
|
438
406
|
|
|
439
407
|
ghostViewSpace.value =
|
|
@@ -467,10 +435,6 @@ const KeyboardAwareScrollView = forwardRef<
|
|
|
467
435
|
keyboardHeight.value = e.height;
|
|
468
436
|
scrollPosition.value = position.value;
|
|
469
437
|
|
|
470
|
-
if (e.height === 0) {
|
|
471
|
-
lastSelection.value = null;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
438
|
syncKeyboardFrame(e);
|
|
475
439
|
},
|
|
476
440
|
},
|
|
@@ -58,17 +58,16 @@ const KeyboardStickyView = forwardRef<
|
|
|
58
58
|
outputRange: [closed, opened],
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
const styles = useMemo(
|
|
62
|
-
|
|
61
|
+
const styles = useMemo(() => {
|
|
62
|
+
return [
|
|
63
63
|
{
|
|
64
64
|
transform: [
|
|
65
65
|
{ translateY: enabled ? Animated.add(height, offset) : closed },
|
|
66
66
|
],
|
|
67
67
|
},
|
|
68
68
|
style,
|
|
69
|
-
]
|
|
70
|
-
|
|
71
|
-
);
|
|
69
|
+
];
|
|
70
|
+
}, [closed, enabled, height, offset, style]);
|
|
72
71
|
|
|
73
72
|
return (
|
|
74
73
|
<Animated.View ref={ref} style={styles} {...props}>
|
|
@@ -6,11 +6,12 @@ import { ClippingScrollView } from "../../bindings";
|
|
|
6
6
|
|
|
7
7
|
import styles from "./styles";
|
|
8
8
|
|
|
9
|
-
import type { ScrollViewProps } from "react-native";
|
|
9
|
+
import type { ScrollViewProps, StyleProp, ViewStyle } from "react-native";
|
|
10
10
|
import type { SharedValue } from "react-native-reanimated";
|
|
11
11
|
|
|
12
|
+
const OS = Platform.OS;
|
|
12
13
|
const ReanimatedClippingScrollView =
|
|
13
|
-
|
|
14
|
+
OS === "android"
|
|
14
15
|
? Reanimated.createAnimatedComponent(ClippingScrollView)
|
|
15
16
|
: ClippingScrollView;
|
|
16
17
|
|
|
@@ -25,7 +26,12 @@ export type AnimatedScrollViewComponent = React.ForwardRefExoticComponent<
|
|
|
25
26
|
type ScrollViewWithBottomPaddingProps = {
|
|
26
27
|
ScrollViewComponent: AnimatedScrollViewComponent;
|
|
27
28
|
children?: React.ReactNode;
|
|
29
|
+
inverted?: boolean;
|
|
28
30
|
bottomPadding: SharedValue<number>;
|
|
31
|
+
/** Absolute Y content offset (iOS only, for ChatKit). */
|
|
32
|
+
contentOffsetY?: SharedValue<number>;
|
|
33
|
+
/** Style applied to the container wrapper (Android only, for ChatKit translateY). */
|
|
34
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
29
35
|
} & ScrollViewProps;
|
|
30
36
|
|
|
31
37
|
const ScrollViewWithBottomPadding = forwardRef<
|
|
@@ -33,35 +39,78 @@ const ScrollViewWithBottomPadding = forwardRef<
|
|
|
33
39
|
ScrollViewWithBottomPaddingProps
|
|
34
40
|
>(
|
|
35
41
|
(
|
|
36
|
-
{
|
|
42
|
+
{
|
|
43
|
+
ScrollViewComponent,
|
|
44
|
+
bottomPadding,
|
|
45
|
+
contentInset,
|
|
46
|
+
scrollIndicatorInsets,
|
|
47
|
+
inverted,
|
|
48
|
+
contentOffsetY,
|
|
49
|
+
containerStyle,
|
|
50
|
+
children,
|
|
51
|
+
style,
|
|
52
|
+
...rest
|
|
53
|
+
},
|
|
37
54
|
ref,
|
|
38
55
|
) => {
|
|
39
|
-
const animatedProps = useAnimatedProps(
|
|
40
|
-
|
|
56
|
+
const animatedProps = useAnimatedProps(() => {
|
|
57
|
+
const bottom = inverted
|
|
58
|
+
? 0
|
|
59
|
+
: bottomPadding.value + (contentInset?.bottom || 0);
|
|
60
|
+
const top = !inverted
|
|
61
|
+
? 0
|
|
62
|
+
: bottomPadding.value + (contentInset?.top || 0);
|
|
63
|
+
|
|
64
|
+
const result: Record<string, unknown> = {
|
|
41
65
|
// iOS prop
|
|
42
66
|
contentInset: {
|
|
43
|
-
bottom:
|
|
44
|
-
top:
|
|
67
|
+
bottom: bottom,
|
|
68
|
+
top: top,
|
|
45
69
|
right: contentInset?.right,
|
|
46
70
|
left: contentInset?.left,
|
|
47
71
|
},
|
|
72
|
+
scrollIndicatorInsets: {
|
|
73
|
+
bottom: bottom,
|
|
74
|
+
top: top,
|
|
75
|
+
right: scrollIndicatorInsets?.right,
|
|
76
|
+
left: scrollIndicatorInsets?.left,
|
|
77
|
+
},
|
|
48
78
|
// Android prop
|
|
49
79
|
contentInsetBottom: bottomPadding.value,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (contentOffsetY) {
|
|
83
|
+
result.contentOffset = { x: 0, y: contentOffsetY.value };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return result;
|
|
87
|
+
}, [
|
|
88
|
+
contentInset?.bottom,
|
|
89
|
+
contentInset?.top,
|
|
90
|
+
contentInset?.right,
|
|
91
|
+
contentInset?.left,
|
|
92
|
+
scrollIndicatorInsets?.bottom,
|
|
93
|
+
scrollIndicatorInsets?.top,
|
|
94
|
+
scrollIndicatorInsets?.right,
|
|
95
|
+
scrollIndicatorInsets?.left,
|
|
96
|
+
inverted,
|
|
97
|
+
contentOffsetY,
|
|
98
|
+
]);
|
|
58
99
|
|
|
59
100
|
return (
|
|
60
101
|
<ReanimatedClippingScrollView
|
|
61
102
|
animatedProps={animatedProps}
|
|
62
|
-
style={
|
|
103
|
+
style={[
|
|
104
|
+
styles.container,
|
|
105
|
+
OS === "android" ? containerStyle : undefined,
|
|
106
|
+
]}
|
|
63
107
|
>
|
|
64
|
-
<ScrollViewComponent
|
|
108
|
+
<ScrollViewComponent
|
|
109
|
+
ref={ref}
|
|
110
|
+
animatedProps={animatedProps}
|
|
111
|
+
style={style}
|
|
112
|
+
{...rest}
|
|
113
|
+
>
|
|
65
114
|
{children}
|
|
66
115
|
</ScrollViewComponent>
|
|
67
116
|
</ReanimatedClippingScrollView>
|
package/src/components/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export {
|
|
|
5
5
|
default as KeyboardToolbar,
|
|
6
6
|
DefaultKeyboardToolbarTheme,
|
|
7
7
|
} from "./KeyboardToolbar";
|
|
8
|
+
export { default as ChatKit } from "./ChatKit";
|
|
8
9
|
export type { KeyboardAvoidingViewProps } from "./KeyboardAvoidingView";
|
|
9
10
|
export type { KeyboardStickyViewProps } from "./KeyboardStickyView";
|
|
10
11
|
export type {
|
|
@@ -12,3 +13,4 @@ export type {
|
|
|
12
13
|
KeyboardAwareScrollViewRef,
|
|
13
14
|
} from "./KeyboardAwareScrollView";
|
|
14
15
|
export type { KeyboardToolbarProps } from "./KeyboardToolbar";
|
|
16
|
+
export type { ChatKitScrollViewProps } from "./ChatKit/types";
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./types";
|
|
|
8
8
|
export * from "./compat";
|
|
9
9
|
|
|
10
10
|
export {
|
|
11
|
+
ChatKit,
|
|
11
12
|
KeyboardAvoidingView,
|
|
12
13
|
KeyboardStickyView,
|
|
13
14
|
KeyboardAwareScrollView,
|
|
@@ -16,6 +17,7 @@ export {
|
|
|
16
17
|
DefaultKeyboardToolbarTheme,
|
|
17
18
|
} from "./components";
|
|
18
19
|
export type {
|
|
20
|
+
ChatKitScrollViewProps,
|
|
19
21
|
KeyboardAvoidingViewProps,
|
|
20
22
|
KeyboardStickyViewProps,
|
|
21
23
|
KeyboardAwareScrollViewProps,
|