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

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

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