-
Notifications
You must be signed in to change notification settings - Fork 244
/
IncomingMessageView.swift
81 lines (68 loc) · 3 KB
/
IncomingMessageView.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
//
// IncomingMessage.swift
//
import SwiftUI
struct IncomingMessageView: View {
@State private var transformAndRest = false
@State private var moveBack = true
@State private var reactionIcon = Image(uiImage: #imageLiteral(resourceName: "love"))
@State private var longPressed = false
var body: some View {
VStack {
if longPressed {
ReactionsView()
} else {
EmptyView()
}
HStack(alignment: .bottom) {
Image(.blos)
.resizable()
.frame(width: 32, height: 32)
.clipShape(Circle())
// Chat bubble
ZStack(alignment: .bottomTrailing) {
RoundedRectangle(cornerRadius: 18)
.fill(Color(.systemGray6))
.frame(width: 171, height: 36)
.overlay(Text("Hi Amos, it's Stefan"))
.onTapGesture(count: 2) {
withAnimation(.interpolatingSpring(stiffness: 170, damping: 10).repeatCount(1, autoreverses: true)) {
transformAndRest = true
reactionIcon = Image("thumbsup")
}
withAnimation(.interpolatingSpring(mass: 1 ,stiffness: 170, damping: 15).delay(1)) {
moveBack = false
}
} // Use tap and hold gesture to reveal the reactions
.onLongPressGesture{
longPressed = true
}
// Reactions background
RoundedRectangle(cornerRadius: 12)
.fill(Color(.systemGray6))
.frame(width: 30, height: 24)
.offset(y: 16)
.overlay(
// Reactions border
ZStack {
RoundedRectangle(cornerRadius: 12)
.stroke(lineWidth: 1)
.fill(.quaternary)
.frame(width: 30, height: 24)
.shadow(color: .black, radius: 10, x: 0, y: -5)
.offset(y: 16)
reactionIcon
.scaleEffect(transformAndRest ? 2.5 : 1)
.scaleEffect(moveBack ? 1 : 0.35)
.offset(y: transformAndRest ? -25 : 17)
.offset(y: moveBack ? 0 : 40)
})
}
}
}
}
}
#Preview {
IncomingMessageView()
.preferredColorScheme(.dark)
}