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)
} else {
self.background {
ZStack {
if let tintColor = style.getTintColor() {
shape
.fill(
style.tintColor ?? .white
)
.overlay(
.fill(tintColor.opacity(0.8))
} else {
shape
.stroke(
(style.tintColor ?? .white).opacity(0.2),
lineWidth: 1
)
.fill(.ultraThinMaterial)
}
// 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)
}
}
@@ -35,7 +46,7 @@ extension View {
}
struct GlassStyle {
let tintColor: Color?
private let tintColor: Color?
private let isInteractive: Bool
static let regular = GlassStyle(tintColor: nil, isInteractive: false)
@@ -53,6 +64,10 @@ struct GlassStyle {
GlassStyle(tintColor: tintColor, isInteractive: true)
}
func getTintColor() -> Color? {
return tintColor
}
@available(macOS 26.0, *)
func toGlass() -> Glass {
var glass = Glass.regular