-
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathAlertKitAPI.swift
More file actions
58 lines (51 loc) · 2.07 KB
/
Copy pathAlertKitAPI.swift
File metadata and controls
58 lines (51 loc) · 2.07 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
import UIKit
public enum AlertKitAPI {
public static func present(view: AlertViewProtocol, completion: @escaping ()->Void = {}) {
guard let window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first else { return }
view.present(on: window, completion: completion)
}
public static func present(title: String? = nil, subtitle: String? = nil, icon: AlertIcon? = nil, style: AlertViewStyle, haptic: AlertHaptic? = nil) {
switch style {
#if os(iOS)
case .iOS16AppleMusic:
guard let window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first else { return }
let view = AlertAppleMusic16View(title: title, subtitle: subtitle, icon: icon)
view.haptic = haptic
view.present(on: window)
#endif
#if os(iOS) || os(visionOS)
case .iOS17AppleMusic:
guard let window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first else { return }
let view = AlertAppleMusic17View(title: title, subtitle: subtitle, icon: icon)
view.haptic = haptic
view.present(on: window)
#endif
}
}
/**
Call only with this one `completion`. Internal ones is canceled.
*/
public static func dismissAllAlerts(completion: (() -> Void)? = nil) {
var alertViews: [AlertViewInternalDismissProtocol] = []
for window in UIApplication.shared.windows {
for view in window.subviews {
if let view = view as? AlertViewInternalDismissProtocol {
alertViews.append(view)
}
}
}
if alertViews.isEmpty {
completion?()
} else {
for (index, view) in alertViews.enumerated() {
if index == .zero {
view.dismiss(customCompletion: {
completion?()
})
} else {
view.dismiss(customCompletion: nil)
}
}
}
}
}