fix: use dvh for bottom nav (#2241)

This commit is contained in:
Nolan Lawson 2022-11-24 15:24:29 -08:00 committed by GitHub
parent b50b9dc40b
commit fac42a91a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 3 deletions

View file

@ -34,13 +34,19 @@
<style id="theBottomNavStyle" media="only x"> <style id="theBottomNavStyle" media="only x">
:root { :root {
--nav-top: calc(100vh - var(--nav-total-height)); --nav-top: calc(100dvh - var(--nav-total-height));
--nav-bottom: 0px; --nav-bottom: initial;
--main-content-pad-top: 0px; --main-content-pad-top: 0px;
--main-content-pad-bottom: var(--main-content-pad-vertical); --main-content-pad-bottom: var(--main-content-pad-vertical);
--toast-gap-bottom: var(--nav-total-height); --toast-gap-bottom: var(--nav-total-height);
--fab-gap-top: 0px; --fab-gap-top: 0px;
} }
@supports not (height: 1dvh) {
/* In browsers that don't support dvh, use the large-small-dynamic-viewport-units-polyfill */
:root {
--nav-top: calc((100 * var(--1dvh)) - var(--nav-total-height));
}
}
</style> </style>
<style id="theGrayscaleStyle" media="only x"> <style id="theGrayscaleStyle" media="only x">

View file

@ -0,0 +1,7 @@
Copyright <YEAR> <COPYRIGHT HOLDER>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,24 @@
// via https://github.com/joppuyo/large-small-dynamic-viewport-units-polyfill/blob/93782ffff5d76f46b71591b859aac44f3cd591b2/src/index.js
// with some stuff removed that we don't need
import { throttleTimer } from '../../_utils/throttleTimer.js'
// Don't execute this resize listener more than the browser can paint
const rafAlignedResize = process.browser && throttleTimer(requestAnimationFrame)
function setVh () {
const dvh = window.innerHeight * 0.01
document.documentElement.style.setProperty('--1dvh', (dvh + 'px'))
}
if (process.browser) {
// We run the calculation as soon as possible (eg. the script is in document head)
setVh()
// We run the calculation again when DOM has loaded
document.addEventListener('DOMContentLoaded', setVh)
// We run the calculation when window is resized
window.addEventListener('resize', () => {
rafAlignedResize(setVh)
})
}

View file

@ -37,3 +37,7 @@ export const importIntlListFormat = async () => { // has to be imported serially
/* webpackChunkName: '$polyfill$-internationalization' */ '@formatjs/intl-listformat/locale-data/en.js' /* webpackChunkName: '$polyfill$-internationalization' */ '@formatjs/intl-listformat/locale-data/en.js'
) )
} }
export const importDynamicViewportUnitsPolyfill = () => import(
/* webpackChunkName: '$polyfill$-dynamic-viewport-units' */ '../../_thirdparty/large-small-dynamic-viewport-units-polyfill/dynamic-viewport-utils-polyfill.js'
)

View file

@ -1,4 +1,5 @@
import { import {
importDynamicViewportUnitsPolyfill,
importIntlListFormat, importIntlListFormat,
importIntlLocale, importIntlPluralRules, importIntlRelativeTimeFormat, importIntlLocale, importIntlPluralRules, importIntlRelativeTimeFormat,
importRequestIdleCallback importRequestIdleCallback
@ -25,7 +26,8 @@ export async function loadPolyfills () {
mark('loadPolyfills') mark('loadPolyfills')
await Promise.all([ await Promise.all([
typeof requestIdleCallback !== 'function' && importRequestIdleCallback(), typeof requestIdleCallback !== 'function' && importRequestIdleCallback(),
loadIntlPolyfillsIfNecessary() loadIntlPolyfillsIfNecessary(),
!CSS.supports('height: 1dvh') && importDynamicViewportUnitsPolyfill()
]) ])
stop('loadPolyfills') stop('loadPolyfills')
} }