-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathWarningState.swift
More file actions
44 lines (35 loc) · 1.12 KB
/
Copy pathWarningState.swift
File metadata and controls
44 lines (35 loc) · 1.12 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
import Foundation
public struct WarningAction: Equatable {
public var title: String
public var url: URL
public init(title: String, url: URL) {
self.title = title
self.url = url
}
}
public struct WarningContent: Equatable {
public var message: String
public var severity: String // "warning" or "info"
public var actions: [WarningAction] // 0-2 CTAs
public init(message: String, severity: String, actions: [WarningAction] = []) {
self.message = message
self.severity = severity
self.actions = actions
}
}
public class WarningStateManager: ObservableObject {
public static let shared = WarningStateManager()
@Published public var currentWarning: WarningContent?
private init() {}
public func setWarning(_ warning: WarningContent) {
DispatchQueue.main.async { [weak self] in
guard self?.currentWarning != warning else { return }
self?.currentWarning = warning
}
}
public func dismissWarning() {
DispatchQueue.main.async { [weak self] in
self?.currentWarning = nil
}
}
}