diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index d6de6d3..d65d037 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -10,6 +10,19 @@ on: branches: [ "main" ] jobs: + xcode-26: + runs-on: macos-26 + env: + DEVELOPER_DIR: /Applications/Xcode_26.app/Contents/Developer + steps: + - uses: actions/checkout@v4 + - name: Version + run: swift --version + - name: Build + run: swift build -v + # - name: Test + # run: swift test -v + xcode-16-3: runs-on: macos-15 env: diff --git a/Demo/Demo/Samples/Advanced/GlassFlower/GlassFlower.swift b/Demo/Demo/Samples/Advanced/GlassFlower/GlassFlower.swift index f906ec4..0c1a80d 100644 --- a/Demo/Demo/Samples/Advanced/GlassFlower/GlassFlower.swift +++ b/Demo/Demo/Samples/Advanced/GlassFlower/GlassFlower.swift @@ -43,10 +43,7 @@ struct GlassFlower: View { endPoint: .top ) ) - - // Apply glass effect from SwiftGlass library to create translucent look - .glass() - + .conditionalGlass() .frame(width: 55, height: 100) // Petal dimensions .offset(x: 0, y: 0) // Position petals away from center .rotationEffect(.degrees(Double(index) * 45), anchor: .bottom) // Distribute evenly in 360° (8×45°) diff --git a/Demo/Demo/Samples/Advanced/GlassFlower/GlassFlowerRotate.swift b/Demo/Demo/Samples/Advanced/GlassFlower/GlassFlowerRotate.swift index 72ca85d..88c5b91 100644 --- a/Demo/Demo/Samples/Advanced/GlassFlower/GlassFlowerRotate.swift +++ b/Demo/Demo/Samples/Advanced/GlassFlower/GlassFlowerRotate.swift @@ -47,7 +47,7 @@ struct GlassFlowerRotate: View { ) // Apply glass effect from SwiftGlass library to create translucent look - .glass() + .conditionalGlass() .frame(width: 55, height: 100) // Petal dimensions .offset(x: 0, y: 0) // Position petals away from center diff --git a/Demo/Demo/Samples/Essential/Buttons.swift b/Demo/Demo/Samples/Essential/Buttons.swift index 26dafe2..e072b39 100644 --- a/Demo/Demo/Samples/Essential/Buttons.swift +++ b/Demo/Demo/Samples/Essential/Buttons.swift @@ -16,29 +16,51 @@ struct Buttons: View { #if !os(watchOS) .toolbar { ToolbarItemGroup(placement: .navigationBarLeading) { - Button(action: {}) { - HStack(spacing: 3) { - Image(systemName: "chevron.left") - .font(.caption) - .padding(.leading, 6) - Text("Back") - .bold() - .padding(.trailing, 1.5) + if #available(iOS 26.0, macOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) { + // No need to apply effect + Button(action: {}) { + HStack(spacing: 3) { + Image(systemName: "chevron.left") + .font(.caption) + .padding(.leading, 6) + Text("Back") + .bold() + .padding(.trailing, 8) + } + .padding(.vertical, 2) + .accentColor(.primary) } - .padding(.vertical, 2) - .accentColor(.primary) - }.background(.primary.opacity(0.1)) - .glass(color: .primary, shadowColor: .primary.opacity(0.75)) + } else { + Button(action: {}) { + HStack(spacing: 3) { + Image(systemName: "chevron.left") + .font(.caption) + .padding(.leading, 6) + Text("Back") + .bold() + .padding(.trailing, 1.5) + } + .padding(.vertical, 2) + .accentColor(.primary) + } + .background(.primary.opacity(0.1)) + .glass(color: .primary, shadowColor: .primary.opacity(0.75)) + } } ToolbarItemGroup(placement: .navigationBarTrailing) { - EditButton() - .bold() - .padding(.vertical, 3) - .padding(.leading, 5) - .padding(.trailing, 11.5) - .background(Color.accentColor.opacity(0.1)) - .glass(color: .accentColor, shadowColor: .accentColor) + if #available(iOS 26.0, macOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) { + // No need to apply effect + EditButton() + } else { + EditButton() + .bold() + .padding(.vertical, 3) + .padding(.leading, 5) + .padding(.trailing, 11.5) + .background(Color.accentColor.opacity(0.1)) + .glass(color: .accentColor, shadowColor: .accentColor) + } } } #endif diff --git a/Demo/Demo/Samples/_BlankTemplate.swift b/Demo/Demo/Samples/_BlankTemplate.swift index 75b16b0..beee55f 100644 --- a/Demo/Demo/Samples/_BlankTemplate.swift +++ b/Demo/Demo/Samples/_BlankTemplate.swift @@ -10,12 +10,19 @@ import SwiftGlass struct BlankTemplate: View { var body: some View { - VStack { - Text("Hello, Developer!") + ZStack { + bg + Text("Hello, Developer!") + .bold() .padding(25) .glass() } } + + var bg: some View { + LinearGradient(colors: [Color.clear, Color.pink.opacity(0.85)], startPoint: .topLeading, endPoint: .bottomTrailing) + .ignoresSafeArea() + } } #Preview("Dark") { diff --git a/Sources/SwiftGlass/ConditionGlass.swift b/Sources/SwiftGlass/ConditionGlass.swift new file mode 100644 index 0000000..e4ddbe7 --- /dev/null +++ b/Sources/SwiftGlass/ConditionGlass.swift @@ -0,0 +1,22 @@ +// +// ConditionGlass.swift +// SwiftGlass +// +// Created by Ming on 10/6/2025. +// + +import SwiftUI + +// MARK: - View Extensions + +extension View { + @ViewBuilder + public func conditionalGlass() -> some View { + if #available(iOS 26.0, macOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) { + self + } else { + // Apply glass effect from SwiftGlass library to create translucent look + self.glass() + } + } +} diff --git a/Sources/SwiftGlass/GlassBackgroundModifier.swift b/Sources/SwiftGlass/GlassBackgroundModifier.swift index 520272b..c991e0b 100644 --- a/Sources/SwiftGlass/GlassBackgroundModifier.swift +++ b/Sources/SwiftGlass/GlassBackgroundModifier.swift @@ -70,23 +70,31 @@ public struct GlassBackgroundModifier: ViewModifier { /// 2. Gradient stroke for edge highlighting /// 3. Shadow for depth perception public func body(content: Content) -> some View { - content - .background(material) // Use the specified material for the frosted glass base - .cornerRadius(radius) // Rounds the corners - .overlay( - // Adds subtle gradient border for dimensional effect - RoundedRectangle(cornerRadius: radius) - .stroke( - LinearGradient( - gradient: Gradient(colors: gradientColors()), - startPoint: .topLeading, - endPoint: .bottomTrailing - ), - lineWidth: strokeWidth - ) - ) - // Adds shadow for depth and elevation - .shadow(color: shadowColor.opacity(shadowOpacity), radius: shadowRadius, x: shadowX, y: shadowY) + if #available(iOS 26.0, macOS 26.0, watchOS 26.0, tvOS 26.0, visionOS 26.0, *) { + content + .background(material) + .glassEffect(in: .rect(cornerRadius: radius)) + .cornerRadius(radius) + .shadow(color: shadowColor.opacity(shadowOpacity), radius: shadowRadius, x: shadowX, y: shadowY) + } else { + content + .background(material) // Use the specified material for the frosted glass base + .cornerRadius(radius) // Rounds the corners + .overlay( + // Adds subtle gradient border for dimensional effect + RoundedRectangle(cornerRadius: radius) + .stroke( + LinearGradient( + gradient: Gradient(colors: gradientColors()), + startPoint: .topLeading, + endPoint: .bottomTrailing + ), + lineWidth: strokeWidth + ) + ) + // 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