@@ -76,20 +76,51 @@ public struct GlassBackgroundModifier: ViewModifier {
7676 /// 2. Gradient stroke for edge highlighting
7777 /// 3. Shadow for depth perception
7878 public func body( content: Content ) -> some View {
79+ #if swift(>=6.0) && canImport(SwiftUI, _version: 6.0)
80+ // Use new glass effect APIs available in newer Xcode/Swift versions
7981 if #available( iOS 26 . 0 , macOS 26 . 0 , watchOS 26 . 0 , tvOS 26 . 0 , visionOS 26 . 0 , * ) {
8082 // Check if content is in a toolbar context
8183 if isInToolbar {
82- content
83- . tint ( color)
84+ AnyView (
85+ content
86+ . tint ( color)
87+ )
8488 } else {
85- content
86- #if !os(visionOS)
87- . glassEffect( . regular. tint ( color. opacity ( colorOpacity) ) . interactive ( ) , in: . rect( cornerRadius: radius) )
88- #endif
89- . cornerRadius( radius)
90- . shadow ( color: shadowColor. opacity ( shadowOpacity) , radius: shadowRadius, x: shadowX, y: shadowY)
89+ AnyView (
90+ content
91+ #if !os(visionOS)
92+ . glassEffect ( . regular. tint ( color. opacity ( colorOpacity) ) . interactive ( ) , in: . rect( cornerRadius: radius) )
93+ #else
94+ . background ( color. opacity ( colorOpacity) )
95+ . background ( material)
96+ . cornerRadius ( radius)
97+ . overlay (
98+ RoundedRectangle ( cornerRadius: radius)
99+ . stroke (
100+ LinearGradient (
101+ gradient: Gradient ( colors: gradientColors ( ) ) ,
102+ startPoint: . topLeading,
103+ endPoint: . bottomTrailing
104+ ) ,
105+ lineWidth: strokeWidth
106+ )
107+ )
108+ #endif
109+ . shadow ( color: shadowColor. opacity ( shadowOpacity) , radius: shadowRadius, x: shadowX, y: shadowY)
110+ )
91111 }
92112 } else {
113+ AnyView ( fallbackGlassEffect ( content: content) )
114+ }
115+ #else
116+ // Fallback for older Xcode versions (16.4 and earlier)
117+ AnyView ( fallbackGlassEffect ( content: content) )
118+ #endif
119+ }
120+
121+ /// Fallback glass effect implementation for older Xcode versions
122+ private func fallbackGlassEffect( content: Content ) -> AnyView {
123+ return AnyView (
93124 content
94125 . background ( color. opacity ( colorOpacity) )
95126 . background ( material) // Use the specified material for the frosted glass base
@@ -108,7 +139,7 @@ public struct GlassBackgroundModifier: ViewModifier {
108139 )
109140 // Adds shadow for depth and elevation
110141 . shadow ( color: shadowColor. opacity ( shadowOpacity) , radius: shadowRadius, x: shadowX, y: shadowY)
111- }
142+ )
112143 }
113144
114145 /// Generates the gradient colors based on the selected style
0 commit comments