CircleBox.js
2.2 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Created by mac on 2017/5/10.
*/
import React, { Component} from 'react';
import {
View,
Text,
StyleSheet
} from 'react-native';
import {AnimatedCircularProgress} from 'react-native-circular-progress';
import {getDataById} from '../../utils/excer';
import {observable, computed, action} from 'mobx';
import {observer} from 'mobx-react/native';
import {width} from '../../utils/getSize'
import PropTypes from 'prop-types';
@observer
export default class CircleBox extends Component {
state = {
progress:0
};
@action
animate = () => {
this.setState({progress:0});
clearInterval(this.time);//取消定时器
this.time = setInterval(() => {//启动定时器
this.setState({progress:this.state.progress+100/60});
}, 1000);
};
componentWillMount() {
this.animate();
}
componentWillReceiveProps() {
// this.animate()
}
componentWillUnmount() {
clearInterval(this.time);
}
calcNum = () => {
let num = this.state.progress*60/100;
// console.warn("num = " + num);
if (num < 60) {
return num.toFixed(0) + "s";
} else if(num < 3600){
return (num / 60).toFixed(0) + "m";
}else{
return (num / 3600).toFixed(0) + "h";
}
}
render() {
return (
<View style={{width, height: 130, justifyContent: 'center', alignItems: 'center'}}>
<AnimatedCircularProgress
size={110}
width={4}
fill={this.state.progress%100}
tintColor="#e52d43"
rotation={0}
backgroundColor="#dddddd"
>
{
() => (
<Text style={styles.font}>
{this.calcNum()}
</Text>
)
}
</AnimatedCircularProgress>
</View>
)
}
}
const styles = StyleSheet.create({
font: {
fontSize: 35,
color: '#999999',
textAlign: 'center',
marginTop: -5,
backgroundColor: 'transparent'
}
});