glass fallback improved

This commit is contained in:
Michael Freno
2026-01-11 14:31:52 -05:00
parent a627f5b942
commit f5d9b35622

View File

@@ -17,17 +17,28 @@ extension View {
self.glassEffect(style.toGlass(), in: shape) self.glassEffect(style.toGlass(), in: shape)
} else { } else {
self.background { self.background {
ZStack {
if let tintColor = style.getTintColor() {
shape shape
.fill( .fill(tintColor.opacity(0.8))
style.tintColor ?? .white } else {
)
.overlay(
shape shape
.stroke( .fill(.ultraThinMaterial)
(style.tintColor ?? .white).opacity(0.2), }
lineWidth: 1
) // Border with tint color mixed with white
if let tintColor = style.getTintColor() {
shape
.strokeBorder(
Color(
red: (tintColor.cgColor?.components?[0] ?? 1.0) * 0.7 + 0.3,
green: (tintColor.cgColor?.components?[1] ?? 1.0) * 0.7 + 0.3,
blue: (tintColor.cgColor?.components?[2] ?? 1.0) * 0.7 + 0.3
).opacity(0.6),
lineWidth: 1.5
) )
}
}
.shadow(color: .black.opacity(0.1), radius: 4, x: 0, y: 2) .shadow(color: .black.opacity(0.1), radius: 4, x: 0, y: 2)
} }
} }
@@ -35,7 +46,7 @@ extension View {
} }
struct GlassStyle { struct GlassStyle {
let tintColor: Color? private let tintColor: Color?
private let isInteractive: Bool private let isInteractive: Bool
static let regular = GlassStyle(tintColor: nil, isInteractive: false) static let regular = GlassStyle(tintColor: nil, isInteractive: false)
@@ -53,6 +64,10 @@ struct GlassStyle {
GlassStyle(tintColor: tintColor, isInteractive: true) GlassStyle(tintColor: tintColor, isInteractive: true)
} }
func getTintColor() -> Color? {
return tintColor
}
@available(macOS 26.0, *) @available(macOS 26.0, *)
func toGlass() -> Glass { func toGlass() -> Glass {
var glass = Glass.regular var glass = Glass.regular