Skip to content

Commit f097bc5

Browse files
committed
fix: "never" - when we are at the end (beginning for inverted case) and close a keyboard we need to scroll along with keyboard movement. Otherwise we have a "jump" animation. (Android)
1 parent 20d8dee commit f097bc5

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

  • src/components/KeyboardChatScrollView/useChatKeyboard

src/components/KeyboardChatScrollView/useChatKeyboard/index.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ function useChatKeyboard(
192192
inverted,
193193
);
194194

195+
// "never" at end: scroll along when keyboard closes to avoid jump
196+
if (
197+
keyboardLiftBehavior === "never" &&
198+
wasAtEnd &&
199+
effective < padding.value
200+
) {
201+
padding.value = effective;
202+
scrollTo(scrollViewRef, 0, 0, false);
203+
204+
return;
205+
}
206+
195207
if (!shouldShiftContent(keyboardLiftBehavior, wasAtEnd)) {
196208
return;
197209
}
@@ -216,6 +228,31 @@ function useChatKeyboard(
216228

217229
scrollTo(scrollViewRef, 0, target, false);
218230
} else {
231+
const effective = getEffectiveHeight(e.height);
232+
233+
// "never" at end: scroll along when keyboard closes to avoid jump
234+
if (keyboardLiftBehavior === "never" && effective < padding.value) {
235+
const wasAtEnd = isScrollAtEnd(
236+
offsetBeforeScroll.value + padding.value,
237+
layout.value.height,
238+
size.value.height,
239+
false,
240+
);
241+
242+
if (wasAtEnd) {
243+
const target = clampedScrollTarget(
244+
offsetBeforeScroll.value,
245+
effective,
246+
size.value.height,
247+
layout.value.height,
248+
);
249+
250+
scrollTo(scrollViewRef, 0, target, false);
251+
}
252+
253+
return;
254+
}
255+
219256
if (!shouldShiftContent(keyboardLiftBehavior, true)) {
220257
return;
221258
}
@@ -225,8 +262,6 @@ function useChatKeyboard(
225262
return;
226263
}
227264

228-
const effective = getEffectiveHeight(e.height);
229-
230265
if (
231266
keyboardLiftBehavior === "persistent" &&
232267
effective < scroll.value - offsetBeforeScroll.value

0 commit comments

Comments
 (0)