Skip to content

Commit 8783c80

Browse files
committed
fix: rewrite onTextChanged to onSelectionChanged event handler in KeyboardAwareScrollView
1 parent 6eb74d2 commit 8783c80

10 files changed

+22
-19
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

src/components/KeyboardAwareScrollView/index.tsx

+22-19
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ const KeyboardAwareScrollView = forwardRef<
192192
);
193193

194194
const scrollFromCurrentPosition = useCallback(
195-
(customHeight?: number) => {
195+
(customHeight: number) => {
196196
"worklet";
197197

198198
const prevScrollPosition = scrollPosition.value;
@@ -207,7 +207,7 @@ const KeyboardAwareScrollView = forwardRef<
207207
...input.value,
208208
layout: {
209209
...input.value.layout,
210-
height: customHeight ?? input.value.layout.height,
210+
height: customHeight ?? input.value.layout.height, // TODO: math.min? When we have multiline input with limited amount of lines, then custom height can be very big?
211211
},
212212
};
213213
scrollPosition.value = position.value;
@@ -217,39 +217,42 @@ const KeyboardAwareScrollView = forwardRef<
217217
},
218218
[maybeScroll],
219219
);
220-
const onChangeText = useCallback(() => {
221-
"worklet";
220+
const onChangeText = useCallback(
221+
(customHeight: number) => {
222+
"worklet";
222223

223-
// if typing a text caused layout shift, then we need to ignore this handler
224-
// because this event will be handled in `useAnimatedReaction` below
225-
if (layout.value?.layout.height !== input.value?.layout.height) {
226-
return;
227-
}
224+
// if typing a text caused layout shift, then we need to ignore this handler
225+
// because this event will be handled in `useAnimatedReaction` below
226+
if (layout.value?.layout.height !== input.value?.layout.height) {
227+
return;
228+
}
228229

229-
scrollFromCurrentPosition();
230-
}, [scrollFromCurrentPosition]);
230+
scrollFromCurrentPosition(customHeight);
231+
},
232+
[scrollFromCurrentPosition],
233+
);
234+
const onChangeTextHandler = useMemo(
235+
() => debounce(onChangeText, 200),
236+
[onChangeText],
237+
);
231238
const onSelectionChange = useCallback(
232239
(e: FocusedInputSelectionChangedEvent) => {
233240
"worklet";
234241

235242
if (e.selection.start.position !== e.selection.end.position) {
236243
scrollFromCurrentPosition(e.selection.end.y);
237244
}
238-
},
239-
[scrollFromCurrentPosition],
240-
);
241245

242-
const onChangeTextHandler = useMemo(
243-
() => debounce(onChangeText, 200),
244-
[onChangeText],
246+
onChangeTextHandler(e.selection.end.y);
247+
},
248+
[scrollFromCurrentPosition, onChangeTextHandler],
245249
);
246250

247251
useFocusedInputHandler(
248252
{
249-
onChangeText: onChangeTextHandler,
250253
onSelectionChange: onSelectionChange,
251254
},
252-
[onChangeTextHandler, onSelectionChange],
255+
[onSelectionChange],
253256
);
254257

255258
useSmoothKeyboardHandler(

0 commit comments

Comments
 (0)