forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandleToast.swift
More file actions
40 lines (35 loc) · 1.21 KB
/
HandleToast.swift
File metadata and controls
40 lines (35 loc) · 1.21 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
import Dependencies
import SwiftUI
import Toast
struct ToastHandler: View {
@ObservedObject var toastController: ToastController
let namespace: String?
init(toastController: ToastController, namespace: String?) {
_toastController = .init(wrappedValue: toastController)
self.namespace = namespace
}
var body: some View {
VStack(spacing: 4) {
ForEach(toastController.messages) { message in
if let n = message.namespace, n != namespace {
EmptyView()
} else {
NotificationView(message: message)
.shadow(color: Color.black.opacity(0.2), radius: 4)
}
}
}
.padding()
.allowsHitTesting(false)
}
}
extension View {
func handleToast(namespace: String? = nil) -> some View {
@Dependency(\.toastController) var toastController
return overlay(alignment: .bottom) {
ToastHandler(toastController: toastController, namespace: namespace)
}.environment(\.toast) { [toastController] content, level in
toastController.toast(content: content, level: level, namespace: namespace)
}
}
}