-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathToastPanelView.swift
More file actions
51 lines (45 loc) · 1.56 KB
/
ToastPanelView.swift
File metadata and controls
51 lines (45 loc) · 1.56 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
import ComposableArchitecture
import Dependencies
import Foundation
import SwiftUI
import Toast
private struct HitTestConfiguration: ViewModifier {
let hitTestPredicate: () -> Bool
func body(content: Content) -> some View {
WithPerceptionTracking {
content.allowsHitTesting(hitTestPredicate())
}
}
}
struct ToastPanelView: View {
let store: StoreOf<ToastPanel>
@Dependency(\.toastController) var toastController
var body: some View {
WithPerceptionTracking {
VStack(spacing: 4) {
if !store.alignTopToAnchor {
Spacer()
.allowsHitTesting(false)
}
ForEach(store.toast.messages) { message in
NotificationView(
message: message,
onDismiss: { toastController.dismissMessage(withId: message.id) }
)
.frame(maxWidth: 450)
// Allow hit testing for notification views
.allowsHitTesting(true)
}
if store.alignTopToAnchor {
Spacer()
.allowsHitTesting(false)
}
}
.colorScheme(store.colorScheme)
.background(Color.clear)
// Only allow hit testing when there are messages
// to prevent the view from blocking the mouse events
.modifier(HitTestConfiguration(hitTestPredicate: { !store.toast.messages.isEmpty }))
}
}
}