Skip to content

Commit e6b072d

Browse files
committed
Add Glass Option
1 parent d4aaf80 commit e6b072d

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Demo/What's New?/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct ContentView : View {
2424
@Previewable @State var showNew: Bool = false
2525
List {
2626
Section(header: Text("Compatible with Toolbar / List")) {
27-
SwiftNEW(show: $showNew, size: .constant("mini"))
27+
SwiftNEW(show: $showNew, size: .constant("mini"), glass: .constant(false))
2828
}
2929
}
3030
}

Sources/SwiftNEW/SwiftNEW.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import SwiftUI
99
import SwiftVB
10-
import SwiftGlass
1110

1211
#if os(iOS)
1312
import Drops
@@ -34,6 +33,7 @@ public struct SwiftNEW: View {
3433
@Binding var showDrop: Bool
3534
@Binding var mesh: Bool
3635
@Binding var specialEffect: String
36+
@Binding var glass: Bool
3737

3838
#if os(iOS) || os(visionOS)
3939
public init(
@@ -48,7 +48,8 @@ public struct SwiftNEW: View {
4848
data: Binding<String>? = .constant("data"),
4949
showDrop: Binding<Bool>? = .constant(false),
5050
mesh: Binding<Bool>? = .constant(true),
51-
specialEffect: Binding<String>? = .constant("")
51+
specialEffect: Binding<String>? = .constant(""),
52+
glass: Binding<Bool>? = .constant(true)
5253
) {
5354
_show = show
5455
_align = align ?? .constant(.center)
@@ -62,6 +63,7 @@ public struct SwiftNEW: View {
6263
_showDrop = showDrop ?? .constant(false)
6364
_mesh = mesh ?? .constant(true)
6465
_specialEffect = specialEffect ?? .constant("")
66+
_glass = glass ?? .constant(true)
6567
compareVersion()
6668
}
6769
#elseif os(macOS)
@@ -77,7 +79,8 @@ public struct SwiftNEW: View {
7779
data: Binding<String>? = .constant("data"),
7880
showDrop: Binding<Bool>? = .constant(false),
7981
mesh: Binding<Bool>? = .constant(true),
80-
specialEffect: Binding<String>? = .constant("")
82+
specialEffect: Binding<String>? = .constant(""),
83+
glass: Binding<Bool>? = .constant(true)
8184
) {
8285
_show = show
8386
_align = align ?? .constant(.center)
@@ -91,6 +94,7 @@ public struct SwiftNEW: View {
9194
_showDrop = showDrop ?? .constant(false)
9295
_mesh = mesh ?? .constant(true)
9396
_specialEffect = specialEffect ?? .constant("")
97+
_glass = glass ?? .constant(true)
9498
compareVersion()
9599
}
96100
#else
@@ -106,7 +110,8 @@ public struct SwiftNEW: View {
106110
data: Binding<String>? = .constant("data"),
107111
showDrop: Binding<Bool>? = .constant(false),
108112
mesh: Binding<Bool>? = .constant(true),
109-
specialEffect: Binding<String>? = .constant("")
113+
specialEffect: Binding<String>? = .constant(""),
114+
glass: Binding<Bool>? = .constant(true)
110115
) {
111116
_show = show
112117
_align = align ?? .constant(.center)
@@ -120,6 +125,7 @@ public struct SwiftNEW: View {
120125
_showDrop = showDrop ?? .constant(false)
121126
_mesh = mesh ?? .constant(true)
122127
_specialEffect = specialEffect ?? .constant("")
128+
_glass = glass ?? .constant(true)
123129
compareVersion()
124130
}
125131
#endif

Sources/SwiftNEW/Views/SwiftNEW+View.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension SwiftNEW {
3939
#endif
4040
}
4141
.opacity(size == "invisible" ? 0 : 1)
42-
.glass(shadowColor: color)
42+
.modifier(ConditionalGlassModifier(isEnabled: glass, shadowColor: color))
4343
.sheet(isPresented: $show) {
4444
sheetContent
4545
}
@@ -100,3 +100,16 @@ private struct PresentationBackgroundModifier: ViewModifier {
100100
}
101101
}
102102
}
103+
104+
private struct ConditionalGlassModifier: ViewModifier {
105+
let isEnabled: Bool
106+
let shadowColor: Color
107+
108+
func body(content: Content) -> some View {
109+
if isEnabled {
110+
content.glass(shadowColor: shadowColor)
111+
} else {
112+
content
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)