提交 f7094833 编写于 作者: Q qiang

fix: h5 windowTop

上级 6b30f3ed
...@@ -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
} }
......
<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) {
......
...@@ -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.
先完成此消息的编辑!
想要评论请 注册