Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the glass modifier’s default styling and extends GlassBackgroundModifier to use new Swift 6 glass APIs while preserving fallbacks for older Xcode versions, and adjusts demo samples for consistent white foreground/background styling.
- Simplified default
colorparameter inglassto.white - Wrapped new SwiftUI 6.0 glass-effect logic behind compiler checks with fallback
- Updated demo views to use
.whiteinstead of.primaryfor visual consistency
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Sources/SwiftGlass/SwiftGlass.swift | Changed default color from platform‐specific to .white |
| Sources/SwiftGlass/GlassBackgroundModifier.swift | Introduced Swift 6 glass APIs under #if checks and maintained fallback implementation |
| Demo/Demo/Samples/Essential/Input.swift | Switched unfocused glass background color from .primary to .white |
| Demo/Demo/Samples/Essential/Basic.swift | Switched Text("HOME") foreground from .primary to .white |
Comments suppressed due to low confidence (3)
Sources/SwiftGlass/SwiftGlass.swift:43
- Changing the default color to
.whiteremoves adaptive background behavior (e.g., dark mode or system background). Consider using a dynamic color or preserving the previous platform‐specific defaults to maintain theming.
color: Color = .white,
Sources/SwiftGlass/GlassBackgroundModifier.swift:113
- The new compiler‐checked branches for Swift 6 and the fallback path aren’t covered by existing tests. Add unit or snapshot tests to verify both the modern glass effect and the fallback implementation.
AnyView(fallbackGlassEffect(content: content))
Demo/Demo/Samples/Essential/Input.swift:23
- [nitpick] Using a solid
.whitebackground might not provide sufficient contrast in all themes or against different content. Verify legibility in both light and dark modes and consider a dynamic or configurable alternative.
color: focus ? .accentColor : .white,
| /// 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) |
There was a problem hiding this comment.
The fallback logic is duplicated in both the #available else branch and the outer compiler #else. Unify these paths by calling fallbackGlassEffect in one place to reduce duplication.
| 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)) |
There was a problem hiding this comment.
Using AnyView for type erasure can degrade SwiftUI performance by preventing view identity optimizations. Consider restructuring the conditional logic with view builders to avoid unnecessary type erasure.
| .font(.largeTitle) | ||
| .fontWeight(.heavy) | ||
| .foregroundStyle(.primary) | ||
| .foregroundStyle(.white) |
There was a problem hiding this comment.
[nitpick] Hardcoding .white as the foreground style may reduce readability on light backgrounds. Consider making this dynamic or theme-aware to ensure adequate contrast.
| .foregroundStyle(.white) | |
| .foregroundStyle(.primary) |
This pull request introduces several changes to the
SwiftGlasslibrary and its demo application, focusing on improving visual consistency and compatibility with newer SwiftUI APIs. The most significant updates include modifying default color values, enhancing theGlassBackgroundModifierfor newer Swift versions, and simplifying fallback implementations for older versions.Visual consistency updates:
Demo/Demo/Samples/Essential/Basic.swift: Changed theforegroundStyleof the "HOME" text from.primaryto.whitefor better visual consistency.Demo/Demo/Samples/Essential/Input.swift: Updated theglassmodifier to use.whiteinstead of.primaryfor the background color when not focused.Compatibility improvements for
SwiftGlass:Sources/SwiftGlass/GlassBackgroundModifier.swift: Enhanced theGlassBackgroundModifierto leverage new glass effect APIs available in Swift 6.0 and newer platforms, while maintaining fallback implementations for older versions. Added support forvisionOSand improved gradient stroke rendering. [1] [2]Sources/SwiftGlass/SwiftGlass.swift: Simplified the defaultcolorparameter in theglassmodifier to.white, removing platform-specific conditional logic.