-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathMrsClausView.swift
69 lines (57 loc) · 1.72 KB
/
MrsClausView.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
//
// MrsClausView.swift
// MARK: Here the reaction icons scale up from the bottom and back to the original size
import SwiftUI
// Create a list of steps for the animation
enum MrsClauseScale: CaseIterable {
// Define the phases of the animation
// Initial appearance, move the view up and scale
case initial, move, scale
// Create a computed properties for the effects you want to have
var verticalOffset: Double {
switch self {
case .initial: 0
case .move, .scale: 0.0
}
}
var scale: Double {
switch self {
case .initial: 1
case .move, .scale: 2.0
}
}
var chromaRotate: Double {
switch self {
case .initial: 0.0
case .move, .scale: 225.0
}
}
}
struct MrsClausView: View {
@State private var reactionCount = 0
var body: some View {
HStack {
Text("🤶")
.font(.largeTitle)
.phaseAnimator(
MrsClauseScale.allCases
) { content, phase in
content
.scaleEffect(phase.scale, anchor: .bottom)
.offset(y: phase.verticalOffset)
.hueRotation(.degrees(phase.chromaRotate))
} animation: { phase in
switch phase {
case .initial: .bouncy(duration: 1.5, extraBounce: 0.25)
case .move: .easeInOut(duration: 0.6).delay(0.25)
case .scale: .spring(duration: 1, bounce: 0.7)
}
}
}
}
func nothing() {}
}
#Preview {
MrsClausView()
.preferredColorScheme(.dark)
}