forked from oblador/react-native-progress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pie.js
80 lines (72 loc) · 1.58 KB
/
Pie.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
var React = require('react-native');
var {
View,
PropTypes,
ART: {
Surface
}
} = React;
var Circle = require('./Shapes/Circle');
var Sector = require('./Shapes/Sector');
var ProgressPie = React.createClass({
propTypes: {
size: PropTypes.number,
progress: PropTypes.number,
color: PropTypes.string,
unfilledColor: PropTypes.string,
borderWidth: PropTypes.number,
borderColor: PropTypes.string,
},
getDefaultProps: function() {
return {
progress: 0,
size: 40,
borderWidth: 1,
color: 'rgba(0, 122, 255, 1)',
};
},
render() {
var {
progress,
size,
borderWidth,
color,
borderColor,
unfilledColor,
indeterminate,
children,
...props
} = this.props;
var angle = progress * Math.PI * 2;
var radius = size/2 - borderWidth;
var offset = {
top: borderWidth,
left: borderWidth,
};
return (
<View {...props}>
<Surface
width={size}
height={size}>
{unfilledColor ? (<Circle
radius={radius}
offset={offset}
fill={unfilledColor} />) : false}
{angle ? (<Sector
radius={radius}
angle={angle}
offset={offset}
fill={color} />) : false}
{borderWidth ?
(<Circle
radius={size/2}
stroke={borderColor || color}
strokeWidth={borderWidth} />) : false}
</Surface>
{children}
</View>
)
}
});
module.exports = ProgressPie;