-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathNotificationView.swift
More file actions
85 lines (74 loc) · 2.61 KB
/
NotificationView.swift
File metadata and controls
85 lines (74 loc) · 2.61 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
81
82
83
84
85
import SwiftUI
struct AutoDismissMessage: View {
let message: ToastController.Message
init(message: ToastController.Message) {
self.message = message
}
var body: some View {
message.content
.foregroundColor(.white)
.padding(8)
.background(
message.level.color as Color,
in: RoundedRectangle(cornerRadius: 8)
)
.frame(minWidth: 300)
}
}
public struct NotificationView: View {
let message: ToastController.Message
let onDismiss: () -> Void
public init(
message: ToastController.Message,
onDismiss: @escaping () -> Void = {}
) {
self.message = message
self.onDismiss = onDismiss
}
public var body: some View {
if let notificationTitle = message.title {
VStack(alignment: .leading, spacing: 8) {
HStack(alignment: .center, spacing: 4) {
Image(systemName: message.level.icon)
.foregroundColor(message.level.color)
Text(notificationTitle)
Spacer()
Button(action: onDismiss) {
Image(systemName: "xmark")
.foregroundColor(Color("ToastDismissButtonColor"))
}
.buttonStyle(.plain)
}
HStack(alignment: .bottom, spacing: 1) {
message.content
Spacer()
if let button = message.button {
Button(action: {
button.action()
onDismiss()
}) {
Text(button.title)
.padding(.horizontal, 7)
.padding(.vertical, 3)
.background(Color("ToastActionButtonColor"))
.cornerRadius(5)
}
.buttonStyle(.plain)
}
}
}
.padding(.horizontal, 12)
.padding(.vertical, 16)
.frame(width: 450, alignment: .topLeading)
.background(Color("ToastBackgroundColor"))
.cornerRadius(4)
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(Color("ToastStrokeColor"), lineWidth: 1)
)
} else {
AutoDismissMessage(message: message)
.frame(maxWidth: .infinity)
}
}
}