Last active
September 12, 2025 14:28
-
-
Save MartijnHols/e9f4f787efa9190885a708468f63c5bb to your computer and use it in GitHub Desktop.
React hooks for getting the document height that updates when the On Screen Keyboard/Virtual Keyboard toggles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| The latest version is available at https://martijnhols.nl/gists/how-to-get-document-height-ios-safari-osk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
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?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how can i get keyboard height