-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using KeyboardAwareScrollView on BottomSheet #789
Comments
Hello @xotahal Sorry for being non-responsive on your PR - I wanted to prepare stable Regarding you problem - don't you think that default keyboard handling from Let's consider step by step how it works in your second video. 1⃣ Bottom sheet is collapsedWhen you focus One potential fix I'm thinking of is to disable 2⃣ Focus again
|
The original idea with memoization was basically needed to implement a "back-scroll on keyboard hide" functionality - i. e. when you close the keyboard you expect, that the input will be returned to the same position. When keyboard becomes hidden, then theoretically we should return "noFocusedInputEvent" event (however I'm not sure it's the case on Android, because on Android you can simple close the keyboard via "V" button in nav bar and focus will be still in your input). And the idea with memoization of field was to have a coordinates before all layout shifts, so that when keyboard becomes invisible, we return all elements to its initial position (and for that we need to know that initial position, so we save it). |
Or maybe there is a simple fix - always invalidate So the final fix consist from two parts:
What do you think? |
Aso you can reach out to me via discord (nickname is kiryl.ziusko) - I'm responding there much faster 👀 |
Describe the bug
There is a problem with calculating position of text input when used on bottom sheet component (@gorhom/bottom-sheet). Let me explain what's happening with these two videos.
When I fully open the bottom sheet then everything seems to be fine.
Screen.Recording.2025-01-30.at.3.51.02.PM.mov
When I make the bottom sheet smaller than keyboard it scrolls wrong. You can see when I press input 0, the bottom sheet itself extend to fully open position and that means the KeyboardAwareScrollView should do nothing, because eventually the 0 input is above the keyboard.
The same behaviour happening even after I hide keyboard and focus the same #0 input. Only after I change to 1 input it works fine and it also works fine if I focus 0 field after I focused 1 field.
Hope it makes sense.
Screen.Recording.2025-01-30.at.3.51.36.PM.mov
Code snippet
I am looking at the code and I think I know what the problem is. I am happy to fix it and prepare PR, but I would maybe appreciate some guidance so the PR meets expectations. I think there might be multiple problems with this kind of use case (including the PR I created already - #770 - I would maybe close the PR and solve it differently because if the view is not there is creates "hard" jump when hiding keyboard)
In this case, the
onFocusedInputLayoutChanged
is not called second time, because the focus input is the same. The problem is it still remembers the previous position of the input so it thinks it is behind the keyboard and it does the scrolling. Once I select #1 input and after 0 it gets the correct position on the screen.What I think should happen is to check the current position of text input in all those functions
maybeScroll
,onStart
,onMove
,onEnd
and based on that decide if we need to scroll. Because the absolute position of the text field is changing when keyboard is showing.Another option would be to listen for the position of the current focused text field if possible and then check the current position in
maybeScroll
.What do you think?
Repo for reproducing
I have this code setup where I use BottomSheet with BottomSheetTextInputs and this libraries' KeyboardAwareScrollView, which is just wrapped by
createBottomSheetScrollableComponent
.To Reproduce
Explained above
Expected behavior
Well I think it should just do nothing actually :) Because TextInput will be eventually above the keyboard.
Screenshots
Uploaded above.
Smartphone (please complete the following information):
Please let me know if any questions. I appreciate the help.
The text was updated successfully, but these errors were encountered: