From 52dda55d0910974684ef2208116f8f417d646915 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 14 Jan 2020 20:57:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20app-v3=20=E5=8E=9F=E7=94=9F=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=20fixed=20=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platforms/app-plus/view/mixins/native.js | 38 ++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/platforms/app-plus/view/mixins/native.js b/src/platforms/app-plus/view/mixins/native.js index 7f0007843..b2fe601b2 100644 --- a/src/platforms/app-plus/view/mixins/native.js +++ b/src/platforms/app-plus/view/mixins/native.js @@ -1,3 +1,32 @@ +const TITLEBAR_HEIGHT = 44 + +function getStatusbarHeight () { + // 横屏时 iOS 获取的状态栏高度错误,进行纠正 + return plus.navigator.isImmersedStatusbar() ? Math.round(plus.os.name === 'iOS' ? plus.navigator.getSafeAreaInsets().top : plus.navigator.getStatusbarHeight()) : 0 +} + +function getNavigationBarHeight () { + const webview = plus.webview.currentWebview() + let style = webview.getStyle() + style = style && style.titleNView + if (style && style.type === 'default') { + return TITLEBAR_HEIGHT + getStatusbarHeight() + } + return 0 +} + +function getFixed ($el) { + let fixed + while ($el) { + const style = getComputedStyle($el) + const transform = style.transform || style.webkitTransform + fixed = transform && transform !== 'none' ? false : fixed + fixed = style.position === 'fixed' ? true : fixed + $el = $el.parentElement + } + return fixed +} + export default { name: 'Native', data () { @@ -28,10 +57,13 @@ export default { const rect = (this.$refs.container || this.$el).getBoundingClientRect() this.hidden = rect.width === 0 || rect.height === 0 if (!this.hidden) { - ['top', 'left', 'width', 'height'].forEach(key => { + const position = this.position + position.position = getFixed(this.$el) ? 'absolute' : 'static' + const keys = ['top', 'left', 'width', 'height'] + keys.forEach(key => { let val = rect[key] - val = key === 'top' ? val + (document.documentElement.scrollTop || document.body.scrollTop || 0) : val - this.position[key] = val + 'px' + val = key === 'top' ? val + (position.position === 'static' ? (document.documentElement.scrollTop || document.body.scrollTop || 0) : getNavigationBarHeight()) : val + position[key] = val + 'px' }) } }, -- GitLab