Skip to content

Commit

Permalink
Add custom background support
Browse files Browse the repository at this point in the history
  • Loading branch information
divadretlaw committed Jun 14, 2024
1 parent a1ea8a5 commit 76ec3ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/CustomAlert/Configuration/CustomAlertBackground.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ public enum CustomAlertBackground {
case color(Color)
/// A `UIBlurEffect` as background with a `Color` as background
case colorBlurEffect(Color, UIBlurEffect.Style)
case anyView(AnyView)

public static func view<Content>(@ViewBuilder builder: () -> Content) -> CustomAlertBackground where Content: View {
CustomAlertBackground.anyView(AnyView(builder()))
}

public static func view<Content>(_ view: Content) -> CustomAlertBackground where Content: View {
CustomAlertBackground.anyView(AnyView(view))
}
}
8 changes: 8 additions & 0 deletions Sources/CustomAlert/Views/BackgroundView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct BackgroundView: View {
color
BlurView(style: style)
}
case let .anyView(view):
view
}
}
}
Expand All @@ -30,5 +32,11 @@ struct BackgroundView_Previews: PreviewProvider {
BackgroundView(background: .blurEffect(.regular))
BackgroundView(background: .color(.blue))
BackgroundView(background: .colorBlurEffect(.blue, .regular))
BackgroundView(background: .view {
ZStack {
Color.green
Text("Test")
}
})
}
}

0 comments on commit 76ec3ed

Please sign in to comment.