-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMascotView.swift
More file actions
80 lines (71 loc) · 2.09 KB
/
Copy pathMascotView.swift
File metadata and controls
80 lines (71 loc) · 2.09 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
71
72
73
74
75
76
77
78
79
80
//
// MascotView.swift
// InstantEnglish
//
// Created on 2024/12/08.
//
import SwiftUI
struct MascotView: View {
var expression: MascotExpression = .happy
var size: CGFloat = 80
var body: some View {
ZStack {
Circle()
.fill(
LinearGradient(
gradient: Gradient(colors: [Color.yellow.opacity(0.3), Color.orange.opacity(0.2)]),
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
.frame(width: size, height: size)
Text(expression.rawValue)
.font(.system(size: size * 0.6))
}
}
}
enum MascotExpression: String {
case happy = "😊"
case excited = "🎉"
case thinking = "🤔"
case celebrating = "🎊"
case encouraging = "💪"
case proud = "😎"
case cheering = "🙌"
case star = "⭐️"
var message: String {
switch self {
case .happy: return "一緒に頑張ろう!"
case .excited: return "やったね!"
case .thinking: return "考えてみよう..."
case .celebrating: return "おめでとう!"
case .encouraging: return "君ならできる!"
case .proud: return "すごいね!"
case .cheering: return "応援してるよ!"
case .star: return "素晴らしい!"
}
}
}
struct AnimatedMascotView: View {
var expression: MascotExpression = .happy
var size: CGFloat = 80
@State private var isAnimating = false
var body: some View {
MascotView(expression: expression, size: size)
.scaleEffect(isAnimating ? 1.1 : 1.0)
.animation(
Animation.easeInOut(duration: 0.6)
.repeatForever(autoreverses: true),
value: isAnimating
)
.onAppear {
isAnimating = true
}
}
}
#Preview {
VStack {
MascotView(expression: .happy)
AnimatedMascotView(expression: .excited)
}
}