-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDonut.tsx
70 lines (66 loc) · 1.82 KB
/
Donut.tsx
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, {useState} from 'react';
import {Button, View, StyleSheet} from 'react-native';
import {ReanimatedArc} from './ReanimatedArc';
const generateValues = () => {
const initialRotation = Math.random() * 120 - 60;
const spaceBetweenArcs = 20;
const firstSecondRatio = Math.random() * 75;
const first = {
arc: Math.random() * 50 + firstSecondRatio,
rotation: initialRotation,
};
const second = {
arc: Math.random() * 50 + (150 - firstSecondRatio),
rotation: first.rotation + first.arc + spaceBetweenArcs,
};
const third = {
arc: 360 - second.arc - first.arc - 3 * spaceBetweenArcs,
rotation: second.rotation + second.arc + spaceBetweenArcs,
};
return [first, second, third];
};
const Donut = () => {
const [values, setValues] = useState(generateValues());
const setNewDonut = () => setValues(generateValues());
return (
<View>
<ReanimatedArc
color="#8EA604"
diameter={200}
width={20}
arcSweepAngle={values[0].arc}
lineCap="round"
rotation={values[0].rotation}
initialAnimation={false}
style={{paddingBottom: 20}}
/>
<ReanimatedArc
color="#FB6107"
diameter={200}
width={20}
arcSweepAngle={values[1].arc}
lineCap="round"
rotation={values[1].rotation}
style={styles.absolute}
initialAnimation={false}
/>
<ReanimatedArc
color="#FEC601"
diameter={200}
width={20}
arcSweepAngle={values[2].arc}
lineCap="round"
rotation={values[2].rotation}
style={styles.absolute}
initialAnimation={false}
/>
<Button title="Animate Arc!" onPress={setNewDonut} />
</View>
);
};
const styles = StyleSheet.create({
absolute: {
position: 'absolute',
},
});
export default Donut;