export const monitorSoftKeyboard = (callback: any) => {
const originalHeight = document.documentElement.clientHeight || document.body.clientHeight;
window.addEventListener('resize', () => {
const resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
if (resizeHeight - 0 < originalHeight - 0) {
callback(true);
} else {
callback(false);
}
});
window.addEventListener('focusin', () => {
callback(true);
})
window.addEventListener('focusout', () => {
callback(false);
})
};
import { monitorSoftKeyboard } from "~/utils/monitorSoftKeyboard";
const [hideBottom, setHideBottom] = useState<boolean>(false)
useEffect(() => {
monitorSoftKeyboard((isUp: any) => {
if (isUp) {
setHideBottom(true);
} else {
setHideBottom(false);
}
});
}, []);