1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/app-mobile/utils/hooks/useKeyboardVisible.ts

28 lines
774 B
TypeScript

import { useEffect, useMemo, useState } from 'react';
import { Keyboard } from 'react-native';
const useKeyboardVisible = () => {
const [keyboardVisible, setKeyboardVisible] = useState(false);
const [hasSoftwareKeyboard, setHasSoftwareKeyboard] = useState(false);
useEffect(() => {
const showListener = Keyboard.addListener('keyboardDidShow', () => {
setKeyboardVisible(true);
setHasSoftwareKeyboard(true);
});
const hideListener = Keyboard.addListener('keyboardDidHide', () => {
setKeyboardVisible(false);
});
return (() => {
showListener.remove();
hideListener.remove();
});
});
return useMemo(() => {
return { keyboardVisible, hasSoftwareKeyboard };
}, [keyboardVisible, hasSoftwareKeyboard]);
};
export default useKeyboardVisible;