Skip to content

Commit 5c67cb5

Browse files
patro85patrick-mayoclaude
authored
feat: make the Liquid Glass effect opt-out via AlertStyle (#6)
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#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: gambit1185_church <patrickmayo@churchofjesuschrist.org> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b0c5d8c commit 5c67cb5

2 files changed

Lines changed: 37 additions & 21 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,13 @@ AlertStyle(backgroundColor: Color?,
166166
titleColor: Color?,
167167
subTitleColor: Color?,
168168
titleFont: Font?,
169-
subTitleFont: Font?)
169+
subTitleFont: Font?,
170+
activityIndicatorColor: Color?,
171+
useGlassEffect: Bool?)
170172
```
171173

174+
> **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.
175+
172176
#### Available Alert Types:
173177
- **Regular:** text only (Title and Subtitle).
174178
- **Complete:** animated checkmark.

Sources/AlertToast/AlertToast.swift

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,54 +138,65 @@ public struct AlertToast: View{
138138
subTitleColor: Color? = nil,
139139
titleFont: Font? = nil,
140140
subTitleFont: Font? = nil,
141-
activityIndicatorColor: Color? = nil)
142-
141+
activityIndicatorColor: Color? = nil,
142+
useGlassEffect: Bool? = nil)
143+
143144
///Get background color
144145
var backgroundColor: Color? {
145146
switch self{
146-
case .style(backgroundColor: let color, _, _, _, _, _):
147+
case .style(backgroundColor: let color, _, _, _, _, _, _):
147148
return color
148149
}
149150
}
150-
151+
151152
/// Get title color
152153
var titleColor: Color? {
153154
switch self{
154-
case .style(_,let color, _,_,_,_):
155+
case .style(_,let color, _,_,_,_,_):
155156
return color
156157
}
157158
}
158-
159+
159160
/// Get subTitle color
160161
var subtitleColor: Color? {
161162
switch self{
162-
case .style(_,_, let color, _,_,_):
163+
case .style(_,_, let color, _,_,_,_):
163164
return color
164165
}
165166
}
166-
167+
167168
/// Get title font
168169
var titleFont: Font? {
169170
switch self {
170-
case .style(_, _, _, titleFont: let font, _,_):
171+
case .style(_, _, _, titleFont: let font, _,_,_):
171172
return font
172173
}
173174
}
174-
175+
175176
/// Get subTitle font
176177
var subTitleFont: Font? {
177178
switch self {
178-
case .style(_, _, _, _, subTitleFont: let font,_):
179+
case .style(_, _, _, _, subTitleFont: let font,_,_):
179180
return font
180181
}
181182
}
182183

183184
var activityIndicatorColor: Color? {
184185
switch self {
185-
case .style(_, _, _, _, _, let color):
186+
case .style(_, _, _, _, _, let color, _):
186187
return color
187188
}
188189
}
190+
191+
/// Whether to use the Liquid Glass background on iOS/macOS 26+.
192+
/// `nil` (the default) means glass is used when available; set `false`
193+
/// to always keep the classic solid-color / blur background.
194+
var useGlassEffect: Bool? {
195+
switch self {
196+
case .style(_, _, _, _, _, _, let useGlassEffect):
197+
return useGlassEffect
198+
}
199+
}
189200
}
190201

191202
///The display mode
@@ -274,7 +285,7 @@ public struct AlertToast: View{
274285
.textColor(style?.titleColor ?? nil)
275286
.padding()
276287
.frame(maxWidth: 400, alignment: .leading)
277-
.alertBackground(style?.backgroundColor ?? nil)
288+
.alertBackground(style?.backgroundColor ?? nil, useGlassEffect: style?.useGlassEffect ?? true)
278289
.cornerRadius(10)
279290
.padding([.horizontal, .bottom])
280291
}
@@ -330,7 +341,7 @@ public struct AlertToast: View{
330341
.padding(.horizontal, 24)
331342
.padding(.vertical, 8)
332343
.frame(minHeight: 50)
333-
.alertBackground(style?.backgroundColor ?? nil)
344+
.alertBackground(style?.backgroundColor ?? nil, useGlassEffect: style?.useGlassEffect ?? true)
334345
.clipShape(Capsule())
335346
.overlay(Capsule().stroke(Color.gray.opacity(0.2), lineWidth: 1))
336347
.shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 6)
@@ -396,7 +407,7 @@ public struct AlertToast: View{
396407
}
397408
.padding()
398409
.withFrame(type != .regular && type != .loading)
399-
.alertBackground(style?.backgroundColor ?? nil)
410+
.alertBackground(style?.backgroundColor ?? nil, useGlassEffect: style?.useGlassEffect ?? true)
400411
.cornerRadius(10)
401412
}
402413

@@ -637,12 +648,13 @@ fileprivate struct WithFrameModifier: ViewModifier{
637648
///Fileprivate View Modifier to change the alert background
638649
@available(iOS 14, macOS 11, *)
639650
fileprivate struct BackgroundModifier: ViewModifier{
640-
651+
641652
var color: Color?
642-
653+
var useGlassEffect: Bool = true
654+
643655
@ViewBuilder
644656
func body(content: Content) -> some View {
645-
if #available(iOS 26, macOS 26, *) {
657+
if #available(iOS 26, macOS 26, *), useGlassEffect {
646658
if let color = color {
647659
content
648660
.background(color)
@@ -744,8 +756,8 @@ public extension View{
744756
/// Choose the alert background
745757
/// - Parameter color: Some Color, if `nil` return `VisualEffectBlur`
746758
/// - Returns: some View
747-
fileprivate func alertBackground(_ color: Color? = nil) -> some View{
748-
modifier(BackgroundModifier(color: color))
759+
fileprivate func alertBackground(_ color: Color? = nil, useGlassEffect: Bool = true) -> some View{
760+
modifier(BackgroundModifier(color: color, useGlassEffect: useGlassEffect))
749761
}
750762

751763
/// Choose the alert background

0 commit comments

Comments
 (0)