提交 e6e5427e 编写于 作者: Q qiang

Merge branch 'fix-window-top' into dev

...@@ -154,9 +154,7 @@ const PLATFORMS = { ...@@ -154,9 +154,7 @@ const PLATFORMS = {
megalo: false, megalo: false,
filterTag: 'wxs', filterTag: 'wxs',
subPackages: false, subPackages: false,
cssVars: { cssVars: {},
'--window-top': '0px'
},
copyWebpackOptions ({ copyWebpackOptions ({
assetsDir, assetsDir,
vueOptions vueOptions
......
...@@ -239,14 +239,6 @@ var VAR_WINDOW_BOTTOM = /var\(--window-bottom\)/gi ...@@ -239,14 +239,6 @@ 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()
......
...@@ -96,9 +96,22 @@ const getPageComponents = function (inputDir, pagesJson) { ...@@ -96,9 +96,22 @@ const getPageComponents = function (inputDir, pagesJson) {
} }
let windowTop = 44 let windowTop = 44
let pageStyle = Object.assign({}, globalStyle, props) const pageStyle = Object.assign({}, globalStyle, props)
if (pageStyle.navigationStyle === 'custom' || ('titleNView' in pageStyle && (!pageStyle.titleNView || pageStyle.titleNView.type === const titleNViewTypeList = {
'transparent' || pageStyle.titleNView.type === 'float'))) { 'none': 'default',
'auto': 'transparent',
'always': 'float'
}
let titleNView = pageStyle.titleNView
titleNView = Object.assign({}, {
type: pageStyle.navigationStyle === 'custom' ? 'none' : 'default'
}, pageStyle.transparentTitle in titleNViewTypeList ? {
type: titleNViewTypeList[pageStyle.transparentTitle],
backgroundColor: 'rgba(0,0,0,0)'
} : null, typeof titleNView === 'object' ? titleNView : (typeof titleNView === 'boolean' ? {
type: titleNView ? 'default' : 'none'
} : null))
if (titleNView.type === 'none' || titleNView.type === 'transparent') {
windowTop = 0 windowTop = 0
} }
......
import { import {
callApiSync, callApiSync,
isTabBarPage, isTabBarPage,
getLastWebview getLastWebview,
getStatusbarHeight,
getScreenInfo
} from '../util' } from '../util'
import { import {
...@@ -17,48 +19,55 @@ export function getSystemInfoSync () { ...@@ -17,48 +19,55 @@ export function getSystemInfoSync () {
export function getSystemInfo () { export function getSystemInfo () {
const platform = plus.os.name.toLowerCase() const platform = plus.os.name.toLowerCase()
const ios = platform === 'ios' const ios = platform === 'ios'
// 安卓 plus 接口获取的屏幕大小值不为整数,iOS js 获取的屏幕大小横屏时颠倒 const {
const screenWidth = plus.screen.resolutionWidth screenWidth,
const screenHeight = plus.screen.resolutionHeight screenHeight
// 横屏时 iOS 获取的状态栏高度错误,进行纠正 } = getScreenInfo()
var landscape = Math.abs(plus.navigator.getOrientation()) === 90 const statusBarHeight = getStatusbarHeight()
var statusBarHeight = Math.round(plus.navigator.getStatusbarHeight())
if (ios && landscape) { let safeAreaInsets
statusBarHeight = Math.min(20, statusBarHeight) const titleNView = {
} height: 0,
var safeAreaInsets cover: false
function getSafeAreaInsets () {
return {
left: 0,
right: 0,
top: titleNView ? 0 : statusBarHeight,
bottom: 0
}
} }
// 判断是否存在 titleNView const webview = getLastWebview()
var titleNView
var webview = getLastWebview()
if (webview) { if (webview) {
let style = webview.getStyle() let style = webview.getStyle()
if (style) { style = style && style.titleNView
titleNView = style && style.titleNView if (style && style.type && style.type !== 'none') {
titleNView = titleNView && titleNView.type === 'default' titleNView.height = style.type === 'transparent' ? 0 : (statusBarHeight + TITLEBAR_HEIGHT)
titleNView.cover = style.type === 'transparent' || style.type === 'float'
} }
safeAreaInsets = ios ? webview.getSafeAreaInsets() : getSafeAreaInsets() safeAreaInsets = webview.getSafeAreaInsets()
} else { } else {
safeAreaInsets = ios ? plus.navigator.getSafeAreaInsets() : getSafeAreaInsets() safeAreaInsets = plus.navigator.getSafeAreaInsets()
} }
var windowBottom = isTabBarPage() && tabBar.visible && tabBar.cover ? tabBar.height : 0 const tabBarView = {
var windowHeight = Math.min(screenHeight - (titleNView ? (statusBarHeight + TITLEBAR_HEIGHT) height: 0,
: 0) - windowBottom, screenHeight) cover: false
var windowWidth = screenWidth }
var safeArea = { if (isTabBarPage()) {
tabBarView.height = tabBar.visible ? tabBar.height : 0
tabBarView.cover = tabBar.cover
}
const windowTop = titleNView.cover ? titleNView.height : 0
const windowBottom = tabBarView.cover ? tabBarView.height : 0
const windowHeight = screenHeight - titleNView.height - tabBarView.height
const windowHeightReal = screenHeight - (titleNView.cover ? 0 : titleNView.height) - (tabBarView.cover ? 0 : tabBarView.height)
const windowWidth = screenWidth
safeAreaInsets = ios ? safeAreaInsets : {
left: 0,
right: 0,
top: titleNView.height && !titleNView.cover ? 0 : statusBarHeight,
bottom: 0
}
const safeArea = {
left: safeAreaInsets.left, left: safeAreaInsets.left,
right: windowWidth - safeAreaInsets.right, right: windowWidth - safeAreaInsets.right,
top: safeAreaInsets.top, top: safeAreaInsets.top,
bottom: windowHeight - safeAreaInsets.bottom, bottom: windowHeightReal - safeAreaInsets.bottom,
width: windowWidth - safeAreaInsets.left - safeAreaInsets.right, width: windowWidth - safeAreaInsets.left - safeAreaInsets.right,
height: windowHeight - safeAreaInsets.top - safeAreaInsets.bottom height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom
} }
return { return {
...@@ -77,8 +86,14 @@ export function getSystemInfo () { ...@@ -77,8 +86,14 @@ export function getSystemInfo () {
fontSizeSetting: '', fontSizeSetting: '',
platform, platform,
SDKVersion: '', SDKVersion: '',
windowTop: 0, windowTop,
windowBottom, windowBottom,
safeArea safeArea,
safeAreaInsets: {
top: safeAreaInsets.top,
right: safeAreaInsets.right,
bottom: safeAreaInsets.bottom,
left: safeAreaInsets.left
}
} }
} }
...@@ -149,3 +149,21 @@ const _transformlng = function (lng, lat) { ...@@ -149,3 +149,21 @@ const _transformlng = function (lng, lat) {
const outOfChina = function (lng, lat) { const outOfChina = function (lng, lat) {
return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false) return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false)
} }
export function getStatusbarHeight () {
// 横屏时 iOS 获取的状态栏高度错误,进行纠正
return plus.navigator.isImmersedStatusbar() ? Math.round(plus.os.name === 'iOS' ? plus.navigator.getSafeAreaInsets().top : plus.navigator.getStatusbarHeight()) : 0
}
export function getScreenInfo () {
const orientation = plus.navigator.getOrientation()
const landscape = Math.abs(orientation) === 90
// 安卓 plus 接口获取的屏幕大小值不为整数
const width = plus.screen.resolutionWidth
const height = plus.screen.resolutionHeight
// 根据方向纠正宽高
return {
screenWidth: Math[landscape ? 'max' : 'min'](width, height),
screenHeight: Math[landscape ? 'min' : 'max'](width, height)
}
}
...@@ -16,12 +16,17 @@ import { ...@@ -16,12 +16,17 @@ import {
from 'uni-core/service/plugins/lifecycle' from 'uni-core/service/plugins/lifecycle'
import { import {
ON_REACH_BOTTOM_DISTANCE ON_REACH_BOTTOM_DISTANCE,
TITLEBAR_HEIGHT
} }
from '../../constants' from '../../constants'
import tabBar from '../tab-bar' import tabBar from '../tab-bar'
import {
getStatusbarHeight
} from '../../api/util'
function parsePageCreateOptions (vm, route) { function parsePageCreateOptions (vm, route) {
const pagePath = '/' + route const pagePath = '/' + route
const routeOptions = __uniRoutes.find(route => route.path === pagePath) const routeOptions = __uniRoutes.find(route => route.path === pagePath)
...@@ -34,13 +39,15 @@ function parsePageCreateOptions (vm, route) { ...@@ -34,13 +39,15 @@ function parsePageCreateOptions (vm, route) {
const onPageScroll = hasLifecycleHook(vm.$options, 'onPageScroll') ? 1 : 0 const onPageScroll = hasLifecycleHook(vm.$options, 'onPageScroll') ? 1 : 0
const onPageReachBottom = hasLifecycleHook(vm.$options, 'onReachBottom') ? 1 : 0 const onPageReachBottom = hasLifecycleHook(vm.$options, 'onReachBottom') ? 1 : 0
const statusbarHeight = getStatusbarHeight()
return { return {
disableScroll, disableScroll,
onPageScroll, onPageScroll,
onPageReachBottom, onPageReachBottom,
onReachBottomDistance, onReachBottomDistance,
windowTop: 0, // TODO statusbarHeight,
windowTop: windowOptions.titleNView && windowOptions.titleNView.type === 'float' ? (statusbarHeight + TITLEBAR_HEIGHT) : 0,
windowBottom: (tabBar.indexOf(route) >= 0 && tabBar.cover) ? tabBar.height : 0 windowBottom: (tabBar.indexOf(route) >= 0 && tabBar.cover) ? tabBar.height : 0
} }
} }
......
...@@ -10,6 +10,10 @@ import { ...@@ -10,6 +10,10 @@ import {
isTabBarPage isTabBarPage
} from '../../../bridge' } from '../../../bridge'
import {
getStatusbarHeight
} from '../../../api/util'
import tabBar from '../../tab-bar' import tabBar from '../../tab-bar'
function initPopupSubNVue (subNVueWebview, style, maskWebview) { function initPopupSubNVue (subNVueWebview, style, maskWebview) {
...@@ -96,7 +100,7 @@ function initSubNVue (subNVue, routeOptions, webview) { ...@@ -96,7 +100,7 @@ function initSubNVue (subNVue, routeOptions, webview) {
style.dock = 'top' style.dock = 'top'
style.top = 0 style.top = 0
style.width = '100%' style.width = '100%'
style.height = TITLEBAR_HEIGHT + plus.navigator.getStatusbarHeight() style.height = TITLEBAR_HEIGHT + getStatusbarHeight()
delete style.left delete style.left
delete style.right delete style.right
delete style.bottom delete style.bottom
......
...@@ -20,6 +20,7 @@ const passiveOptions = supportsPassive ? { ...@@ -20,6 +20,7 @@ const passiveOptions = supportsPassive ? {
} : false } : false
function onCssVar ({ function onCssVar ({
statusbarHeight,
windowTop, windowTop,
windowBottom windowBottom
}) { }) {
...@@ -29,8 +30,9 @@ function onCssVar ({ ...@@ -29,8 +30,9 @@ function onCssVar ({
const style = document.documentElement.style const style = document.documentElement.style
style.setProperty('--window-top', windowTop + 'px') style.setProperty('--window-top', windowTop + 'px')
style.setProperty('--window-bottom', windowBottom + 'px') style.setProperty('--window-bottom', windowBottom + 'px')
style.setProperty('--status-bar-height', plus.navigator.getStatusbarHeight() + 'px') style.setProperty('--status-bar-height', statusbarHeight + 'px')
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log(`--status-bar-height=${statusbarHeight}`)
console.log(`--window-top=${windowTop}`) console.log(`--window-top=${windowTop}`)
console.log(`--window-bottom=${windowBottom}`) console.log(`--window-bottom=${windowBottom}`)
} }
...@@ -38,6 +40,7 @@ function onCssVar ({ ...@@ -38,6 +40,7 @@ function onCssVar ({
} }
function onPageCreate ({ function onPageCreate ({
statusbarHeight,
windowTop, windowTop,
windowBottom, windowBottom,
disableScroll, disableScroll,
...@@ -46,6 +49,7 @@ function onPageCreate ({ ...@@ -46,6 +49,7 @@ function onPageCreate ({
onReachBottomDistance onReachBottomDistance
}, pageId) { }, pageId) {
onCssVar({ onCssVar({
statusbarHeight,
windowTop, windowTop,
windowBottom windowBottom
}) })
......
<template> <template>
<uni-page :data-page="$route.meta.pagePath"> <uni-page :data-page="$route.meta.pagePath">
<page-head <page-head
v-if="showNavigationBar" v-if="navigationBar.type!=='none'"
v-bind="navigationBar" /> v-bind="navigationBar" />
<page-refresh <page-refresh
v-if="enablePullDownRefresh" v-if="enablePullDownRefresh"
ref="refresh" ref="refresh"
:color="refreshOptions.color" :color="refreshOptions.color"
:offset="refreshOptions.offset" /> :offset="refreshOptions.offset"
/>
<page-body <page-body
v-if="enablePullDownRefresh" v-if="enablePullDownRefresh"
@touchstart.native="_touchstart" @touchstart.native="_touchstart"
@touchmove.native="_touchmove" @touchmove.native="_touchmove"
@touchend.native="_touchend" @touchend.native="_touchend"
@touchcancel.native="_touchend"> @touchcancel.native="_touchend"
>
<slot name="page" /> <slot name="page" />
</page-body> </page-body>
<page-body v-else> <page-body v-else>
...@@ -22,11 +24,11 @@ ...@@ -22,11 +24,11 @@
</uni-page> </uni-page>
</template> </template>
<style> <style>
uni-page { uni-page {
display: block; display: block;
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
</style> </style>
<script> <script>
import { import {
...@@ -47,6 +49,8 @@ import PageRefresh from './pageRefresh' ...@@ -47,6 +49,8 @@ import PageRefresh from './pageRefresh'
import pullToRefresh from './pull-to-refresh' import pullToRefresh from './pull-to-refresh'
import safeAreaInsets from 'safe-area-insets'
export default { export default {
name: 'Page', name: 'Page',
mpType: 'page', mpType: 'page',
...@@ -124,8 +128,8 @@ export default { ...@@ -124,8 +128,8 @@ export default {
default: false default: false
}, },
titleNView: { titleNView: {
type: [Boolean, Object], type: [Boolean, Object, String],
default: true default: ''
}, },
pullToRefresh: { pullToRefresh: {
type: Object, type: Object,
...@@ -139,7 +143,7 @@ export default { ...@@ -139,7 +143,7 @@ export default {
}, },
transparentTitle: { transparentTitle: {
type: String, type: String,
default: 'none' default: ''
}, },
titlePenetrate: { titlePenetrate: {
type: String, type: String,
...@@ -152,6 +156,16 @@ export default { ...@@ -152,6 +156,16 @@ export default {
'auto': 'transparent', 'auto': 'transparent',
'always': 'float' 'always': 'float'
} }
// 将 navigationStyle 和 transparentTitle 都合并到 titleNView
let titleNView = this.titleNView
titleNView = Object.assign({}, {
type: this.navigationStyle === 'custom' ? 'none' : 'default'
}, this.transparentTitle in titleNViewTypeList ? {
type: titleNViewTypeList[this.transparentTitle],
backgroundColor: 'rgba(0,0,0,0)'
} : null, typeof titleNView === 'object' ? titleNView : (typeof titleNView === 'boolean' ? {
type: titleNView ? 'default' : 'none'
} : null))
const yesNoParseList = { const yesNoParseList = {
'YES': true, 'YES': true,
...@@ -167,12 +181,8 @@ export default { ...@@ -167,12 +181,8 @@ export default {
titleImage: this.titleImage, titleImage: this.titleImage,
duration: '0', duration: '0',
timingFunc: '', timingFunc: '',
type: titleNViewTypeList[this.transparentTitle],
transparentTitle: this.transparentTitle,
titlePenetrate: yesNoParseList[this.titlePenetrate] titlePenetrate: yesNoParseList[this.titlePenetrate]
}, this.titleNView) }, titleNView)
const showNavigationBar = this.navigationStyle === 'default' && this.titleNView
const refreshOptions = Object.assign({ const refreshOptions = Object.assign({
support: true, support: true,
...@@ -185,10 +195,8 @@ export default { ...@@ -185,10 +195,8 @@ export default {
let offset = upx2px(refreshOptions.offset) let offset = upx2px(refreshOptions.offset)
if (showNavigationBar) { if (titleNView.type !== 'transparent') {
if (!(this.titleNView && this.titleNView.type === 'transparent')) { offset += NAVBAR_HEIGHT + safeAreaInsets.top
offset += NAVBAR_HEIGHT
}
} }
refreshOptions.offset = offset refreshOptions.offset = offset
...@@ -196,7 +204,6 @@ export default { ...@@ -196,7 +204,6 @@ export default {
refreshOptions.range = upx2px(refreshOptions.range) refreshOptions.range = upx2px(refreshOptions.range)
return { return {
showNavigationBar,
navigationBar, navigationBar,
refreshOptions refreshOptions
} }
......
...@@ -14,6 +14,8 @@ uni-page-wrapper { ...@@ -14,6 +14,8 @@ uni-page-wrapper {
uni-page-head[uni-page-head-type="default"] ~ uni-page-wrapper { uni-page-head[uni-page-head-type="default"] ~ uni-page-wrapper {
height: calc(100% - 44px); height: calc(100% - 44px);
height: calc(100% - 44px - constant(safe-area-inset-top));
height: calc(100% - 44px - env(safe-area-inset-top));
} }
.uni-app--showtabbar uni-page-wrapper { .uni-app--showtabbar uni-page-wrapper {
...@@ -34,8 +36,8 @@ uni-page-head[uni-page-head-type="default"] ~ uni-page-wrapper { ...@@ -34,8 +36,8 @@ uni-page-head[uni-page-head-type="default"] ~ uni-page-wrapper {
.uni-app--showtabbar uni-page-head[uni-page-head-type="default"] ~ uni-page-wrapper { .uni-app--showtabbar uni-page-head[uni-page-head-type="default"] ~ uni-page-wrapper {
height: calc(100% - 44px - 50px); height: calc(100% - 44px - 50px);
height: calc(100% - 44px - 50px - constant(safe-area-inset-bottom)); height: calc(100% - 44px - constant(safe-area-inset-top) - 50px - constant(safe-area-inset-bottom));
height: calc(100% - 44px - 50px - env(safe-area-inset-bottom)); height: calc(100% - 44px - env(safe-area-inset-top) - 50px - env(safe-area-inset-bottom));
} }
uni-page-body { uni-page-body {
......
...@@ -41,14 +41,12 @@ ...@@ -41,14 +41,12 @@
> >
<i <i
v-if="loading" v-if="loading"
class="uni-loading"/> class="uni-loading" />
<img <img
v-if="titleImage!==''" v-if="titleImage!==''"
:src="titleImage" :src="titleImage"
class="uni-page-head__title_image" > class="uni-page-head__title_image" >
<template v-else> <template v-else>{{ titleText }}</template>
{{ titleText }}
</template>
</div> </div>
</div> </div>
<div <div
...@@ -98,7 +96,8 @@ ...@@ -98,7 +96,8 @@
<div <div
v-if="type!=='transparent'&&type!=='float'" v-if="type!=='transparent'&&type!=='float'"
:class="{'uni-placeholder-titlePenetrate': titlePenetrate}" :class="{'uni-placeholder-titlePenetrate': titlePenetrate}"
class="uni-placeholder"/> class="uni-placeholder"
/>
</uni-page-head> </uni-page-head>
</template> </template>
<style> <style>
...@@ -112,7 +111,11 @@ uni-page-head .uni-page-head { ...@@ -112,7 +111,11 @@ uni-page-head .uni-page-head {
left: 0; left: 0;
width: 100%; width: 100%;
height: 44px; height: 44px;
height: calc(44px + constant(safe-area-inset-top));
height: calc(44px + env(safe-area-inset-top));
padding: 7px 3px; padding: 7px 3px;
padding-top: calc(7px + constant(safe-area-inset-top));
padding-top: calc(7px + env(safe-area-inset-top));
display: flex; display: flex;
overflow: hidden; overflow: hidden;
justify-content: space-between; justify-content: space-between;
...@@ -129,7 +132,7 @@ uni-page-head .uni-page-head-titlePenetrate .uni-page-head-bd * { ...@@ -129,7 +132,7 @@ uni-page-head .uni-page-head-titlePenetrate .uni-page-head-bd * {
pointer-events: none; pointer-events: none;
} }
uni-page-head .uni-page-head-titlePenetrate *{ uni-page-head .uni-page-head-titlePenetrate * {
pointer-events: auto; pointer-events: auto;
} }
...@@ -140,9 +143,11 @@ uni-page-head .uni-page-head.uni-page-head-transparent .uni-page-head-ft > div { ...@@ -140,9 +143,11 @@ uni-page-head .uni-page-head.uni-page-head-transparent .uni-page-head-ft > div {
uni-page-head .uni-page-head ~ .uni-placeholder { uni-page-head .uni-page-head ~ .uni-placeholder {
width: 100%; width: 100%;
height: 44px; height: 44px;
height: calc(44px + constant(safe-area-inset-top));
height: calc(44px + env(safe-area-inset-top));
} }
uni-page-head .uni-placeholder-titlePenetrate{ uni-page-head .uni-placeholder-titlePenetrate {
pointer-events: none; pointer-events: none;
} }
...@@ -321,7 +326,9 @@ export default { ...@@ -321,7 +326,9 @@ export default {
}, },
backgroundColor: { backgroundColor: {
type: String, type: String,
default: '#000' default () {
return this.type === 'transparent' ? '#000' : '#F8F8F8'
}
}, },
textColor: { textColor: {
type: String, type: String,
...@@ -373,12 +380,6 @@ export default { ...@@ -373,12 +380,6 @@ export default {
type: String, type: String,
default: '' default: ''
}, },
transparentTitle: {
default: 'none',
validator (value) {
return ['none', 'auto', 'always'].indexOf(value) !== -1
}
},
titlePenetrate: { titlePenetrate: {
type: Boolean, type: Boolean,
default: false default: false
......
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
borderRadiusElemStyle.backgroundColor = `rgba(${rgba})` borderRadiusElemStyle.backgroundColor = `rgba(${rgba})`
}) })
}) })
} else if (this.transparentTitle === 'always') { } else if (this.type === 'float') {
const iconElems = this.$el.querySelectorAll('.uni-btn-icon') const iconElems = this.$el.querySelectorAll('.uni-btn-icon')
const iconElemsStyles = [] const iconElemsStyles = []
for (let i = 0; i < iconElems.length; i++) { for (let i = 0; i < iconElems.length; i++) {
...@@ -70,13 +70,13 @@ export default { ...@@ -70,13 +70,13 @@ export default {
}, },
computed: { computed: {
color () { color () {
return this.type === 'transparent' || this.transparentTitle === 'always' ? '#fff' : this.textColor return this.type === 'transparent' ? '#fff' : this.textColor
}, },
offset () { offset () {
return parseInt(this.coverage) return parseInt(this.coverage)
}, },
bgColor () { bgColor () {
if (this.type === 'transparent' || this.transparentTitle === 'always') { if (this.type === 'transparent') {
const { const {
r, r,
g, g,
......
...@@ -7,9 +7,11 @@ import safeAreaInsets from 'safe-area-insets' ...@@ -7,9 +7,11 @@ 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
const top = parseInt((style.getPropertyValue('--window-top').match(/\d+/) || ['0'])[0])
const bottom = parseInt((style.getPropertyValue('--window-bottom').match(/\d+/) || ['0'])[0])
return { return {
top: (parseInt(style.getPropertyValue('--window-top')) || 0) + safeAreaInsets.top, top: top ? (top + safeAreaInsets.top) : 0,
bottom: (parseInt(style.getPropertyValue('--window-bottom')) || 0) + safeAreaInsets.bottom bottom: bottom ? (bottom + safeAreaInsets.bottom) : 0
} }
} }
...@@ -18,7 +20,8 @@ export default function getWindowOffset () { ...@@ -18,7 +20,8 @@ export default function getWindowOffset () {
const pages = getCurrentPages() const pages = getCurrentPages()
if (pages.length) { if (pages.length) {
const pageVm = pages[pages.length - 1].$parent.$parent const pageVm = pages[pages.length - 1].$parent.$parent
top = pageVm.showNavigationBar && (pageVm.navigationBar.type !== 'transparent' || pageVm.navigationBar.type !== 'float') ? NAVBAR_HEIGHT : 0 const navigationBarType = pageVm.navigationBar.type
top = navigationBarType === 'default' || navigationBarType === 'float' ? NAVBAR_HEIGHT : 0
} }
const app = getApp() const app = getApp()
if (app) { if (app) {
......
...@@ -21,7 +21,7 @@ export function getSystemInfoSync () { ...@@ -21,7 +21,7 @@ export function getSystemInfoSync () {
var screenWidth = screen.width var screenWidth = screen.width
var screenHeight = screen.height var screenHeight = screen.height
var language = navigator.language var language = navigator.language
var statusBarHeight = 0 var statusBarHeight = safeAreaInsets.top
var osname var osname
var osversion var osversion
var model var model
...@@ -84,7 +84,7 @@ export function getSystemInfoSync () { ...@@ -84,7 +84,7 @@ export function getSystemInfoSync () {
const { const {
top: windowTop, top: windowTop,
bottom: windowBottom bottom: windowBottom
} = getWindowOffset(false, true) } = getWindowOffset()
windowHeight -= windowTop windowHeight -= windowTop
windowHeight -= windowBottom windowHeight -= windowBottom
...@@ -102,7 +102,13 @@ export function getSystemInfoSync () { ...@@ -102,7 +102,13 @@ export function getSystemInfoSync () {
system, system,
platform, platform,
model, model,
safeArea safeArea,
safeAreaInsets: {
top: safeAreaInsets.top,
right: safeAreaInsets.right,
bottom: safeAreaInsets.bottom,
left: safeAreaInsets.left
}
} }
} }
/** /**
......
...@@ -24,11 +24,12 @@ const passiveOptions = supportsPassive ? { ...@@ -24,11 +24,12 @@ const passiveOptions = supportsPassive ? {
function updateCssVar (vm) { function updateCssVar (vm) {
if (uni.canIUse('css.var')) { if (uni.canIUse('css.var')) {
const pageVm = vm.$parent.$parent const pageVm = vm.$parent.$parent
const windowTop = pageVm.showNavigationBar && pageVm.navigationBar.type !== 'transparent' && pageVm.navigationBar.type !== const navigationBarType = pageVm.navigationBar.type
'float' ? (NAVBAR_HEIGHT + const windowTopValue = navigationBarType === 'default' || navigationBarType === 'float' ? NAVBAR_HEIGHT : 0
'px') const windowBottomValue = getApp().$children[0].showTabBar ? TABBAR_HEIGHT : 0
: '0px' const envMethod = uni.canIUse('css.env') ? 'env' : (uni.canIUse('css.constant') ? 'constant' : '')
const windowBottom = getApp().$children[0].showTabBar ? (TABBAR_HEIGHT + 'px') : '0px' const windowTop = windowTopValue && envMethod ? `calc(${windowTopValue}px + ${envMethod}(safe-area-inset-top))` : '0px'
const windowBottom = windowBottomValue && envMethod ? `calc(${windowBottomValue}px + ${envMethod}(safe-area-inset-bottom))` : '0px'
const style = document.documentElement.style const style = document.documentElement.style
style.setProperty('--window-top', windowTop) style.setProperty('--window-top', windowTop)
style.setProperty('--window-bottom', windowBottom) style.setProperty('--window-bottom', windowBottom)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册