Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions Demo/Demo/Samples/Advanced/GlassFlower/GlassFlower.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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°)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 41 additions & 19 deletions Demo/Demo/Samples/Essential/Buttons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions Demo/Demo/Samples/_BlankTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
22 changes: 22 additions & 0 deletions Sources/SwiftGlass/ConditionGlass.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
42 changes: 25 additions & 17 deletions Sources/SwiftGlass/GlassBackgroundModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading