Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
divadretlaw committed Mar 26, 2024
1 parent 9423d11 commit 27d0821
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Sources/CustomAlert/API+Bool.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// API.swift
// API+Bool.swift
// CustomAlert
//
// Created by David Walter on 03.04.22.
Expand Down
21 changes: 4 additions & 17 deletions Sources/CustomAlert/AlertButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
}
}
Original file line number Diff line number Diff line change
@@ -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 }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AlertDismissAction.swift
// Environment+AlertDismissAction.swift
// CustomAlert
//
// Created by David Walter on 25.03.24.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Environment.swift
// Environment+CustomAlertConfiguration.swift
// CustomAlert
//
// Created by David Walter on 17.10.23.
Expand All @@ -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))
}
}

0 comments on commit 27d0821

Please sign in to comment.