mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-27 21:18:30 -05:00
Bottom nav hiding on keyboard show, use the existing solution
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import * as React from "react";
|
||||
import { keyboardIsOpen } from "~/utils/visual-viewport";
|
||||
|
||||
const HEIGHT_PROPERTY = "--visual-viewport-height";
|
||||
const OFFSET_TOP_PROPERTY = "--visual-viewport-offset-top";
|
||||
const KEYBOARD_OPEN_ATTRIBUTE = "data-keyboard-open";
|
||||
|
||||
// Syncs the ACTUAL visual viewport to two CSS variables so elements can respect the space taken by the mobile keyboard
|
||||
// Syncs the ACTUAL visual viewport to two CSS variables (and whether the mobile keyboard is open to an attribute on <html>)
|
||||
// so elements can respect the space taken by the mobile keyboard
|
||||
// (not written on mount: until the viewport changes the CSS fallbacks match, and every write restyles the whole document)
|
||||
export function useVisualViewport() {
|
||||
React.useEffect(() => {
|
||||
@@ -23,6 +26,10 @@ export function useVisualViewport() {
|
||||
const style = document.documentElement.style;
|
||||
style.setProperty(HEIGHT_PROPERTY, `${height}px`);
|
||||
style.setProperty(OFFSET_TOP_PROPERTY, `${offsetTop}px`);
|
||||
document.documentElement.toggleAttribute(
|
||||
KEYBOARD_OPEN_ATTRIBUTE,
|
||||
keyboardIsOpen(),
|
||||
);
|
||||
};
|
||||
|
||||
viewport.addEventListener("resize", update);
|
||||
@@ -33,6 +40,7 @@ export function useVisualViewport() {
|
||||
viewport.removeEventListener("scroll", update);
|
||||
document.documentElement.style.removeProperty(HEIGHT_PROPERTY);
|
||||
document.documentElement.style.removeProperty(OFFSET_TOP_PROPERTY);
|
||||
document.documentElement.removeAttribute(KEYBOARD_OPEN_ATTRIBUTE);
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
|
||||
@@ -670,27 +670,10 @@
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
/* iOS can't pin the tab bar on top of the virtual keyboard, so it gets out of the way while typing */
|
||||
@media (pointer: coarse) {
|
||||
body:has(
|
||||
:is(
|
||||
input:is(
|
||||
:not([type]),
|
||||
[type="text"],
|
||||
[type="search"],
|
||||
[type="email"],
|
||||
[type="url"],
|
||||
[type="tel"],
|
||||
[type="password"],
|
||||
[type="number"]
|
||||
),
|
||||
textarea,
|
||||
[contenteditable]:not([contenteditable="false"])
|
||||
):not([readonly], [inputmode="none"]):focus
|
||||
) {
|
||||
--mobile-nav-height: 0px;
|
||||
--mobile-tab-bar-display: none;
|
||||
}
|
||||
/* iOS can't pin the tab bar on top of the virtual keyboard, so it gets out of the way while the keyboard is open */
|
||||
html[data-keyboard-open] body {
|
||||
--mobile-nav-height: 0px;
|
||||
--mobile-tab-bar-display: none;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 599px) {
|
||||
|
||||
@@ -44,5 +44,7 @@ export function keyboardIsOpen() {
|
||||
const viewport = window.visualViewport;
|
||||
if (!viewport) return false;
|
||||
|
||||
return window.innerHeight - viewport.height > KEYBOARD_MIN_HEIGHT;
|
||||
return (
|
||||
window.innerHeight - viewport.height * viewport.scale > KEYBOARD_MIN_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user