feat(NavBar): add new prop fill (#2896)

* feat(NavBar): add new prop fill

fix #2887

* refactor(NavBar): rename fill to placeholder
This commit is contained in:
rex 2020-03-23 20:53:18 +08:00 committed by GitHub
parent c7efd0ea7e
commit dbe94b3bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 4 deletions

View File

@ -56,6 +56,7 @@ Page({
| right-text | 右侧文案 | *string* | `''` | - | | right-text | 右侧文案 | *string* | `''` | - |
| left-arrow | 是否显示左侧箭头 | *boolean* | `false` | - | | left-arrow | 是否显示左侧箭头 | *boolean* | `false` | - |
| fixed | 是否固定在顶部 | *boolean* | `false` | - | | fixed | 是否固定在顶部 | *boolean* | `false` | - |
| placeholder | 固定在顶部时是否开启占位 | *boolean* | `false` | - |
| border | 是否显示下边框 | *boolean* | `true` | - | | border | 是否显示下边框 | *boolean* | `true` | - |
| z-index | 元素 z-index | *number* | `1` | - | | z-index | 元素 z-index | *number* | `1` | - |
| safe-area-inset-top | 是否留出顶部安全距离(状态栏高度) | *boolean* | `true` | - | | safe-area-inset-top | 是否留出顶部安全距离(状态栏高度) | *boolean* | `true` | - |

View File

@ -5,7 +5,14 @@ VantComponent({
props: { props: {
title: String, title: String,
fixed: Boolean, fixed: {
type: Boolean,
observer: 'setHeight'
},
placeholder: {
type: Boolean,
observer: 'setHeight'
},
leftText: String, leftText: String,
rightText: String, rightText: String,
leftArrow: Boolean, leftArrow: Boolean,
@ -20,16 +27,24 @@ VantComponent({
safeAreaInsetTop: { safeAreaInsetTop: {
type: Boolean, type: Boolean,
value: true value: true
}, }
}, },
data: { data: {
statusBarHeight: 0 statusBarHeight: 0,
height: 44
}, },
created() { created() {
const { statusBarHeight } = wx.getSystemInfoSync(); const { statusBarHeight } = wx.getSystemInfoSync();
this.setData({ statusBarHeight }); this.setData({
statusBarHeight,
height: 44 + statusBarHeight
});
},
mounted() {
this.setHeight();
}, },
methods: { methods: {
@ -39,6 +54,20 @@ VantComponent({
onClickRight() { onClickRight() {
this.$emit('click-right'); this.$emit('click-right');
},
setHeight() {
if (!this.data.fixed || !this.data.placeholder) {
return;
}
wx.nextTick(() => {
this.getRect('.van-nav-bar').then(
(res: WechatMiniprogram.BoundingClientRectCallbackResult) => {
this.setData({ height: res.height });
}
);
});
} }
} }
}); });

View File

@ -1,5 +1,7 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="../wxs/utils.wxs" module="utils" />
<view wx:if="{{ fixed && placeholder }}" style="height: {{ height }}px;" />
<view <view
class="{{ utils.bem('nav-bar', { fixed }) }} custom-class {{ border ? 'van-hairline--bottom' : '' }}" class="{{ utils.bem('nav-bar', { fixed }) }} custom-class {{ border ? 'van-hairline--bottom' : '' }}"
style="z-index: {{ zIndex }}; padding-top: {{ safeAreaInsetTop ? statusBarHeight : 0 }}px;" style="z-index: {{ zIndex }}; padding-top: {{ safeAreaInsetTop ? statusBarHeight : 0 }}px;"