-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLoadingAnimation.js
134 lines (127 loc) · 3.25 KB
/
LoadingAnimation.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React from "react";
import { Text, View, StatusBar } from "react-native";
import Svg, { Circle } from "react-native-svg";
import { MotiView } from "moti";
function CustomCircle({
radius = 40,
strokeWidth = 4,
color = "#000",
delay = 0
}) {
const circumference = 2 * Math.PI * radius;
const halfCircle = radius + strokeWidth;
const wantedAngle = 60;
const angleInRadians = (wantedAngle * Math.PI) / 180;
const arcLength = radius * angleInRadians;
const strokeDashoffset = circumference - arcLength;
const initialAngle = (180 - wantedAngle) / 2 + wantedAngle;
return (
<MotiView
style={{ width: radius * 2, height: radius * 2, position: "absolute" }}
from={{ rotate: `-${initialAngle}deg` }}
animate={{ rotate: `-${360 + initialAngle}deg` }}
key={Math.random()}
transition={{
repeatReverse: false,
damping: 120,
mass: 2,
loop: true,
duration: 2000,
delay
}}
>
<Svg
width={halfCircle * 2}
height={halfCircle * 2}
viewBox={`0 0 ${halfCircle * 2} ${halfCircle * 2}`}
>
<Circle
cx="50%"
cy="50%"
r={radius}
fill="transparent"
stroke={color}
strokeWidth={strokeWidth}
strokeLinecap="round"
strokeDashoffset={strokeDashoffset}
strokeDasharray={circumference}
></Circle>
</Svg>
</MotiView>
);
}
function LoadingCircles({
size = 30,
count = 3,
frontColor = "#504774",
backColor = "#EF7519",
stagger = 100
}) {
return (
<View>
<View
style={{
alignItems: "center",
justifyContent: "center"
}}
>
{[...Array(count).keys()].map((i) => {
const strokeWidth = Math.floor(size / 3);
const radius = i * strokeWidth * 2 + size;
return (
<CustomCircle
key={`back-${i}`}
radius={radius}
delay={stagger + i * stagger}
color={backColor}
strokeWidth={strokeWidth}
/>
);
})}
</View>
<View style={{ alignItems: "center", justifyContent: "center" }}>
{[...Array(count).keys()].map((i) => {
const strokeWidth = Math.floor(size / 3);
const radius = i * strokeWidth * 2 + size;
return (
<CustomCircle
key={`front-${i}`}
radius={radius}
delay={i * stagger}
color={frontColor}
strokeWidth={strokeWidth}
/>
);
})}
</View>
</View>
);
}
export default function App() {
return (
<View
style={{
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#FAEED6"
}}
>
<StatusBar hidden />
<View style={{ alignItems: "center", justifyContent: "center" }}>
<LoadingCircles size={30} count={3} stagger={100} />
</View>
<Text
style={{
position: "absolute",
bottom: 100,
fontFamily: "Menlo",
opacity: 0.6,
color: "#333"
}}
>
<Text style={{ fontWeight: "900" }}>FatihArslan</Text>
</Text>
</View>
);
}