30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
|
import * as React from 'react';
|
||
|
import { Keyboard, Platform } from 'react-native';
|
||
|
export default function useIsKeyboardShown() {
|
||
|
const [isKeyboardShown, setIsKeyboardShown] = React.useState(false);
|
||
|
React.useEffect(() => {
|
||
|
const handleKeyboardShow = () => setIsKeyboardShown(true);
|
||
|
|
||
|
const handleKeyboardHide = () => setIsKeyboardShown(false);
|
||
|
|
||
|
if (Platform.OS === 'ios') {
|
||
|
Keyboard.addListener('keyboardWillShow', handleKeyboardShow);
|
||
|
Keyboard.addListener('keyboardWillHide', handleKeyboardHide);
|
||
|
} else {
|
||
|
Keyboard.addListener('keyboardDidShow', handleKeyboardShow);
|
||
|
Keyboard.addListener('keyboardDidHide', handleKeyboardHide);
|
||
|
}
|
||
|
|
||
|
return () => {
|
||
|
if (Platform.OS === 'ios') {
|
||
|
Keyboard.removeListener('keyboardWillShow', handleKeyboardShow);
|
||
|
Keyboard.removeListener('keyboardWillHide', handleKeyboardHide);
|
||
|
} else {
|
||
|
Keyboard.removeListener('keyboardDidShow', handleKeyboardShow);
|
||
|
Keyboard.removeListener('keyboardDidHide', handleKeyboardHide);
|
||
|
}
|
||
|
};
|
||
|
}, []);
|
||
|
return isKeyboardShown;
|
||
|
}
|
||
|
//# sourceMappingURL=useIsKeyboardShown.js.map
|