Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,13 @@ AlertStyle(backgroundColor: Color?,
titleColor: Color?,
subTitleColor: Color?,
titleFont: Font?,
subTitleFont: Font?)
subTitleFont: Font?,
activityIndicatorColor: Color?,
useGlassEffect: Bool?)
```

> **Liquid Glass:** on iOS 26 / macOS 26+ the toast background uses the native Liquid Glass material by default. To keep the classic solid-color / blur background, pass `useGlassEffect: false` in the style.

#### Available Alert Types:
- **Regular:** text only (Title and Subtitle).
- **Complete:** animated checkmark.
Expand Down
52 changes: 32 additions & 20 deletions Sources/AlertToast/AlertToast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,54 +138,65 @@ public struct AlertToast: View{
subTitleColor: Color? = nil,
titleFont: Font? = nil,
subTitleFont: Font? = nil,
activityIndicatorColor: Color? = nil)

activityIndicatorColor: Color? = nil,
useGlassEffect: Bool? = nil)

///Get background color
var backgroundColor: Color? {
switch self{
case .style(backgroundColor: let color, _, _, _, _, _):
case .style(backgroundColor: let color, _, _, _, _, _, _):
return color
}
}

/// Get title color
var titleColor: Color? {
switch self{
case .style(_,let color, _,_,_,_):
case .style(_,let color, _,_,_,_,_):
return color
}
}

/// Get subTitle color
var subtitleColor: Color? {
switch self{
case .style(_,_, let color, _,_,_):
case .style(_,_, let color, _,_,_,_):
return color
}
}

/// Get title font
var titleFont: Font? {
switch self {
case .style(_, _, _, titleFont: let font, _,_):
case .style(_, _, _, titleFont: let font, _,_,_):
return font
}
}

/// Get subTitle font
var subTitleFont: Font? {
switch self {
case .style(_, _, _, _, subTitleFont: let font,_):
case .style(_, _, _, _, subTitleFont: let font,_,_):
return font
}
}

var activityIndicatorColor: Color? {
switch self {
case .style(_, _, _, _, _, let color):
case .style(_, _, _, _, _, let color, _):
return color
}
}

/// Whether to use the Liquid Glass background on iOS/macOS 26+.
/// `nil` (the default) means glass is used when available; set `false`
/// to always keep the classic solid-color / blur background.
var useGlassEffect: Bool? {
switch self {
case .style(_, _, _, _, _, _, let useGlassEffect):
return useGlassEffect
}
}
}

///The display mode
Expand Down Expand Up @@ -274,7 +285,7 @@ public struct AlertToast: View{
.textColor(style?.titleColor ?? nil)
.padding()
.frame(maxWidth: 400, alignment: .leading)
.alertBackground(style?.backgroundColor ?? nil)
.alertBackground(style?.backgroundColor ?? nil, useGlassEffect: style?.useGlassEffect ?? true)
.cornerRadius(10)
.padding([.horizontal, .bottom])
}
Expand Down Expand Up @@ -330,7 +341,7 @@ public struct AlertToast: View{
.padding(.horizontal, 24)
.padding(.vertical, 8)
.frame(minHeight: 50)
.alertBackground(style?.backgroundColor ?? nil)
.alertBackground(style?.backgroundColor ?? nil, useGlassEffect: style?.useGlassEffect ?? true)
.clipShape(Capsule())
.overlay(Capsule().stroke(Color.gray.opacity(0.2), lineWidth: 1))
.shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 6)
Expand Down Expand Up @@ -396,7 +407,7 @@ public struct AlertToast: View{
}
.padding()
.withFrame(type != .regular && type != .loading)
.alertBackground(style?.backgroundColor ?? nil)
.alertBackground(style?.backgroundColor ?? nil, useGlassEffect: style?.useGlassEffect ?? true)
.cornerRadius(10)
}

Expand Down Expand Up @@ -637,12 +648,13 @@ fileprivate struct WithFrameModifier: ViewModifier{
///Fileprivate View Modifier to change the alert background
@available(iOS 14, macOS 11, *)
fileprivate struct BackgroundModifier: ViewModifier{

var color: Color?

var useGlassEffect: Bool = true

@ViewBuilder
func body(content: Content) -> some View {
if #available(iOS 26, macOS 26, *) {
if #available(iOS 26, macOS 26, *), useGlassEffect {
if let color = color {
content
.background(color)
Expand Down Expand Up @@ -744,8 +756,8 @@ public extension View{
/// Choose the alert background
/// - Parameter color: Some Color, if `nil` return `VisualEffectBlur`
/// - Returns: some View
fileprivate func alertBackground(_ color: Color? = nil) -> some View{
modifier(BackgroundModifier(color: color))
fileprivate func alertBackground(_ color: Color? = nil, useGlassEffect: Bool = true) -> some View{
modifier(BackgroundModifier(color: color, useGlassEffect: useGlassEffect))
}

/// Choose the alert background
Expand Down