-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
99 lines (87 loc) · 2.36 KB
/
App.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { Dimensions, Pressable, StyleSheet, Text, View } from "react-native";
import React, { useCallback, useEffect } from "react";
import Svg, { Circle } from "react-native-svg";
import Animated, {
useAnimatedProps,
useDerivedValue,
useSharedValue,
withTiming,
} from "react-native-reanimated";
import { ReText } from "react-native-redash";
const BG_COLOR = "#444B6F";
const BG_STROKE_COLOR = "#303858";
const STROKE_COLOR = "#A6E1FA";
const { width: WIDTH, height: HEIGHT } = Dimensions.get("window");
const CIRCLE_LENGTH = 1000;
const R = CIRCLE_LENGTH / (2 * Math.PI);
const AnimatedCircle = Animated.createAnimatedComponent(Circle);
const App = () => {
const progress = useSharedValue(0);
useEffect(() => {
progress.value = withTiming(1, { duration: 2000 });
}, []);
const animatedProps = useAnimatedProps(() => ({
strokeDashoffset: CIRCLE_LENGTH * (1 - progress.value),
}));
const progressText = useDerivedValue(() => {
return `${Math.floor(progress.value * 100)}`;
});
const onPress = useCallback(() => {
progress.value = withTiming(progress.value > 0 ? 0 : 1, { duration: 2000 });
})
return (
<View style={styles.container}>
<ReText style={styles.text} text={progressText} />
<Svg style={{position:"absolute"}}>
<Circle
cx={WIDTH / 2}
cy={"50%"}
r={R}
stroke={BG_STROKE_COLOR}
strokeWidth={30}
/>
<AnimatedCircle
cx={WIDTH / 2}
cy={"50%"}
r={R}
stroke={STROKE_COLOR}
strokeWidth={15}
strokeDasharray={CIRCLE_LENGTH}
strokeLinecap={"round"}
animatedProps={animatedProps}
/>
</Svg>
<Pressable style={styles.button} onPress={onPress}>
<Text style={styles.buttonText}>Run</Text>
</Pressable>
</View>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex:1,
backgroundColor: BG_COLOR,
alignItems: "center",
justifyContent: "center",
},
text: {
fontSize: 80,
color: "white",
},
button:{
backgroundColor: BG_STROKE_COLOR,
position:"absolute",
width: WIDTH * 0.7,
height: 60,
bottom:40,
borderRadius: 25,
alignItems:"center",
justifyContent:"center"
},
buttonText:{
color:"white",
fontSize: 25,
letterSpacing: 2
}
});