divadretlaw / CustomAlert

🔔 Custom Alert for SwiftUI
MIT License
192 stars 18 forks source link

Core Customization #32

Closed mickeyl closed 1 day ago

mickeyl commented 2 days ago

First off, thanks for working on this package. While you would think an alert view is a trivial thing, it isn't ­– and I have noticed that you did walk the extra mile to provide a drop-in replacement for the built-in alert that looks and feels like the original on all supported platforms.

While that's great (it is!), I wonder how involved it would be to allow for some customisations to the core alert, e.g. in many alert reimplementations I have noticed a slight drop shadow around the edges that makes the view pop more ­– or customize the width (in percentage of the screen width) the alert is allowed to take up.

Update: I have since then found the configuration API, though it doesn't allow for a drop shadow or specifying the minimal width in percentage of screen width.

Update2: So I have found the proper place to get a drop shadow by applying a diff like that:

diff --git a/Sources/CustomAlert/Views/CustomAlert.swift b/Sources/CustomAlert/Views/CustomAlert.swift
index eb439bc..7621bf1 100644
--- a/Sources/CustomAlert/Views/CustomAlert.swift
+++ b/Sources/CustomAlert/Views/CustomAlert.swift
@@ -194,7 +194,7 @@ import SwiftUI
         }
         .frame(minWidth: minWidth, maxWidth: maxWidth)
         .background(BackgroundView(background: configuration.alert.background))
-        .cornerRadius(configuration.alert.cornerRadius)
+        .cornerRadius(configuration.alert.cornerRadius).shadow(radius: 20)
         .padding(configuration.padding)
         .transition(configuration.transition)
         .animation(.default, value: isPresented)

Now this is hardcoded, but it's probably pretty simple to enhance the configuration structure.

divadretlaw commented 1 day ago

Hello, thank you for your suggestion and finding the place where to add it.

I created a custom alert configuration to apply a shadow.

.configureCustomAlert { configuration in
    configuration.alert.shadow = .init(radius: 20)
}

Will be available in 4.0.3