Skip to content

Commit a3a6694

Browse files
committed
fix(loading): 使用 css 动画
close #81
1 parent b7fe5f1 commit a3a6694

File tree

3 files changed

+12
-52
lines changed

3 files changed

+12
-52
lines changed

src/loading/loading.less

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
justify-content: center;
44
align-items: center;
55
overflow: hidden;
6+
7+
&__hide {
8+
height: 0 !important;
9+
display: none;
10+
}
11+
12+
&__animated&__hide {
13+
display: flex;
14+
}
615
}
716

817
.loading {

src/loading/loading.ts

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ Component({
1010
show: {
1111
// 默认显示出来
1212
type: Boolean,
13-
value: true,
14-
observer(newValue) {
15-
this._computedStyle(newValue, this.data.animated)
16-
}
13+
value: true
1714
},
1815
animated: {
1916
type: Boolean,
20-
value: false,
21-
observer(newValue) {
22-
this._computedStyle(this.data.show, newValue)
23-
}
17+
value: false
2418
},
2519
duration: {
2620
// 过渡动画时间
@@ -36,48 +30,5 @@ Component({
3630
type: String,
3731
value: '加载中'
3832
}
39-
},
40-
data: {
41-
animationData: {},
42-
animationInstance: {},
43-
displayStyle: 'none'
44-
},
45-
methods: {
46-
_computedStyle(show, animated) {
47-
if (!show) {
48-
if (!animated) {
49-
this.setData({
50-
displayStyle: 'none'
51-
})
52-
} else {
53-
this._startAnimation()
54-
}
55-
} else {
56-
this.setData({
57-
displayStyle: ''
58-
})
59-
}
60-
},
61-
_startAnimation() {
62-
setTimeout(() => {
63-
const data: any = this.data
64-
const animation = data.animationInstance
65-
animation.height(0).step()
66-
this.setData({
67-
animationData: animation.export()
68-
})
69-
}, 0)
70-
}
71-
},
72-
lifetimes: {
73-
attached() {
74-
const data: any = this.data
75-
const animationInstance = wx.createAnimation({
76-
duration: data.duration,
77-
timingFunction: 'ease'
78-
})
79-
this.setData({ animationInstance })
80-
this._computedStyle(this.data.show, this.data.animated)
81-
}
8233
}
8334
})

src/loading/loading.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<view style="display:{{displayStyle}};" class="wx_loading_view {{extClass}}" animation="{{animationData}}" id="wx_loading_view">
1+
<view class="wx_loading_view {{animated ? 'wx_loading_view__animated' : ''}} {{!show ? 'wx_loading_view__hide' : ''}} {{extClass}}" style="{{animated ? 'transition: height ' + duration + 'ms ease;' : ''}}" id="wx_loading_view">
22
<view wx:if="{{type==='dot-white'}}" class="loading wx_dot_loading wx_dot_loading_white">
33
</view>
44
<view wx:elif="{{type==='dot-gray'}}" class="loading wx_dot_loading"></view>

0 commit comments

Comments
 (0)