Skip to content

Commit 4a29e0a

Browse files
committed
Added missing saturation
1 parent 44e5055 commit 4a29e0a

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var colorTint: UIColor // tint color. default is nil
5050
var colorTintAlpha: CGFloat // tint color alpha. default is 0
5151
var blurRadius: CGFloat // blur radius. default is 0
5252
var scale: CGFloat // scale factor. default is 1
53+
var saturation: CGFloat // saturation factor. default is 1
5354
```
5455

5556
If you want `colorTintAlpha` to be different from `0`, make sure you always set it right after setting the `colorTint` or it may not be applied as expected.

Sources/VisualEffectView/VisualEffectView+SwiftUI.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public struct VisualEffect: UIViewRepresentable {
3737
*/
3838
let blurRadius: CGFloat
3939

40+
/**
41+
The saturation factor.
42+
43+
Values above 1.0 increase saturation, values below 1.0 decrease saturation, and 1.0 maintains original saturation.
44+
45+
The default value is `1.0`.
46+
*/
47+
let saturation: CGFloat
48+
4049
/**
4150
The scale factor for the blur effect.
4251

@@ -51,12 +60,14 @@ public struct VisualEffect: UIViewRepresentable {
5160
- colorTint: The tint color to apply to the blur effect. Defaults to `nil`.
5261
- colorTintAlpha: The alpha component of the tint color. Defaults to `0.0`.
5362
- blurRadius: The radius of the blur effect. Defaults to `0.0`.
63+
- saturation: The saturation adjustment factor. Values above 1.0 increase saturation, values below 1.0 decrease saturation. Defaults to `1.0`.
5464
- scale: The scale factor for the blur effect. Defaults to `1.0`.
5565
*/
56-
public init(colorTint: Color? = nil, colorTintAlpha: CGFloat = 0, blurRadius: CGFloat = 0, scale: CGFloat = 1) {
66+
public init(colorTint: Color? = nil, colorTintAlpha: CGFloat = 0, blurRadius: CGFloat = 0, saturation: CGFloat = 1, scale: CGFloat = 1) {
5767
self.colorTint = colorTint
5868
self.colorTintAlpha = colorTintAlpha
5969
self.blurRadius = blurRadius
70+
self.saturation = saturation
6071
self.scale = scale
6172
}
6273

@@ -69,6 +80,7 @@ public struct VisualEffect: UIViewRepresentable {
6980
}
7081
view.colorTintAlpha = colorTintAlpha
7182
view.blurRadius = blurRadius
83+
view.saturation = saturation
7284
view.scale = scale
7385

7486
return view
@@ -80,6 +92,7 @@ public struct VisualEffect: UIViewRepresentable {
8092
}
8193
uiView.colorTintAlpha = colorTintAlpha
8294
uiView.blurRadius = blurRadius
95+
uiView.saturation = saturation
8396
uiView.scale = scale
8497
}
8598
}
@@ -90,7 +103,7 @@ public struct VisualEffect: UIViewRepresentable {
90103
.frame(width: 400, height: 400)
91104
Color.red
92105
.frame(width: 200, height: 100)
93-
VisualEffect(colorTint: .white, colorTintAlpha: 0.5, blurRadius: 18)
106+
VisualEffect(colorTint: .white, colorTintAlpha: 0.5, blurRadius: 18, saturation: 2.0)
94107
.frame(width: 300, height: 200)
95108
}
96109
}

Sources/VisualEffectView/VisualEffectView.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ open class VisualEffectView: UIVisualEffectView {
6060
}
6161
}
6262

63+
/**
64+
Saturation factor.
65+
66+
Values above 1.0 increase saturation, values below 1.0 decrease saturation, and 1.0 maintains original saturation.
67+
68+
The default value is 1.0.
69+
*/
70+
open var saturation: CGFloat {
71+
get { return _value(forKey: .saturationDeltaFactor) ?? 1.0 }
72+
set { _setValue(newValue, forKey: .saturationDeltaFactor) }
73+
}
74+
6375
/**
6476
Scale factor.
6577

@@ -103,7 +115,7 @@ private extension VisualEffectView {
103115
}
104116

105117
enum Key: String {
106-
case colorTint, colorTintAlpha, blurRadius, scale
118+
case colorTint, colorTintAlpha, blurRadius, saturationDeltaFactor, scale
107119
}
108120

109121
}

0 commit comments

Comments
 (0)