import React, { useEffect, useState } from 'react'; import './App.css'; import { ContextWindowHeight } from './components/contextWindowHeight'; import { MainScreen } from './components/mainScreen/mainScreen'; function App() { // const [windowHeight, setWindowHeight] = useState(window.screen.availHeight); - не робит на iphone const [windowHeight, setWindowHeight] = useState(window.visualViewport.height); const [currentOrientaton, setCurrentOrientaton] = useState(window.orientation); window.visualViewport.onresize = (e) => { //@ts-ignore setWindowHeight(e.currentTarget.height); } // !!! работает на свойстве помеченном как deprecate - на айфоне иначе хз как window.onorientationchange = e => { //@ts-ignore let angle = e.target.orientation; if(currentOrientaton !== angle) { setCurrentOrientaton(angle); } } useEffect(() => { if(!navigator.userAgent.includes('iPhone')) { return; } if(currentOrientaton === 90) { document.querySelector('body').style['paddingLeft'] = 'env(safe-area-inset-left)' } else if(currentOrientaton === -90) { document.querySelector('body').style['paddingLeft'] = '0' } }, [currentOrientaton]); return (
); } export default App;