@@ -3,10 +3,6 @@ import {View, StyleSheet} from 'react-native'
33import Svg , { Path , Circle } from 'react-native-svg'
44
55const 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
3834const 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