-
Notifications
You must be signed in to change notification settings - Fork 240
/
EmotionalReactions.swift
162 lines (145 loc) · 6.65 KB
/
EmotionalReactions.swift
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// EmotionalReactions.swift
import SwiftUI
struct EmotionalReactions: View {
@State private var heartCount = 0
@State private var thumbsUpCount = 0
@State private var thumbsDownCount = 0
@State private var cryCount = 0
@State private var sadCount = 0
@State private var isLoved = false
@State private var isLiked = false
let inboundBubbleColor = Color(#colorLiteral(red: 0.07058823529, green: 0.07843137255, blue: 0.0862745098, alpha: 1))
let reactionsBGColor = Color(#colorLiteral(red: 0.05490196078, green: 0.09019607843, blue: 0.137254902, alpha: 1))
var body: some View {
HStack(spacing: 20) {
Button {
heartCount += 1
withAnimation(.interpolatingSpring(stiffness: 170, damping: 5)) {
isLoved.toggle()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.45) {
withAnimation(.interpolatingSpring(stiffness: 170, damping: 10)) {
isLoved = false
}
}
} label: {
ZStack {
Circle()
.strokeBorder(lineWidth: isLoved ? 0 : 4)
.animation(.easeInOut(duration: 0.5).delay(0.1),value: isLoved)
.frame(width: 70, height: 70)
.foregroundColor(Color(.systemPink))
.hueRotation(.degrees(isLoved ? 300 : 200))
.scaleEffect(isLoved ? 1.15 : 0)
.animation(.easeInOut(duration: 0.5), value: isLoved)
SplashView()
.opacity(isLoved ? 0 : 1)
.animation(.easeInOut(duration: 0.5).delay(0.25), value: isLoved)
.scaleEffect(isLoved ? 1.25 : 0)
.animation(.easeInOut(duration: 0.5), value: isLoved)
SplashView()
.rotationEffect(.degrees(90))
.opacity(isLoved ? 0 : 1)
.offset(y: isLoved ? 6 : -6)
.animation(.easeInOut(duration: 0.5).delay(0.2), value: isLoved)
.scaleEffect(isLoved ? 1.25 : 0)
.animation(.easeOut(duration: 0.5), value: isLoved)
Image(.heart)
.phaseAnimator([false, true], trigger: heartCount) { icon, scaleFromBottom in
icon
.scaleEffect(scaleFromBottom ? 1.5 : 1, anchor: .bottom)
} animation: { scaleFromBottom in
.bouncy(duration: 0.4, extraBounce: 0.4)
}
}
}
Button {
thumbsUpCount += 1
withAnimation(.interpolatingSpring(stiffness: 170, damping: 5)) {
isLiked.toggle()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.45) {
withAnimation(.interpolatingSpring(stiffness: 170, damping: 10)) {
isLiked = false
}
}
} label: {
ZStack {
Circle()
.strokeBorder(lineWidth: isLiked ? 0 : 4)
.animation(.easeInOut(duration: 0.5).delay(0.1),value: isLiked)
.frame(width: 70, height: 70)
.foregroundColor(Color(.systemPink))
.hueRotation(.degrees(isLiked ? 300 : 200))
.scaleEffect(isLiked ? 1.15 : 0)
.animation(.easeInOut(duration: 0.5), value: isLiked)
SplashView()
.opacity(isLiked ? 0 : 1)
.animation(.easeInOut(duration: 0.5).delay(0.25), value: isLiked)
.scaleEffect(isLiked ? 1.25 : 0)
.animation(.easeInOut(duration: 0.5), value: isLiked)
SplashView()
.rotationEffect(.degrees(90))
.opacity(isLiked ? 0 : 1)
.offset(y: isLiked ? 6 : -6)
.animation(.easeInOut(duration: 0.5).delay(0.2), value: isLiked)
.scaleEffect(isLiked ? 1.25 : 0)
.animation(.easeOut(duration: 0.5), value: isLiked)
Image(.thumbup)
.phaseAnimator([false, true], trigger: thumbsUpCount) { icon, scaleRotate in
icon
.rotationEffect(.degrees(scaleRotate ? -45 : 0), anchor: .bottomLeading)
.scaleEffect(scaleRotate ? 1.5 : 1)
} animation: { scaleRotate in
.bouncy(duration: 0.4, extraBounce: 0.4)
}
}
}
Button {
thumbsDownCount += 1
} label: {
Image("thumbdown")
}
.phaseAnimator([false, true], trigger: thumbsDownCount) { icon, dislike in
icon
.rotationEffect(.degrees(dislike ? -45 : 0), anchor: .leading)
.scaleEffect(dislike ? 1.5 : 1)
} animation: { dislike in
.bouncy(duration: 0.2, extraBounce: 0.4)
}
Button {
cryCount += 1
} label: {
Image("crying")
}
.phaseAnimator([false, true], trigger: cryCount) { icon, crying in
icon
.offset(y: crying ? -30 : 0)
.scaleEffect(crying ? 1.5 : 1)
} animation: { crying in
.bouncy(duration: 0.2, extraBounce: 0.4)
}
Button {
sadCount += 1
} label: {
Image("sad")
}
.phaseAnimator([false, true], trigger: sadCount) { icon, sad in
icon
.offset(y: sad ? -30 : 0)
.rotationEffect(.degrees(sad ? 45 : 0))
.scaleEffect(sad ? 1.5 : 1)
} animation: { sad in
.bouncy(duration: 0.2, extraBounce: 0.4)
}
}
.padding()
.background(.quaternary)
.cornerRadius(16)
}
}
#Preview {
EmotionalReactions()
.preferredColorScheme(.dark)
}