提交 c028d252 编写于 作者: Q qiang

fix: app-v3 windowTop

fix: app-v3 --window-top

fix: app-v3 windowTop
上级 cddc9e83
...@@ -152,9 +152,7 @@ const PLATFORMS = { ...@@ -152,9 +152,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
......
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
}
} }
} }
export { export {
isTabBarPage isTabBarPage
} from '../bridge' } from '../bridge'
export function callApiSync (api, args, name, alias) { export function callApiSync (api, args, name, alias) {
const ret = api(args) const ret = api(args)
if (ret && ret.errMsg) { if (ret && ret.errMsg) {
...@@ -148,4 +148,22 @@ const _transformlng = function (lng, lat) { ...@@ -148,4 +148,22 @@ 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)
...@@ -40,7 +45,7 @@ function parsePageCreateOptions (vm, route) { ...@@ -40,7 +45,7 @@ function parsePageCreateOptions (vm, route) {
onPageScroll, onPageScroll,
onPageReachBottom, onPageReachBottom,
onReachBottomDistance, onReachBottomDistance,
windowTop: 0, // TODO windowTop: windowOptions.titleNView && windowOptions.titleNView.type === 'float' ? (getStatusbarHeight() + TITLEBAR_HEIGHT) : 0,
windowBottom: (tabBar.indexOf(route) >= 0 && tabBar.cover) ? tabBar.height : 0 windowBottom: (tabBar.indexOf(route) >= 0 && tabBar.cover) ? tabBar.height : 0
} }
} }
...@@ -88,4 +93,4 @@ export function initLifecycle (Vue) { ...@@ -88,4 +93,4 @@ export function initLifecycle (Vue) {
} }
} }
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册