-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathXLike1.swift
65 lines (55 loc) · 2.39 KB
/
XLike1.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
//
// XLike1.swift
// Twitter Like Reaction Animation
//
import SwiftUI
public struct XLike1: View {
public init() {}
@State private var numberOfLikes: Int = 1
@State private var isLiked = false
public var body: some View {
HStack {
Button {
isLiked.toggle()
if isLiked {
numberOfLikes += 1
} else {
numberOfLikes -= 1
}
} label: {
ZStack{
Image(systemName: isLiked ? "heart.fill" : "heart")
.font(isLiked ? .title2 : .title3)
.foregroundColor(Color(isLiked ? .systemPink : .systemGray))
.animation(.interpolatingSpring(stiffness: 170, damping: 15), value: isLiked)
Circle()
.strokeBorder(lineWidth: isLiked ? 0 : 35)
.animation(.easeInOut(duration: 0.5).delay(0.1),value: isLiked)
.frame(width: 70, height: 70, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
.foregroundColor(Color(.systemPink))
.hueRotation(.degrees(isLiked ? 300 : 200))
.scaleEffect(isLiked ? 1.3 : 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.5 : 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.5 : 0)
.animation(.easeOut(duration: 0.5), value: isLiked)
}
}
Text("\(numberOfLikes)")
.foregroundColor(Color(isLiked ? .systemPink : .systemGray))
}
}
}
#Preview {
XLike1()
.preferredColorScheme(.dark)
}