From 55568754bd54278de79131760432dc52c3bf1a15 Mon Sep 17 00:00:00 2001 From: lainlee Date: Wed, 27 Nov 2019 18:42:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20navigation-bar=20=E5=9C=A8?= =?UTF-8?q?=E6=97=A7=E7=89=88=E6=9C=AC=E5=BE=AE=E4=BF=A1=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/navigation-bar/navigation-bar.ts | 32 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/navigation-bar/navigation-bar.ts b/src/navigation-bar/navigation-bar.ts index 8b5ff88..e2c0985 100644 --- a/src/navigation-bar/navigation-bar.ts +++ b/src/navigation-bar/navigation-bar.ts @@ -54,18 +54,14 @@ Component({ displayStyle: '' }, attached() { - const isSupport = !!wx.getMenuButtonBoundingClientRect - const rect = wx.getMenuButtonBoundingClientRect ? wx.getMenuButtonBoundingClientRect() : null wx.getSystemInfo({ success: res => { const ios = !!(res.system.toLowerCase().search('ios') + 1) this.setData({ - ios, - statusBarHeight: res.statusBarHeight, - innerWidth: isSupport ? `width:${rect.left}px` : '', - innerPaddingRight: isSupport ? `padding-right:${res.windowWidth - rect.left}px` : '', - leftWidth: isSupport ? `width:${res.windowWidth - rect.left}px` : '', + ios: ios, + statusBarHeight: res.statusBarHeight }) + this.setStyle(res) }, }) }, @@ -73,6 +69,28 @@ Component({ * 组件的方法列表 */ methods: { + setStyle(res) { + var isSupport = !!wx.getMenuButtonBoundingClientRect + if (isSupport) { + var rect = wx.getMenuButtonBoundingClientRect() + this.setData({ + innerWidth: 'width:' + rect.left + 'px', + innerPaddingRight: 'padding-right:' + (res.windowWidth - rect.left) + 'px', + leftWidth: 'width:' + (res.windowWidth - rect.left) + 'px' + }) + if (rect.left === 0) { + setTimeout(() => { + this.setStyle(res) + }, 100) + } + } else { + this.setData({ + innerWidth: '', + innerPaddingRight: '', + leftWidth: '' + }) + } + }, _showChange(show) { const animated = this.data.animated let displayStyle = ''