-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimatedCircularProgress.js
59 lines (49 loc) · 1.4 KB
/
AnimatedCircularProgress.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
56
57
58
59
import React, { Component } from 'react';
import { PropTypes } from 'prop-types';
import { Animated, ViewPropTypes } from 'react-native';
import CircularProgress from './CircularProgress';
const AnimatedProgress = Animated.createAnimatedComponent(CircularProgress);
export default class AnimatedCircularProgress extends Component {
constructor(props) {
super(props);
this.state = {
chartFillAnimation: new Animated.Value(props.prefill || 0),
};
}
componentDidMount() {
this.animateFill();
}
componentDidUpdate(prevProps) {
if (prevProps.fill !== this.props.fill) {
this.animateFill();
}
}
animateFill() {
const { tension, friction } = this.props;
Animated.spring(this.state.chartFillAnimation, {
toValue: this.props.fill,
tension,
friction,
}).start();
}
render() {
const { fill, prefill, ...other } = this.props;
return <AnimatedProgress {...other} fill={this.state.chartFillAnimation} />;
}
}
AnimatedCircularProgress.propTypes = {
style: ViewPropTypes.style,
size: PropTypes.number.isRequired,
fill: PropTypes.number,
prefill: PropTypes.number,
width: PropTypes.number.isRequired,
beginColor: PropTypes.string,
endColor: PropTypes.string,
backgroundColor: PropTypes.string,
tension: PropTypes.number,
friction: PropTypes.number,
};
AnimatedCircularProgress.defaultProps = {
tension: 7,
friction: 10,
};