diff --git a/Demo/Demo/Samples/Essential/Basic.swift b/Demo/Demo/Samples/Essential/Basic.swift index 5935271..792ffe0 100644 --- a/Demo/Demo/Samples/Essential/Basic.swift +++ b/Demo/Demo/Samples/Essential/Basic.swift @@ -46,7 +46,7 @@ struct Basic: View { Text("HOME") .font(.largeTitle) .fontWeight(.heavy) - .foregroundStyle(.primary) + .foregroundStyle(.white) } #if !os(watchOS) diff --git a/Demo/Demo/Samples/Essential/Input.swift b/Demo/Demo/Samples/Essential/Input.swift index 7309232..8393583 100644 --- a/Demo/Demo/Samples/Essential/Input.swift +++ b/Demo/Demo/Samples/Essential/Input.swift @@ -20,7 +20,7 @@ struct Input: View { .textFieldStyle(.plain) .padding(25) .glass( - color: focus ? .accentColor : .primary, + color: focus ? .accentColor : .white, shadowColor: focus ? .accentColor : .primary ) .padding(50) diff --git a/Sources/SwiftGlass/GlassBackgroundModifier.swift b/Sources/SwiftGlass/GlassBackgroundModifier.swift index cbca0c9..81be4ad 100644 --- a/Sources/SwiftGlass/GlassBackgroundModifier.swift +++ b/Sources/SwiftGlass/GlassBackgroundModifier.swift @@ -76,20 +76,51 @@ public struct GlassBackgroundModifier: ViewModifier { /// 2. Gradient stroke for edge highlighting /// 3. Shadow for depth perception public func body(content: Content) -> some View { + #if swift(>=6.0) && canImport(SwiftUI, _version: 6.0) + // Use new glass effect APIs available in newer Xcode/Swift versions if #available(iOS 26.0, macOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) { // Check if content is in a toolbar context if isInToolbar { - content - .tint(color) + AnyView( + content + .tint(color) + ) } else { - content - #if !os(visionOS) - .glassEffect(.regular.tint(color.opacity(colorOpacity)).interactive(), in: .rect(cornerRadius: radius)) - #endif - .cornerRadius(radius) - .shadow(color: shadowColor.opacity(shadowOpacity), radius: shadowRadius, x: shadowX, y: shadowY) + AnyView( + content + #if !os(visionOS) + .glassEffect(.regular.tint(color.opacity(colorOpacity)).interactive(), in: .rect(cornerRadius: radius)) + #else + .background(color.opacity(colorOpacity)) + .background(material) + .cornerRadius(radius) + .overlay( + RoundedRectangle(cornerRadius: radius) + .stroke( + LinearGradient( + gradient: Gradient(colors: gradientColors()), + startPoint: .topLeading, + endPoint: .bottomTrailing + ), + lineWidth: strokeWidth + ) + ) + #endif + .shadow(color: shadowColor.opacity(shadowOpacity), radius: shadowRadius, x: shadowX, y: shadowY) + ) } } else { + AnyView(fallbackGlassEffect(content: content)) + } + #else + // Fallback for older Xcode versions (16.4 and earlier) + AnyView(fallbackGlassEffect(content: content)) + #endif + } + + /// Fallback glass effect implementation for older Xcode versions + private func fallbackGlassEffect(content: Content) -> AnyView { + return AnyView( content .background(color.opacity(colorOpacity)) .background(material) // Use the specified material for the frosted glass base @@ -108,7 +139,7 @@ public struct GlassBackgroundModifier: ViewModifier { ) // Adds shadow for depth and elevation .shadow(color: shadowColor.opacity(shadowOpacity), radius: shadowRadius, x: shadowX, y: shadowY) - } + ) } /// Generates the gradient colors based on the selected style diff --git a/Sources/SwiftGlass/SwiftGlass.swift b/Sources/SwiftGlass/SwiftGlass.swift index cffc1d7..91e1f5e 100644 --- a/Sources/SwiftGlass/SwiftGlass.swift +++ b/Sources/SwiftGlass/SwiftGlass.swift @@ -40,17 +40,7 @@ public extension View { func glass( displayMode: GlassBackgroundModifier.GlassBackgroundDisplayMode = .always, radius: CGFloat = 32, - color: Color = { - #if os(iOS) || os(tvOS) - return Color(UIColor.systemBackground) - #elseif os(watchOS) - return Color(UIColor.black) - #elseif os(macOS) - return Color(NSColor.controlBackgroundColor) - #else - return Color.primary - #endif - }(), + color: Color = .white, colorOpacity: Double = 0.1, material: Material = .ultraThinMaterial, gradientOpacity: Double = 0.5,