kirillzyusko / react-native-keyboard-controller

Keyboard manager which works in identical way on both iOS and Android
https://kirillzyusko.github.io/react-native-keyboard-controller/
MIT License
1.59k stars 64 forks source link

Deleting an entire line in a long text inside an input makes scroll to the top on iOS #512

Open ticketapp opened 2 months ago

ticketapp commented 2 months ago

Describe the bug When I delete an entire line of a long text it makes the scroll view scroll to the top. It happend on Android on 1.11.6 as well but has been fixed between 1.11.6 and the current version (1.12.6)

Code snippet <KeyboardAwareScrollView> <Input.Area autoFocus scrollEnabled={false} value={editText} minHeight={55} onChangeText={setEditText} /> </KeyboardAwareScrollView>

Expected behavior The view shouldn't scroll if the line is not hidden

Screenshots https://github.com/user-attachments/assets/fcf71eba-a64b-46ac-bfc8-bb1db930b522

Smartphone (please complete the following information):

kirillzyusko commented 2 months ago

@ticketapp do you have a big single TextInput (multiline, but with disabled scroll) on the page?

Does it makes sense to use the KeyboardAwareScrollView or maybe it would be better to use KeyboardAvoidingView in this case? ๐Ÿค”

ticketapp commented 1 month ago

@kirillzyusko yes I have a big single TextInput (multiline with disabled scoll) on this page, but I have an other page with other elements of undetermined height where I need a KeyboardAwareScrollView

kirillzyusko commented 1 month ago

@ticketapp in your case the problem happens, because KeyboardAwareScrollView detects text changes inside inputs and tries to assure, that input is located within visible area and is not obscured by header or keyboard:

https://github.com/kirillzyusko/react-native-keyboard-controller/blob/dce5a5741d701789fb97d852439b83f9ab1c2d7d/src/components/KeyboardAwareScrollView/index.tsx#L244

Since you have a big input which is simultaneously obscured by keyboard and header - whenever you modify the text it will scroll down.

A straightforward approach would be to add a new property to KeyboardAwareScrollView and allow to run this handler (onChangeText) conditionally.

A more sophisticated approach would be to track cursor position (onSelectionChange from useFocusedInputHandler) and assure it's always in visible area but it would require more code changes๐Ÿ˜…

I think temporarily you can patch-package this library and comment out onChangeText handler - and in a meantime I'll try to invent a solution that will cover all the cases ๐Ÿ‘

ticketapp commented 1 month ago

Thank you very much for your response

youssdevx commented 1 month ago

Many thanks @kirillzyusko ๐Ÿ™๐Ÿฝ