Skip to content

Commit a6ed031

Browse files
committed
Update ContentView.swift
1 parent c1bf56e commit a6ed031

1 file changed

Lines changed: 28 additions & 43 deletions

File tree

Example/ContentView.swift

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -142,58 +142,43 @@ struct ContentView: View {
142142
struct DemoCard: View {
143143
let title: String
144144
let style: VisualEffectView.VisualEffectStyle
145-
let colorTint: Color?
146-
let colorTintAlpha: CGFloat
147-
let blurRadius: CGFloat
148-
let saturation: CGFloat
145+
var colorTint: Color? = nil
146+
var colorTintAlpha: CGFloat = 0
147+
var blurRadius: CGFloat = 0
148+
var saturation: CGFloat = 1
149149
var height: CGFloat = 200
150150

151-
init(
152-
title: String,
153-
style: VisualEffectView.VisualEffectStyle,
154-
colorTint: Color? = nil,
155-
colorTintAlpha: CGFloat = 0,
156-
blurRadius: CGFloat = 0,
157-
saturation: CGFloat = 1,
158-
height: CGFloat = 200
159-
) {
160-
self.title = title
161-
self.style = style
162-
self.colorTint = colorTint
163-
self.colorTintAlpha = colorTintAlpha
164-
self.blurRadius = blurRadius
165-
self.saturation = saturation
166-
self.height = height
151+
private var isCustomBlur: Bool {
152+
if case .customBlur = style { return true }
153+
return false
167154
}
168155

169156
var body: some View {
170157
ZStack {
171-
Group {
172-
if style == .customBlur {
173-
VisualEffect(
174-
colorTint: colorTint,
175-
colorTintAlpha: colorTintAlpha,
176-
blurRadius: blurRadius,
177-
saturation: saturation
178-
)
179-
} else {
180-
VisualEffect(style: style)
181-
}
158+
if isCustomBlur {
159+
VisualEffect(
160+
colorTint: colorTint,
161+
colorTintAlpha: colorTintAlpha,
162+
blurRadius: blurRadius,
163+
saturation: saturation
164+
)
165+
} else {
166+
VisualEffect(style: style)
182167
}
183-
.frame(height: height)
184-
.cornerRadius(20)
185-
.overlay {
186-
VStack(spacing: 8) {
187-
Text(title)
188-
.font(.headline)
189-
if style == .customBlur {
190-
Text("Blur: \(Int(blurRadius))")
191-
.font(.caption)
192-
.foregroundStyle(.secondary)
193-
}
168+
}
169+
.frame(height: height)
170+
.clipShape(RoundedRectangle(cornerRadius: 20))
171+
.overlay {
172+
VStack(spacing: 8) {
173+
Text(title)
174+
.font(.headline)
175+
if isCustomBlur {
176+
Text("Blur: \(Int(blurRadius))")
177+
.font(.caption)
178+
.foregroundStyle(.secondary)
194179
}
195-
.padding()
196180
}
181+
.padding()
197182
}
198183
}
199184
}

0 commit comments

Comments
 (0)