From 7d312f3a108d5d4e7f2ae17ab28ff7817580e20e Mon Sep 17 00:00:00 2001 From: gambit1185_church Date: Mon, 1 Jun 2026 11:45:19 -0600 Subject: [PATCH] feat: make the Liquid Glass effect opt-out via AlertStyle The glass background (added for iOS/macOS 26) is now controllable through a new `useGlassEffect` parameter on `AlertStyle.style(...)`: - `nil` (default) / `true`: use Liquid Glass when running on iOS/macOS 26+ - `false`: always keep the classic solid-color / BlurView background This lets apps whose design doesn't suit Liquid Glass opt out while keeping glass on by default where available. Addresses the "I'd prefer to have this be optional" feedback on elai950/AlertToast#112. The new associated value defaults to nil, so existing `.style(...)` call sites remain source-compatible. Also refreshed the README AlertStyle reference (it was missing activityIndicatorColor too). Co-Authored-By: Claude Opus 4.8 (1M context) --- README.md | 6 +++- Sources/AlertToast/AlertToast.swift | 52 ++++++++++++++++++----------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index dcae730..40e2559 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Sources/AlertToast/AlertToast.swift b/Sources/AlertToast/AlertToast.swift index 0362fc7..4085781 100644 --- a/Sources/AlertToast/AlertToast.swift +++ b/Sources/AlertToast/AlertToast.swift @@ -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 @@ -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]) } @@ -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) @@ -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) } @@ -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) @@ -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