diff --git a/Sources/CustomAlert/API+Bool.swift b/Sources/CustomAlert/API+Bool.swift index 5b03b1d..ea44ca4 100644 --- a/Sources/CustomAlert/API+Bool.swift +++ b/Sources/CustomAlert/API+Bool.swift @@ -1,5 +1,5 @@ // -// API.swift +// API+Bool.swift // CustomAlert // // Created by David Walter on 03.04.22. diff --git a/Sources/CustomAlert/AlertButtonStyle.swift b/Sources/CustomAlert/AlertButtonStyle.swift index 76e078c..77768ab 100644 --- a/Sources/CustomAlert/AlertButtonStyle.swift +++ b/Sources/CustomAlert/AlertButtonStyle.swift @@ -14,10 +14,10 @@ public struct AlertButtonStyle: ButtonStyle { @Environment(\.customAlertConfiguration.button) private var buttonConfiguration @Environment(\.alertDismiss) private var alertDismiss - @Environment(\.isEnabled) var isEnabled - @Environment(\.colorScheme) var colorScheme - @Environment(\.alertButtonHeight) var maxHeight - @Environment(\.window) var window + @Environment(\.isEnabled) private var isEnabled + @Environment(\.colorScheme) private var colorScheme + @Environment(\.alertButtonHeight) private var maxHeight + @Environment(\.window) private var window public func makeBody(configuration: Self.Configuration) -> some View { HStack { @@ -107,16 +107,3 @@ public extension ButtonStyle where Self == AlertButtonStyle { AlertButtonStyle() } } - -private struct AlertButtonHeightKey: EnvironmentKey { - static var defaultValue: CGFloat? { - nil - } -} - -extension EnvironmentValues { - var alertButtonHeight: CGFloat? { - get { self[AlertButtonHeightKey.self] } - set { self[AlertButtonHeightKey.self] = newValue } - } -} diff --git a/Sources/CustomAlert/Environment/Environment+AlertButtonHeight.swift b/Sources/CustomAlert/Environment/Environment+AlertButtonHeight.swift new file mode 100644 index 0000000..3ea81c1 --- /dev/null +++ b/Sources/CustomAlert/Environment/Environment+AlertButtonHeight.swift @@ -0,0 +1,21 @@ +// +// Environment+AlertButtonHeight.swift +// CustomAlert +// +// Created by David Walter on 26.03.24. +// + +import SwiftUI + +private struct AlertButtonHeightKey: EnvironmentKey { + static var defaultValue: CGFloat? { + nil + } +} + +extension EnvironmentValues { + var alertButtonHeight: CGFloat? { + get { self[AlertButtonHeightKey.self] } + set { self[AlertButtonHeightKey.self] = newValue } + } +} diff --git a/Sources/CustomAlert/Envrionment/AlertDismissAction.swift b/Sources/CustomAlert/Environment/Environment+AlertDismissAction.swift similarity index 95% rename from Sources/CustomAlert/Envrionment/AlertDismissAction.swift rename to Sources/CustomAlert/Environment/Environment+AlertDismissAction.swift index 1163944..36b5e6a 100644 --- a/Sources/CustomAlert/Envrionment/AlertDismissAction.swift +++ b/Sources/CustomAlert/Environment/Environment+AlertDismissAction.swift @@ -1,5 +1,5 @@ // -// AlertDismissAction.swift +// Environment+AlertDismissAction.swift // CustomAlert // // Created by David Walter on 25.03.24. diff --git a/Sources/CustomAlert/Envrionment/Environment.swift b/Sources/CustomAlert/Environment/Environment+CustomAlertConfiguration.swift similarity index 50% rename from Sources/CustomAlert/Envrionment/Environment.swift rename to Sources/CustomAlert/Environment/Environment+CustomAlertConfiguration.swift index 36503c4..c1483c0 100644 --- a/Sources/CustomAlert/Envrionment/Environment.swift +++ b/Sources/CustomAlert/Environment/Environment+CustomAlertConfiguration.swift @@ -1,5 +1,5 @@ // -// Environment.swift +// Environment+CustomAlertConfiguration.swift // CustomAlert // // Created by David Walter on 17.10.23. @@ -19,3 +19,14 @@ public extension EnvironmentValues { set { self[CustomAlertConfigurationKey.self] = newValue } } } + +extension View { + /// Create a custom alert configuration + /// + /// - Parameter configure: Callback to change the default configuration + /// + /// - Returns: The view with a customized ``CustomAlertConfiguration`` + func customAlertStyle(style configure: (inout CustomAlertConfiguration) -> Void) -> some View { + environment(\.customAlertConfiguration, .create(configure: configure)) + } +}