I build a SPA that should always take 100% of screen height with the target browser group - iOS(mobile) Safari. height:100vh
doesn't work properly on iOS Safari -
CSS3 100vh not constant in mobile browser
https://css-tricks.com/css-fix-for-100vh-in-mobile-webkit/
A suggested solution on some resources to use -webkit-fill-available
didn't help.
Therefore, I decided to control the height of the app container with JS:
const [height, setHeight] = useState(window.innerHeight);
const handleWindowSizeChange = () => {
setHeight(window.innerHeight);
};
useEffect(() => {
window.addEventListener("resize", handleWindowSizeChange);
return () => window.removeEventListener("resize", handleWindowSizeChange);
}, []);
return (
<div className="App" style={{ height: height }}>
<header className="top"></header>
<div className="main"></div>
<footer className="bottom"><button>Click</button></footer>
</div>
My solution works until we rotate the screen from portrait orientation to landscape, and back to portrait. After these rotations, we have a gap at the bottom of the screen view, right below the app footer. The same behaviour can be noticed if we open a demo - https://react-div-100vh.vercel.app/ for a package which is supposed to solve the issue, and make the same screen rotations.
Browser: Safari 14.6 iOS/iPhone 7