提交 3a9ad945 编写于 作者: Q qiang

feat: uni.getSystemInfo 增加 safeArea 属性支持(app-plus)

上级 612dc687
......@@ -23,10 +23,19 @@ export function getSystemInfo () {
const screenHeight = plus.screen.resolutionHeight
// 横屏时 iOS 获取的状态栏高度错误,进行纠正
var landscape = Math.abs(plus.navigator.getOrientation()) === 90
var statusBarHeight = plus.navigator.getStatusbarHeight()
var statusBarHeight = Math.round(plus.navigator.getStatusbarHeight())
if (ios && landscape) {
statusBarHeight = Math.min(20, statusBarHeight)
}
var safeAreaInsets
function getSafeAreaInsets () {
return {
left: 0,
right: 0,
top: titleNView ? 0 : statusBarHeight,
bottom: 0
}
}
// 判断是否存在 titleNView
var titleNView
var webview = getLastWebview()
......@@ -36,7 +45,22 @@ export function getSystemInfo () {
titleNView = style && style.titleNView
titleNView = titleNView && titleNView.type === 'default'
}
safeAreaInsets = ios ? webview.getSafeAreaInsets() : getSafeAreaInsets()
} else {
safeAreaInsets = ios ? plus.navigator.getSafeAreaInsets() : getSafeAreaInsets()
}
var windowHeight = Math.min(screenHeight - (titleNView ? (statusBarHeight + TITLEBAR_HEIGHT)
: 0) - (isTabBarPage() && tabBar.visible ? TABBAR_HEIGHT : 0), screenHeight)
var windowWidth = screenWidth
var safeArea = {
left: safeAreaInsets.left,
right: windowWidth - safeAreaInsets.right,
top: safeAreaInsets.top,
bottom: windowHeight - safeAreaInsets.bottom,
width: windowWidth - safeAreaInsets.left - safeAreaInsets.right,
height: windowHeight - safeAreaInsets.top - safeAreaInsets.bottom
}
return {
errMsg: 'getSystemInfo:ok',
brand: '',
......@@ -44,11 +68,8 @@ export function getSystemInfo () {
pixelRatio: plus.screen.scale,
screenWidth,
screenHeight,
// 安卓端 webview 宽度有时比屏幕多 1px,相比取最小值
// TODO screenWidth,screenHeight
windowWidth: screenWidth,
windowHeight: Math.min(screenHeight - (titleNView ? (statusBarHeight + TITLEBAR_HEIGHT)
: 0) - (isTabBarPage() && tabBar.visible ? TABBAR_HEIGHT : 0), screenHeight),
windowWidth,
windowHeight,
statusBarHeight,
language: plus.os.language,
system: plus.os.version,
......@@ -57,6 +78,7 @@ export function getSystemInfo () {
platform,
SDKVersion: '',
windowTop: 0,
windowBottom: 0
windowBottom: 0,
safeArea
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册