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.38k stars 55 forks source link

feat: scroll to at least the first snapToOffset value if any #452

Closed kgni closed 1 month ago

kgni commented 1 month ago

📜 Description

💡 Motivation and Context

When dealing with Scrollviews that are snapping to a specific point, if the keyboard is creating a scroll, we in some cases want the scrollview to scroll to at least the first snapToOffsets

It fixes layouts being stuck between 2 states, please see the following issue for more info: https://github.com/kirillzyusko/react-native-keyboard-controller/issues/450

Closes https://github.com/kirillzyusko/react-native-keyboard-controller/issues/450

📢 Changelog

JS

🤔 How Has This Been Tested?

Tested really briefly, going to point my own project to this PR for further testing

📸 Screenshots (if appropriate):

To be added

📝 Checklist

kgni commented 1 month ago

https://github.com/kirillzyusko/react-native-keyboard-controller/assets/84397151/699d2ed7-1318-4b86-a261-ea1c613dcb71

kgni commented 1 month ago

The only issue with this implementation currently, is that we have to ensure that the body (from the 1. Room address & name title -> Next button sticky footer), has a minHeight that is tall enough so that the keyboard can actually scroll to the snapToOffsets.

A side effect of that, is that the body for this layout is always scrollable to at least the snapToOffset, which is probably not desired. Instead the layout should not be scrollable whenever there is no need to.

I tried to create an implementation where the body would initially not be scrollable, by calculating the different element heights on initial Layout:

screenHeight - headerHeight - footerHeight = bodyHeight

My thought then was, that when the keyboard opens we would add to the bodyHeight to make it scrollable - however I ran into an issue where the keyboard would not trigger the scroll, because the addition to the bodyHeight is done after the keyboard triggers (I used the useKeyboardHandler, to add the height of the keyboard to the minBodyHeight).

Do you have an idea how I could add to the bodyHeight and then trigger the scroll? @kirillzyusko

Also if I'm not making sense, please let me know. I can create a loom explaining it more

kirillzyusko commented 1 month ago

I can create a loom explaining it more

Well, that would be good - because you are the only one person who has an access to the source code and for me it's slightly difficult to understand a references without an actual reproduction demo. So if you can create code sample and post it here - that would be amazing!

kgni commented 1 month ago

So if you can create code sample and post it here - that would be amazing!

Sure thing!

I will probably create one by the end of the week

kirillzyusko commented 1 month ago

Size diff job is failing - it's expected, because of GitHub security preferences (it can not send a comment to PR from external contributors - I haven't figured out how to fix it yet). So ignore it 🙃

Size diff from this PR is 2kb.