fix(collapse): avoid use animation when height is 0 (#3562)

fix #3449
This commit is contained in:
rex 2020-08-26 18:40:35 +08:00 committed by GitHub
parent 13e82ea0db
commit b7e184aa69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ VantComponent({
relation: { relation: {
name: 'collapse', name: 'collapse',
type: 'ancestor', type: 'ancestor',
current: 'collapse-item' current: 'collapse-item',
}, },
props: { props: {
@ -19,22 +19,22 @@ VantComponent({
clickable: Boolean, clickable: Boolean,
border: { border: {
type: Boolean, type: Boolean,
value: true value: true,
}, },
isLink: { isLink: {
type: Boolean, type: Boolean,
value: true value: true,
} },
}, },
data: { data: {
expanded: false expanded: false,
}, },
created() { created() {
this.animation = wx.createAnimation({ this.animation = wx.createAnimation({
duration: 0, duration: 0,
timingFunction: 'ease-in-out' timingFunction: 'ease-in-out',
}); });
}, },
@ -79,32 +79,31 @@ VantComponent({
const { animation } = this; const { animation } = this;
if (expanded) { if (expanded) {
animation if (height === 0) {
.height(height) animation.height('auto').top(1).step();
.top(1) } else {
.step({ animation
duration: inited ? 300 : 1 .height(height)
}) .top(1)
.height('auto') .step({
.step(); duration: inited ? 300 : 1,
})
.height('auto')
.step();
}
this.setData({ this.setData({
animation: animation.export() animation: animation.export(),
}); });
return; return;
} }
animation animation.height(height).top(0).step({ duration: 1 }).height(0).step({
.height(height) duration: 300,
.top(0) });
.step({ duration: 1 })
.height(0)
.step({
duration: 300
});
this.setData({ this.setData({
animation: animation.export() animation: animation.export(),
}); });
}); });
}, },
@ -119,6 +118,6 @@ VantComponent({
const currentName = name == null ? index : name; const currentName = name == null ? index : name;
this.parent.switch(currentName, !expanded); this.parent.switch(currentName, !expanded);
} },
} },
}); });