feat(Tabbar): add placeholder prop (#5979)

This commit is contained in:
neverland
2020-04-01 20:41:04 +08:00
committed by GitHub
parent 0698872285
commit 02e67fdd47
7 changed files with 70 additions and 17 deletions
+40 -14
View File
@@ -10,6 +10,7 @@ export default createComponent({
props: {
route: Boolean,
zIndex: [Number, String],
placeholder: Boolean,
activeColor: String,
inactiveColor: String,
value: {
@@ -30,6 +31,12 @@ export default createComponent({
},
},
data() {
return {
height: null,
};
},
computed: {
fit() {
if (this.safeAreaInsetBottom !== null) {
@@ -45,6 +52,12 @@ export default createComponent({
children: 'setActiveItem',
},
mounted() {
if (this.placeholder && this.fixed) {
this.height = this.$refs.tabbar.getBoundingClientRect().height;
}
},
methods: {
setActiveItem() {
this.children.forEach((item, index) => {
@@ -58,22 +71,35 @@ export default createComponent({
this.$emit('change', active);
}
},
genTabbar() {
return (
<div
ref="tabbar"
style={{ zIndex: this.zIndex }}
class={[
{ [BORDER_TOP_BOTTOM]: this.border },
bem({
unfit: !this.fit,
fixed: this.fixed,
}),
]}
>
{this.slots()}
</div>
);
},
},
render() {
return (
<div
style={{ zIndex: this.zIndex }}
class={[
{ [BORDER_TOP_BOTTOM]: this.border },
bem({
unfit: !this.fit,
fixed: this.fixed,
}),
]}
>
{this.slots()}
</div>
);
if (this.placeholder && this.fixed) {
return (
<div class={bem('placeholder')} style={{ height: `${this.height}px` }}>
{this.genTabbar()}
</div>
);
}
return this.genTabbar();
},
});