fix(mobile): increase font sizes and other mobile-centric improvements (#1907)

This commit is contained in:
Mo
2022-11-01 11:41:40 -05:00
committed by GitHub
parent f54b017f53
commit 994f824757
72 changed files with 543 additions and 283 deletions

View File

@@ -1,24 +1,27 @@
import { isDev } from '@/Utils'
import { log, LoggingDomain } from './Logging'
export const ViewportHeightKey = '--viewport-height'
export const setViewportHeightWithFallback = () => {
const currentHeight = parseInt(document.documentElement.style.getPropertyValue(ViewportHeightKey))
const newValue = visualViewport && visualViewport.height > 0 ? visualViewport.height : window.innerHeight
if (isDev) {
// eslint-disable-next-line no-console
console.log(`currentHeight: ${currentHeight}, newValue: ${newValue}`)
}
if (currentHeight && newValue < currentHeight) {
return
}
if (!newValue) {
document.documentElement.style.setProperty(ViewportHeightKey, '100vh')
setCustomViewportHeight('100', 'vh')
return
}
document.documentElement.style.setProperty(ViewportHeightKey, `${newValue}px`)
setCustomViewportHeight(String(newValue), 'px')
}
/**
* @param forceTriggerResizeEvent On iPad at least, setProperty(ViewportHeightKey) does not trigger a resize event
*/
export const setCustomViewportHeight = (height: string, suffix: 'px' | 'vh', forceTriggerResizeEvent = false) => {
log(LoggingDomain.Viewport, `setCustomViewportHeight: ${height}`)
document.documentElement.style.setProperty(ViewportHeightKey, `${height}${suffix}`)
if (forceTriggerResizeEvent) {
window.dispatchEvent(new Event('resize'))
}
}