Created
September 13, 2022 13:56
-
-
Save niraj-khatiwada/c2c4371ec038a6efb3245e487e20da79 to your computer and use it in GitHub Desktop.
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 React from 'react'; | |
import {Keyboard} from 'react-native'; | |
function useKeyboardHeight() { | |
const [keyboardHeight, setKeyboardHeight] = React.useState(0); | |
function onKeyboardDidShow(e) { | |
setKeyboardHeight(e.endCoordinates.height); | |
} | |
function onKeyboardDidHide() { | |
setKeyboardHeight(0); | |
} | |
React.useEffect(() => { | |
Keyboard.addListener('keyboardDidShow', onKeyboardDidShow); | |
Keyboard.addListener('keyboardDidHide', onKeyboardDidHide); | |
return () => { | |
Keyboard.removeAllListeners('keyboardDidShow'); | |
Keyboard.removeAllListeners('keyboardDidHide'); | |
}; | |
}, []); | |
return [keyboardHeight]; | |
} | |
export default useKeyboardHeight; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment