Created
September 13, 2022 13:55
-
-
Save niraj-khatiwada/b5f5dab6f9ec7e6d7d95fb4beb996294 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'; | |
const useIsKeyboardVisible = () => { | |
const [isVisible, setIsVisible] = React.useState(false); | |
React.useEffect(() => { | |
const didShowListener = Keyboard.addListener('keyboardDidShow', () => { | |
setIsVisible(true); | |
}); | |
const didHideListener = Keyboard.addListener('keyboardDidHide', () => { | |
setIsVisible(false); | |
}); | |
return () => { | |
didShowListener?.remove(); | |
didHideListener?.remove(); | |
}; | |
}, []); | |
return isVisible; | |
}; | |
export default useIsKeyboardVisible; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment