-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9fb304
commit f1385f9
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// CustomAlertShadow.swift | ||
// CustomAlert | ||
// | ||
// Created by David Walter on 16.11.24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Shadow configuration of the alert | ||
public struct CustomAlertShadow: Sendable { | ||
let color: Color | ||
let radius: CGFloat | ||
let x: CGFloat | ||
let y: CGFloat | ||
|
||
/// Create a custom alert shadow | ||
/// | ||
/// - Parameters: | ||
/// - color: The shadow's color. | ||
/// - radius: A measure of how much to blur the shadow. Larger values | ||
/// result in more blur. | ||
/// - x: An amount to offset the shadow horizontally from the view. | ||
/// - y: An amount to offset the shadow vertically from the view. | ||
public init( | ||
color: Color = Color(.sRGBLinear, white: 0, opacity: 0.33), | ||
radius: CGFloat, | ||
x: CGFloat = 0, | ||
y: CGFloat = 0 | ||
) { | ||
self.color = color | ||
self.radius = radius | ||
self.x = x | ||
self.y = y | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// ShadowApplier.swift | ||
// CustomAlert | ||
// | ||
// Created by David Walter on 16.11.24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension View { | ||
func shadow(_ shadow: CustomAlertShadow?) -> some View { | ||
modifier(ShadowApplier(shadow: shadow)) | ||
} | ||
} | ||
|
||
private struct ShadowApplier: ViewModifier { | ||
let shadow: CustomAlertShadow? | ||
|
||
func body(content: Content) -> some View { | ||
if let shadow { | ||
content.shadow(color: shadow.color, radius: shadow.radius, x: shadow.x, y: shadow.y) | ||
} else { | ||
content | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters