From 3a9ad945f4604386bdf4cf1706355d8e7c572b2a Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 22 Aug 2019 00:24:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20uni.getSystemInfo=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20safeArea=20=E5=B1=9E=E6=80=A7=E6=94=AF=E6=8C=81=EF=BC=88app-?= =?UTF-8?q?plus=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app-plus/service/api/device/system.js | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/platforms/app-plus/service/api/device/system.js b/src/platforms/app-plus/service/api/device/system.js index 84ae08db6..de4886a2a 100644 --- a/src/platforms/app-plus/service/api/device/system.js +++ b/src/platforms/app-plus/service/api/device/system.js @@ -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 } -} +} -- GitLab