-
Notifications
You must be signed in to change notification settings - Fork 1
/
AnimatedProgressProvider.js
55 lines (48 loc) · 1.13 KB
/
AnimatedProgressProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from "react";
import { Animate } from "react-move";
class AnimatedProgressProvider extends React.Component {
interval = undefined;
state = {
isAnimated: false
};
static defaultProps = {
valueStart: 0
};
componentDidMount() {
if (this.props.repeat) {
this.interval = window.setInterval(() => {
this.setState({
isAnimated: !this.state.isAnimated
});
}, this.props.duration * 1000);
} else {
this.setState({
isAnimated: !this.state.isAnimated
});
}
}
componentWillUnmount() {
window.clearInterval(this.interval);
}
render() {
return (
<Animate
start={() => ({
value: this.props.valueStart
})}
update={() => ({
value: [
this.state.isAnimated ? this.props.valueEnd : this.props.valueStart
],
timing: {
duration: this.props.duration * 1000,
ease: this.props.easingFunction
}
})}
>
{({ value }) => this.props.children(value)}
</Animate>
);
}
}
export default AnimatedProgressProvider;