Skip to content

Commit a186af9

Browse files
committed
update enhancer
1 parent 35a6b2e commit a186af9

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/Circle.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,16 @@ class Circle extends Component {
7474
strokeWidth={ptg === 0 ? 0 : strokeWidth}
7575
fillOpacity="0"
7676
style={pathStyle}
77+
ref={(path) => {
78+
this.paths[index] = path;
79+
}}
7780
/>
7881
);
7982
});
8083
}
8184

85+
paths = {};
86+
8287
render() {
8388
const {
8489
prefixCls, strokeWidth, trailWidth,

src/Line.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import enhancer from './enhancer';
33
import { propTypes, defaultProps } from './types';
44

55
class Line extends Component {
6+
paths = {};
7+
68
render() {
79
const {
810
className,
@@ -67,7 +69,9 @@ class Line extends Component {
6769
stroke={color}
6870
strokeWidth={strokeWidth}
6971
fillOpacity="0"
70-
ref={(path) => { this.path = path; }}
72+
ref={(path) => {
73+
this.paths[index] = path;
74+
}}
7175
style={pathStyle}
7276
/>
7377
);

src/enhancer.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
const enhancer = WrappedComponent => class Progress extends WrappedComponent {
22
componentDidUpdate() {
3-
if (!this.path) {
4-
return;
5-
}
6-
const pathStyle = this.path.style;
7-
pathStyle.transitionDuration = '.3s, .3s, .3s, .06s';
83
const now = Date.now();
9-
if (this.prevTimeStamp && now - this.prevTimeStamp < 100) {
10-
pathStyle.transitionDuration = '0s, 0s';
4+
let updated = false;
5+
6+
Object.keys(this.paths).forEach((key) => {
7+
const path = this.paths[key];
8+
9+
if (!path) {
10+
return;
11+
}
12+
13+
updated = true;
14+
const pathStyle = path.style;
15+
pathStyle.transitionDuration = '.3s, .3s, .3s, .06s';
16+
17+
if (this.prevTimeStamp && now - this.prevTimeStamp < 100) {
18+
pathStyle.transitionDuration = '0s, 0s';
19+
}
20+
});
21+
22+
if (updated) {
23+
this.prevTimeStamp = Date.now();
1124
}
12-
this.prevTimeStamp = Date.now();
1325
}
1426

1527
render() {

0 commit comments

Comments
 (0)