提交 445bca93 编写于 作者: Q qiang

fix: h5 --window-top --window-bottom

上级 ae7b600d
...@@ -239,6 +239,14 @@ var VAR_WINDOW_BOTTOM = /var\(--window-bottom\)/gi ...@@ -239,6 +239,14 @@ var VAR_WINDOW_BOTTOM = /var\(--window-bottom\)/gi
function processCss(css) { function processCss(css) {
var envMethod = ''
envMethod = uni.canIUse('css.constant') ? 'constant' : envMethod
envMethod = uni.canIUse('css.env') ? 'env' : envMethod
if (envMethod) {
css = css.replace(VAR_STATUS_BAR_HEIGHT, envMethod + '(safe-area-inset-top)')
.replace(VAR_WINDOW_TOP, 'calc(var(--window-top) + ' + envMethod + '(safe-area-inset-top))')
.replace(VAR_WINDOW_BOTTOM, 'calc(var(--window-bottom) + ' + envMethod + '(safe-area-inset-bottom))')
}
var page = getPage() var page = getPage()
if (!uni.canIUse('css.var')) { //不支持 css 变量 if (!uni.canIUse('css.var')) { //不支持 css 变量
var offset = getWindowOffset() var offset = getWindowOffset()
...@@ -265,6 +273,7 @@ function getWindowOffset() { ...@@ -265,6 +273,7 @@ function getWindowOffset() {
if (app && app.$route && app.$route.meta && app.$route.meta.name) { if (app && app.$route && app.$route.meta && app.$route.meta.name) {
return { return {
top: app.$route.meta.windowTop, top: app.$route.meta.windowTop,
// TODO 可配置 TabBar 高度
bottom: app.$route.meta.isTabBar ? 50 : 0 bottom: app.$route.meta.isTabBar ? 50 : 0
} }
} }
...@@ -272,4 +281,4 @@ function getWindowOffset() { ...@@ -272,4 +281,4 @@ function getWindowOffset() {
top: 0, top: 0,
bottom: 0 bottom: 0
} }
} }
...@@ -92,10 +92,10 @@ const getPageComponents = function (inputDir, pagesJson) { ...@@ -92,10 +92,10 @@ const getPageComponents = function (inputDir, pagesJson) {
} }
let windowTop = 44 let windowTop = 44
let pageStyle = Object.assign({}, globalStyle, props) let pageStyle = Object.assign({}, globalStyle, props)
if (pageStyle.navigationStyle === 'custom' || !pageStyle.titleNView || pageStyle.titleNView.type === if (pageStyle.navigationStyle === 'custom' || ('titleNView' in pageStyle && (!pageStyle.titleNView || pageStyle.titleNView.type ===
'transparent' || pageStyle.titleNView.type === 'float') { 'transparent' || pageStyle.titleNView.type === 'float'))) {
windowTop = 0 windowTop = 0
} }
// 删除 app-plus 平台配置 // 删除 app-plus 平台配置
...@@ -327,4 +327,4 @@ global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection( ...@@ -327,4 +327,4 @@ global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection(
${genRegisterPageVueComponentsCode(pageComponents)} ${genRegisterPageVueComponentsCode(pageComponents)}
global.__uniRoutes=[${genPageRoutes(pageComponents).concat(genSystemRoutes()).join(',')}] global.__uniRoutes=[${genPageRoutes(pageComponents).concat(genSystemRoutes()).join(',')}]
` `
} }
function cssSupports (css) {
return window.CSS && window.CSS.supports && window.CSS.supports(css)
}
export default { export default {
'css.var': window.CSS && window.CSS.supports && window.CSS.supports('--a', 0) 'css.var': cssSupports('--a:0'),
} 'css.env': cssSupports('top:env(a)'),
'css.constant': cssSupports('top:constant(a)')
}
...@@ -2,13 +2,14 @@ import { ...@@ -2,13 +2,14 @@ import {
NAVBAR_HEIGHT, NAVBAR_HEIGHT,
TABBAR_HEIGHT TABBAR_HEIGHT
} from 'uni-helpers/constants' } from 'uni-helpers/constants'
import safeAreaInsets from 'safe-area-insets'
export default function getWindowOffset () { export default function getWindowOffset () {
if (uni.canIUse('css.var')) { if (uni.canIUse('css.var')) {
const style = document.documentElement.style const style = document.documentElement.style
return { return {
top: parseInt(style.getPropertyValue('--window-top')) || 0, top: (parseInt(style.getPropertyValue('--window-top')) || 0) + safeAreaInsets.top,
bottom: parseInt(style.getPropertyValue('--window-bottom')) || 0 bottom: (parseInt(style.getPropertyValue('--window-bottom')) || 0) + safeAreaInsets.bottom
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册