fix: add fallback for viewport height on mobile (#1766)
This commit is contained in:
@@ -41,16 +41,17 @@ const getKey = () => {
|
|||||||
return keyCount++
|
return keyCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
const setViewportHeight = () => {
|
export const setViewportHeightWithFallback = () => {
|
||||||
const currentValue = parseInt(document.documentElement.style.getPropertyValue('--viewport-height'))
|
const currentValue = parseInt(document.documentElement.style.getPropertyValue('--viewport-height'))
|
||||||
const newValue = visualViewport && visualViewport.height > 0 ? visualViewport.height : window.innerHeight
|
const newValue = visualViewport && visualViewport.height > 0 ? visualViewport.height : window.innerHeight
|
||||||
|
const supportsSVHUnit = CSS.supports('height', '1svh')
|
||||||
|
|
||||||
if (currentValue && !newValue) {
|
if (currentValue && !newValue) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentValue && !newValue) {
|
if (!currentValue && !newValue) {
|
||||||
document.documentElement.style.setProperty('--viewport-height', '100vh')
|
document.documentElement.style.setProperty('--viewport-height', supportsSVHUnit ? '100svh' : '100vh')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,9 +80,9 @@ const startApplication: StartApplication = async function startApplication(
|
|||||||
|
|
||||||
const onDestroy = () => {
|
const onDestroy = () => {
|
||||||
if (device.environment === Environment.Desktop) {
|
if (device.environment === Environment.Desktop) {
|
||||||
window.removeEventListener('resize', setViewportHeight)
|
window.removeEventListener('resize', setViewportHeightWithFallback)
|
||||||
}
|
}
|
||||||
window.removeEventListener('orientationchange', setViewportHeight)
|
window.removeEventListener('orientationchange', setViewportHeightWithFallback)
|
||||||
const rootElement = document.getElementById(ElementIds.RootId) as HTMLElement
|
const rootElement = document.getElementById(ElementIds.RootId) as HTMLElement
|
||||||
root.unmount()
|
root.unmount()
|
||||||
rootElement.remove()
|
rootElement.remove()
|
||||||
@@ -96,10 +97,10 @@ const startApplication: StartApplication = async function startApplication(
|
|||||||
|
|
||||||
disableIosTextFieldZoom()
|
disableIosTextFieldZoom()
|
||||||
|
|
||||||
setViewportHeight()
|
setViewportHeightWithFallback()
|
||||||
window.addEventListener('orientationchange', setViewportHeight)
|
window.addEventListener('orientationchange', setViewportHeightWithFallback)
|
||||||
if (device.environment === Environment.Desktop) {
|
if (device.environment === Environment.Desktop) {
|
||||||
window.addEventListener('resize', setViewportHeight)
|
window.addEventListener('resize', setViewportHeightWithFallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultMonospaceFont(device.platform)
|
setDefaultMonospaceFont(device.platform)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { ArchiveManager, AutolockService, IOService, WebAlertService, ThemeManag
|
|||||||
import { MobileWebReceiver } from './MobileWebReceiver'
|
import { MobileWebReceiver } from './MobileWebReceiver'
|
||||||
import { AndroidBackHandler } from '@/NativeMobileWeb/AndroidBackHandler'
|
import { AndroidBackHandler } from '@/NativeMobileWeb/AndroidBackHandler'
|
||||||
import { PrefDefaults } from '@/Constants/PrefDefaults'
|
import { PrefDefaults } from '@/Constants/PrefDefaults'
|
||||||
|
import { setViewportHeightWithFallback } from '@/App'
|
||||||
|
|
||||||
type WebServices = {
|
type WebServices = {
|
||||||
viewControllerManager: ViewControllerManager
|
viewControllerManager: ViewControllerManager
|
||||||
@@ -233,8 +234,9 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
|||||||
await this.lockApplicationAfterMobileEventIfApplicable()
|
await this.lockApplicationAfterMobileEventIfApplicable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
async handleMobileGainingFocusEvent(): Promise<void> {
|
||||||
async handleMobileGainingFocusEvent(): Promise<void> {}
|
setViewportHeightWithFallback()
|
||||||
|
}
|
||||||
|
|
||||||
async handleMobileLosingFocusEvent(): Promise<void> {
|
async handleMobileLosingFocusEvent(): Promise<void> {
|
||||||
if (this.protections.getMobileScreenshotPrivacyEnabled()) {
|
if (this.protections.getMobileScreenshotPrivacyEnabled()) {
|
||||||
@@ -248,6 +250,8 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
|||||||
if (this.protections.getMobileScreenshotPrivacyEnabled()) {
|
if (this.protections.getMobileScreenshotPrivacyEnabled()) {
|
||||||
this.mobileDevice().hideMobileInterfaceFromScreenshots()
|
this.mobileDevice().hideMobileInterfaceFromScreenshots()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setViewportHeightWithFallback()
|
||||||
}
|
}
|
||||||
|
|
||||||
private async lockApplicationAfterMobileEventIfApplicable(): Promise<void> {
|
private async lockApplicationAfterMobileEventIfApplicable(): Promise<void> {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
@media screen and (max-width: 768px) {
|
@media screen and (max-width: 768px) {
|
||||||
--sn-stylekit-font-size-editor: 1rem;
|
--sn-stylekit-font-size-editor: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--viewport-height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
html {
|
html {
|
||||||
|
|||||||
Reference in New Issue
Block a user