Skip to content

Commit

Permalink
fix: don't handle input switch twice
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Jan 3, 2025
1 parent 9cbeb66 commit 5e6c79a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/KeyboardAwareScrollView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const KeyboardAwareScrollView = forwardRef<
const scrollBeforeKeyboardMovement = useSharedValue(0);
const { input } = useReanimatedFocusedInput();
const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);
const lastSelection =
useSharedValue<FocusedInputSelectionChangedEvent | null>(null);

const { height } = useWindowDimensions();

Expand Down Expand Up @@ -154,9 +156,13 @@ const KeyboardAwareScrollView = forwardRef<
const inputHeight = layout.value?.layout.height || 0;
const point = absoluteY + inputHeight;

console.log({ absoluteY, inputHeight, point, visibleRect });

if (visibleRect - point <= bottomOffset) {
const relativeScrollTo =
keyboardHeight.value - (height - point) + bottomOffset;

console.log({ relativeScrollTo });
const interpolatedScrollTo = interpolate(
e,
[initialKeyboardSize.value, keyboardHeight.value],
Expand All @@ -171,6 +177,11 @@ const KeyboardAwareScrollView = forwardRef<
const targetScrollY =
Math.max(interpolatedScrollTo, 0) + scrollPosition.value;

console.log({
targetScrollY,
scrollPosition: scrollPosition.value,
interpolatedScrollTo,
});
scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);

return interpolatedScrollTo;
Expand Down Expand Up @@ -260,6 +271,15 @@ const KeyboardAwareScrollView = forwardRef<
(e: FocusedInputSelectionChangedEvent) => {
"worklet";

const lastTarget = lastSelection.value?.target;

lastSelection.value = e;

if (e.target !== lastTarget) {
// ignore this event, because "focus changed" event handled in `useSmoothKeyboardHandler`
return;
}

console.log(e);

if (e.selection.start.position !== e.selection.end.position) {
Expand Down

0 comments on commit 5e6c79a

Please sign in to comment.