Skip to content

Commit

Permalink
Optionally allow alert to be dismissed on background tap
Browse files Browse the repository at this point in the history
  • Loading branch information
divadretlaw committed Jan 19, 2024
1 parent b9c5ef8 commit 6fe5957
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public struct CustomAlertConfiguration {
public var transition: AnyTransition = .opacity.combined(with: .scale(scale: 1.1))
/// The vertical alginment of the alert
public var alignment: VerticalAlignment = .center
/// Allow dismissing the alert when tapping on the background
public var dismissOnBackgroundTap: Bool = false

/// Create a custom configuration
/// - Parameter configure: Callback to change the default configuration
Expand Down
5 changes: 5 additions & 0 deletions Sources/CustomAlert/Views/CustomAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ struct CustomAlert<Content, Actions>: View where Content: View, Actions: View {
ZStack {
BackgroundView(background: configuration.background)
.edgesIgnoringSafeArea(.all)
.onTapGesture {
if configuration.dismissOnBackgroundTap {
isPresented = false
}
}

VStack(spacing: 0) {
if configuration.alignment.hasTopSpacer {
Expand Down

0 comments on commit 6fe5957

Please sign in to comment.