Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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()
Comment thread
1998code marked this conversation as resolved.
} 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
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, *) {
Comment thread
1998code marked this conversation as resolved.
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