forked from karthikeya1220/HealYou
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularProgress.tsx
More file actions
70 lines (66 loc) · 1.67 KB
/
CircularProgress.tsx
File metadata and controls
70 lines (66 loc) · 1.67 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
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import Svg, { Circle } from 'react-native-svg';
interface CircularProgressProps {
size: number;
progress: number;
strokeWidth: number;
color: string;
backgroundColor?: string;
children?: React.ReactNode;
}
export default function CircularProgress({
size,
progress,
strokeWidth,
color,
backgroundColor = '#F3F4F6',
children
}: CircularProgressProps) {
const radius = (size - strokeWidth) / 2;
const circumference = 2 * Math.PI * radius;
const strokeDasharray = circumference;
const strokeDashoffset = circumference - (progress / 100) * circumference;
return (
<View style={[styles.container, { width: size, height: size }]}>
<Svg width={size} height={size} style={styles.svg}>
<Circle
cx={size / 2}
cy={size / 2}
r={radius}
stroke={backgroundColor}
strokeWidth={strokeWidth}
fill="transparent"
/>
<Circle
cx={size / 2}
cy={size / 2}
r={radius}
stroke={color}
strokeWidth={strokeWidth}
fill="transparent"
strokeDasharray={strokeDasharray}
strokeDashoffset={strokeDashoffset}
strokeLinecap="round"
transform={`rotate(-90 ${size / 2} ${size / 2})`}
/>
</Svg>
<View style={styles.content}>
{children}
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
},
svg: {
position: 'absolute',
},
content: {
justifyContent: 'center',
alignItems: 'center',
},
});