-
-
Save MartijnHols/e9f4f787efa9190885a708468f63c5bb to your computer and use it in GitHub Desktop.
| The latest version is available at https://martijnhols.nl/gists/how-to-get-document-height-ios-safari-osk |
| import { useEffect } from 'react' | |
| const useOnScreenKeyboardScrollFix = () => { | |
| useEffect(() => { | |
| const handleScroll = () => { | |
| window.scrollTo(0, 0) | |
| } | |
| window.addEventListener('scroll', handleScroll) | |
| return () => { | |
| window.removeEventListener('scroll', handleScroll) | |
| } | |
| }, []) | |
| } | |
| export default useOnScreenKeyboardScrollFix |
Little tricky. Sucks that mobile-PWA development is so harsh sometimes. But this solution works like a charm. Love it. Many thanks!
when i use useOnScreenKeyboardScrollFix, the scroll content in FullViewportContainer will stop scroll, so i can not scroll into view on focusin
how can i get keyboard height
Hi @MartijnHols, First of all, thank you so much for your work!!! I have the same issue on my app and I implemented your solution and it works but most of the time when the keyboard is open and the screen resizes + the scroll to top emitting, there is a glitch that the app slides from the bottom to the top... Here is an example, first focus has the glitch and the second don't:
Screen.Recording.2024-06-23.at.12.45.24.mov
same problem here. did you end up getting a fix?
It seems to work if I adjust the maxHeight instead of the height and it has a h-full class from tailwind ( which is just height:100% )
Aaaand it must be the direct children of the root it seems