fix: viewport height on mobile Chrome & Safari (#1376)

This commit is contained in:
Aman Harwara
2022-08-08 14:32:16 +05:30
committed by GitHub
parent d533fb78e0
commit 887402f75f
2 changed files with 14 additions and 0 deletions

View File

@@ -39,6 +39,10 @@ const getKey = () => {
const RootId = 'app-group-root' const RootId = 'app-group-root'
const setViewportHeight = () => {
document.documentElement.style.setProperty('--viewport-height', `${window.innerHeight}px`)
}
const startApplication: StartApplication = async function startApplication( const startApplication: StartApplication = async function startApplication(
defaultSyncServerHost: string, defaultSyncServerHost: string,
device: WebOrDesktopDevice, device: WebOrDesktopDevice,
@@ -54,6 +58,8 @@ const startApplication: StartApplication = async function startApplication(
const rootElement = document.getElementById(RootId) as HTMLElement const rootElement = document.getElementById(RootId) as HTMLElement
root.unmount() root.unmount()
rootElement.remove() rootElement.remove()
window.removeEventListener('resize', setViewportHeight)
window.removeEventListener('orientationchange', setViewportHeight)
renderApp() renderApp()
} }
@@ -63,6 +69,10 @@ const startApplication: StartApplication = async function startApplication(
const appendedRootNode = document.body.appendChild(rootElement) const appendedRootNode = document.body.appendChild(rootElement)
root = createRoot(appendedRootNode) root = createRoot(appendedRootNode)
setViewportHeight()
window.addEventListener('resize', setViewportHeight)
window.addEventListener('orientationchange', setViewportHeight)
root.render( root.render(
<ApplicationGroupView <ApplicationGroupView
key={getKey()} key={getKey()}

View File

@@ -108,8 +108,12 @@ p {
} }
.main-ui-view { .main-ui-view {
// Fallbacks
min-height: 100vh; min-height: 100vh;
height: 100vh; height: 100vh;
// Mobile-corrected viewport height
min-height: var(--viewport-height);
height: var(--viewport-height);
position: relative; position: relative;
overflow: auto; overflow: auto;
background-color: var(--editor-header-bar-background-color); background-color: var(--editor-header-bar-background-color);