Skip to content

Commit e0871a1

Browse files
committed
Fix Color Opacity
1 parent 7f357a2 commit e0871a1

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

Demo/Demo/Samples/Advanced/GlassFlower/GlassFlower.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct GlassFlower: View {
4545
)
4646

4747
// Apply glass effect from SwiftGlass library to create translucent look
48-
.glass(color: colors[index % colors.count])
48+
.glass(color: colors[index % colors.count], colorOpacity: 1, shadowColor: .white)
4949

5050
.frame(width: 55, height: 100) // Petal dimensions
5151
.offset(x: 0, y: 0) // Position petals away from center

Demo/Demo/Samples/Advanced/GlassFlower/GlassFlowerRotate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct GlassFlowerRotate: View {
4747
)
4848

4949
// Apply glass effect from SwiftGlass library to create translucent look
50-
.glass(color: colors[index % colors.count])
50+
.glass(color: colors[index % colors.count], colorOpacity: 1, shadowColor: .white)
5151

5252
.frame(width: 55, height: 100) // Petal dimensions
5353
.offset(x: 0, y: 0) // Position petals away from center

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ SwiftGlass offers extensive customization options:
126126
| `displayMode` | `.always` or `.automatic` | `.always` | Controls when the effect is displayed |
127127
| `radius` | `CGFloat` | `32` | Corner radius of the glass effect |
128128
| `color` | `Color` | System background color | Base color for gradient and highlights |
129+
| `colorOpacity` | `Double` | `0.1` | Opacity level for the base color |
129130
| `material` | `Material` | `.ultraThinMaterial` | SwiftUI material style |
130131
| `gradientOpacity` | `Double` | `0.5` | Opacity level for the gradient overlay |
131132
| `gradientStyle` | `.normal` or `.reverted` | `.normal` | Direction style of the gradient |

Sources/SwiftGlass/GlassBackgroundModifier.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public struct GlassBackgroundModifier: ViewModifier {
2525
let displayMode: GlassBackgroundDisplayMode
2626
let radius: CGFloat
2727
let color: Color
28+
let colorOpacity: Double
2829
let material: Material
2930
let gradientOpacity: Double
3031
let gradientStyle: GradientStyle
@@ -41,6 +42,7 @@ public struct GlassBackgroundModifier: ViewModifier {
4142
displayMode: GlassBackgroundDisplayMode,
4243
radius: CGFloat,
4344
color: Color,
45+
colorOpacity: Double,
4446
material: Material,
4547
gradientOpacity: Double,
4648
gradientStyle: GradientStyle,
@@ -55,6 +57,7 @@ public struct GlassBackgroundModifier: ViewModifier {
5557
self.displayMode = displayMode
5658
self.radius = radius
5759
self.color = color
60+
self.colorOpacity = colorOpacity
5861
self.material = material
5962
self.gradientOpacity = gradientOpacity
6063
self.gradientStyle = gradientStyle
@@ -80,13 +83,13 @@ public struct GlassBackgroundModifier: ViewModifier {
8083
.tint(color)
8184
} else {
8285
content
83-
.glassEffect(.regular.tint(color.opacity(0.1)).interactive(), in: .rect(cornerRadius: radius))
86+
.glassEffect(.regular.tint(color.opacity(colorOpacity)).interactive(), in: .rect(cornerRadius: radius))
8487
.cornerRadius(radius)
8588
.shadow(color: shadowColor.opacity(shadowOpacity), radius: shadowRadius, x: shadowX, y: shadowY)
8689
}
8790
} else {
8891
content
89-
.background(color.opacity(0.1))
92+
.background(color.opacity(colorOpacity))
9093
.background(material) // Use the specified material for the frosted glass base
9194
.cornerRadius(radius) // Rounds the corners
9295
.overlay(

Sources/SwiftGlass/SwiftGlass.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public extension View {
5151
return Color.primary
5252
#endif
5353
}(),
54+
colorOpacity: Double = 0.1,
5455
material: Material = .ultraThinMaterial,
5556
gradientOpacity: Double = 0.5,
5657
gradientStyle: GlassBackgroundModifier.GradientStyle = .normal,
@@ -81,6 +82,7 @@ public extension View {
8182
displayMode: displayMode,
8283
radius: radius,
8384
color: color,
85+
colorOpacity: colorOpacity,
8486
material: material,
8587
gradientOpacity: gradientOpacity,
8688
gradientStyle: gradientStyle,

0 commit comments

Comments
 (0)