Skip to content

Commit ff6e246

Browse files
authored
Merge pull request #2 from klaudialax/master
Adjustable size
2 parents 3fd6744 + 98c7ceb commit ff6e246

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ const App = () => {
2727
````
2828

2929
## Props
30-
* percentage (default: 80)
31-
* blankColor (default: "#eaeaea")
30+
* percentage (default: 80)
31+
* blankColor (default: "#eaeaea")
3232
* donutColor (default: "#43cdcf")
3333
* fillColor (default: "white")
3434
* progressWidth (default: 35)
35+
* size (default: 100)

src/CircularProgress.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import {View, StyleSheet} from 'react-native'
33
import Svg, {Path, Circle} from 'react-native-svg'
44

55
const styles = StyleSheet.create({
6-
base: {
7-
width: 100,
8-
height: 100
9-
},
106
textView: {
117
position: 'absolute',
128
top: 0, left: 0, bottom: 0, right: 0,
@@ -15,10 +11,10 @@ const styles = StyleSheet.create({
1511
}
1612
})
1713

18-
function generateArc(percentage){
14+
function generateArc(percentage, radius){
1915
if (percentage === 100) percentage = 99.999
2016
const a = percentage*2*Math.PI/100 // angle (in radian) depends on percentage
21-
const r = 50 // radius of the circle
17+
const r = radius // radius of the circle
2218
var rx = r,
2319
ry = r,
2420
xAxisRotation = 0,
@@ -36,25 +32,27 @@ function generateArc(percentage){
3632
}
3733

3834
const CircularProgress = ({
39-
percentage = 40,
40-
blankColor = "#eaeaea",
35+
percentage = 40,
36+
blankColor = "#eaeaea",
4137
donutColor = "#43cdcf",
4238
fillColor = "white",
4339
progressWidth = 35,
40+
size = 100,
4441
children
4542
}) => {
46-
return <View style={styles.base}>
47-
<Svg width="100" height="100">
48-
<Circle cx="50" cy="50" r="50" fill={blankColor}/>
49-
<Path
50-
d={`M50 50 L50 0 ${generateArc(percentage)} Z`}
43+
let half = size / 2;
44+
return <View style={{width: size, height: size}}>
45+
<Svg width={size} height={size}>
46+
<Circle cx={half} cy={half} r={half} fill={blankColor}/>
47+
<Path
48+
d={`M${half} ${half} L${half} 0 ${generateArc(percentage, half)} Z`}
5149
fill={donutColor}
5250
/>
53-
{<Circle cx="50" cy="50" r={progressWidth} fill={fillColor}/>}
51+
{<Circle cx={half} cy={half} r={progressWidth} fill={fillColor}/>}
5452
</Svg>
5553
<View style={styles.textView}>
5654
{children}
5755
</View>
5856
</View>
5957
}
60-
export default CircularProgress
58+
export default CircularProgress

0 commit comments

Comments
 (0)