Skip to content

Instantly share code, notes, and snippets.

@abhi21git
Last active December 11, 2025 13:54
Show Gist options
  • Select an option

  • Save abhi21git/ccf9fc56fe5a5eea109c0c1201009a2b to your computer and use it in GitHub Desktop.

Select an option

Save abhi21git/ccf9fc56fe5a5eea109c0c1201009a2b to your computer and use it in GitHub Desktop.
Check for iOS 26 (can be modified for other versions too) and conditional glass effect to manage backward compatibility.
struct AppConfig {
static var isCompilerAtLeast62: Bool {
#if compiler(>=6.2)
return true
#else
return false
#endif
}
// This will only return true when built from Xcode 26 and for iOS 26 on other version it will return false.
static var isOS26Available: Bool {
#if os(iOS)
if #available(iOS 26.0, *) {
return isCompilerAtLeast62
} else {
return false
}
#elseif os(watchOS)
if #available(watchOS 26.0, *) {
return isCompilerAtLeast62
} else {
return false
}
#endif
}
}
// MARK: - Glass effect
extension View {
@ViewBuilder
func glassEffect<S: Shape, Content: View>(
in shape: S? = nil as Capsule?,
color: Color? = nil,
isInteractive: Bool = false,
fallback transform: (Self) -> Content
) -> some View {
#if compiler(>=6.2)
if #available(iOS 26.0, *) {
applyGlassEffect(shape: shape, color: color, isInteractive: isInteractive)
} else {
applyFallback(shape: shape, transform: transform)
}
#else
applyFallback(shape: shape, transform: transform)
#endif
}
@ViewBuilder
func glassEffect<S: Shape>(
in shape: S? = nil as Circle?,
color: Color? = nil,
isInteractive: Bool = false
) -> some View {
#if compiler(>=6.2)
if #available(iOS 26.0, *) {
applyGlassEffect(shape: shape, color: color, isInteractive: isInteractive)
} else {
applyFallback(shape: shape, transform: { $0 })
}
#else
applyFallback(shape: shape, transform: { $0 })
#endif
}
#if compiler(>=6.2)
@available(iOS 26.0, *)
@ViewBuilder private func applyGlassEffect<S: Shape>(
shape: S?,
color: Color?,
isInteractive: Bool
) -> some View {
let baseStyle = isInteractive ? Glass.regular.interactive() : Glass.regular
let glassStyle = color.map { baseStyle.tint($0) } ?? baseStyle
if let shape {
self.glassEffect(glassStyle, in: shape)
} else {
self.glassEffect(glassStyle)
}
}
#endif
@ViewBuilder
private func applyFallback<S: Shape, Content: View>(
shape: S?,
transform: (Self) -> Content
) -> some View {
if let shape {
transform(self).clipShape(shape)
} else {
transform(self)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment