Skip to content

Fix crashing on older Xcode#8

Merged
1998code merged 1 commit intomainfrom
7-adding-package-to-other-package
Jun 11, 2025
Merged

Fix crashing on older Xcode#8
1998code merged 1 commit intomainfrom
7-adding-package-to-other-package

Conversation

@1998code
Copy link
Copy Markdown
Owner

This pull request introduces several changes to the SwiftGlass library 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 the GlassBackgroundModifier for newer Swift versions, and simplifying fallback implementations for older versions.

Visual consistency updates:

Compatibility improvements for SwiftGlass:

  • Sources/SwiftGlass/GlassBackgroundModifier.swift: Enhanced the GlassBackgroundModifier to leverage new glass effect APIs available in Swift 6.0 and newer platforms, while maintaining fallback implementations for older versions. Added support for visionOS and improved gradient stroke rendering. [1] [2]
  • Sources/SwiftGlass/SwiftGlass.swift: Simplified the default color parameter in the glass modifier to .white, removing platform-specific conditional logic.

@1998code 1998code requested a review from Copilot June 11, 2025 19:17
@1998code 1998code self-assigned this Jun 11, 2025
@1998code 1998code added the bug Something isn't working label Jun 11, 2025
@1998code 1998code linked an issue Jun 11, 2025 that may be closed by this pull request
@1998code 1998code merged commit 4e7eeeb into main Jun 11, 2025
@1998code 1998code deleted the 7-adding-package-to-other-package branch June 11, 2025 19:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 color parameter in glass to .white
  • Wrapped new SwiftUI 6.0 glass-effect logic behind compiler checks with fallback
  • Updated demo views to use .white instead of .primary for 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 .white removes 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 .white background 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)
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +117
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))
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
.font(.largeTitle)
.fontWeight(.heavy)
.foregroundStyle(.primary)
.foregroundStyle(.white)
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Hardcoding .white as the foreground style may reduce readability on light backgrounds. Consider making this dynamic or theme-aware to ensure adequate contrast.

Suggested change
.foregroundStyle(.white)
.foregroundStyle(.primary)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adding package to other package

2 participants