|
@@ -7,14 +7,14 @@
|
|
|
|
|
|
|
|
import SwiftUI
|
|
import SwiftUI
|
|
|
|
|
|
|
|
-final class AlertPresenter: ObservableObject {
|
|
|
|
|
|
|
+public final class AlertPresenter: ObservableObject {
|
|
|
|
|
|
|
|
private struct AlertConfiguration {
|
|
private struct AlertConfiguration {
|
|
|
let title: String
|
|
let title: String
|
|
|
let buttons: [AlertButton]
|
|
let buttons: [AlertButton]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- struct AlertButton {
|
|
|
|
|
|
|
+ public struct AlertButton {
|
|
|
let title: String
|
|
let title: String
|
|
|
let role: ButtonRole
|
|
let role: ButtonRole
|
|
|
let action: Action
|
|
let action: Action
|
|
@@ -23,26 +23,28 @@ final class AlertPresenter: ObservableObject {
|
|
|
private var alertConfiguration = AlertConfiguration(title: "", buttons: [])
|
|
private var alertConfiguration = AlertConfiguration(title: "", buttons: [])
|
|
|
|
|
|
|
|
@Published
|
|
@Published
|
|
|
- var isPresenting: Bool = false
|
|
|
|
|
|
|
+ public var isPresenting: Bool = false
|
|
|
|
|
|
|
|
- var title: String {
|
|
|
|
|
|
|
+ public var title: String {
|
|
|
alertConfiguration.title
|
|
alertConfiguration.title
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public init() { }
|
|
|
|
|
+
|
|
|
@ViewBuilder
|
|
@ViewBuilder
|
|
|
- func buildButtons() -> some View {
|
|
|
|
|
|
|
+ public func buildButtons() -> some View {
|
|
|
ForEach(alertConfiguration.buttons.indices) { index in
|
|
ForEach(alertConfiguration.buttons.indices) { index in
|
|
|
let button = self.alertConfiguration.buttons[index]
|
|
let button = self.alertConfiguration.buttons[index]
|
|
|
Button(button.title, role: button.role, action: button.action)
|
|
Button(button.title, role: button.role, action: button.action)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- func showAlert(_ title: String, buttons: [AlertButton]) {
|
|
|
|
|
|
|
+ public func showAlert(_ title: String, buttons: [AlertButton]) {
|
|
|
self.alertConfiguration = AlertConfiguration(title: title, buttons: buttons)
|
|
self.alertConfiguration = AlertConfiguration(title: title, buttons: buttons)
|
|
|
self.isPresenting = true
|
|
self.isPresenting = true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- func showSimpleAlert(_ title: String, action: @escaping Action) {
|
|
|
|
|
|
|
+ public func showSimpleAlert(_ title: String, action: @escaping Action) {
|
|
|
showAlert(title, buttons: [AlertButton(title: "OK", role: .cancel, action: action)])
|
|
showAlert(title, buttons: [AlertButton(title: "OK", role: .cancel, action: action)])
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|