Skip to content

Commit ed9e7ef

Browse files
committed
fix: don't handle input switch twice
1 parent 26aaf69 commit ed9e7ef

File tree

1 file changed

+20
-0
lines changed
  • src/components/KeyboardAwareScrollView

1 file changed

+20
-0
lines changed

src/components/KeyboardAwareScrollView/index.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ const KeyboardAwareScrollView = forwardRef<
112112
const scrollBeforeKeyboardMovement = useSharedValue(0);
113113
const { input } = useReanimatedFocusedInput();
114114
const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);
115+
const lastSelection =
116+
useSharedValue<FocusedInputSelectionChangedEvent | null>(null);
115117

116118
const { height } = useWindowDimensions();
117119

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

159+
console.log({ absoluteY, inputHeight, point, visibleRect });
160+
157161
if (visibleRect - point <= bottomOffset) {
158162
const relativeScrollTo =
159163
keyboardHeight.value - (height - point) + bottomOffset;
164+
165+
console.log({ relativeScrollTo });
160166
const interpolatedScrollTo = interpolate(
161167
e,
162168
[initialKeyboardSize.value, keyboardHeight.value],
@@ -171,6 +177,11 @@ const KeyboardAwareScrollView = forwardRef<
171177
const targetScrollY =
172178
Math.max(interpolatedScrollTo, 0) + scrollPosition.value;
173179

180+
console.log({
181+
targetScrollY,
182+
scrollPosition: scrollPosition.value,
183+
interpolatedScrollTo,
184+
});
174185
scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);
175186

176187
return interpolatedScrollTo;
@@ -260,6 +271,15 @@ const KeyboardAwareScrollView = forwardRef<
260271
(e: FocusedInputSelectionChangedEvent) => {
261272
"worklet";
262273

274+
const lastTarget = lastSelection.value?.target;
275+
276+
lastSelection.value = e;
277+
278+
if (e.target !== lastTarget) {
279+
// ignore this event, because "focus changed" event handled in `useSmoothKeyboardHandler`
280+
return;
281+
}
282+
263283
console.log(e);
264284

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

0 commit comments

Comments
 (0)