Skip to content

Commit d7db284

Browse files
authored
Merge pull request #17 from TimOliver/layout-fixes
Made filter recreation happen in each layout pass
2 parents 9fe0278 + 11e23d8 commit d7db284

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

BlurUIKit/UIKit/VariableBlurView.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ public class VariableBlurView: UIView {
137137
// On iOS 17+, use the modern trait change registration
138138
if #available(iOS 17, *) {
139139
registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: VariableBlurView, _: UITraitCollection) in
140-
self.configureView()
141-
self.updateDimmingViewAlpha()
140+
self.setNeedsLayout()
142141
}
143142
}
144143
}
@@ -149,17 +148,16 @@ public class VariableBlurView: UIView {
149148
super.didMoveToSuperview()
150149
configureView()
151150
makeDimmingViewIfNeeded()
152-
updateBlurFilter()
153151
}
154152

155153
public override func layoutSubviews() {
156154
super.layoutSubviews()
157155

158156
blurEffectView.frame = bounds
159-
updateBlurFilter()
160-
161157
dimmingView?.frame = dimmingViewFrame()
158+
162159
updateDimmingViewAlpha()
160+
configureView()
163161

164162
guard needsUpdate else { return }
165163
generateImagesAsNeeded()
@@ -170,8 +168,7 @@ public class VariableBlurView: UIView {
170168
super.traitCollectionDidChange(previousTraitCollection)
171169
// On iOS 17+, trait changes are handled via registerForTraitChanges in commonInit()
172170
if #unavailable(iOS 17) {
173-
configureView()
174-
updateDimmingViewAlpha()
171+
setNeedsLayout()
175172
}
176173
}
177174

@@ -217,7 +214,7 @@ public class VariableBlurView: UIView {
217214

218215
// Update the parameters of the blur filter when the state in this view changes
219216
private func updateBlurFilter() {
220-
guard let variableBlurFilter = BlurFilterProvider.blurFilter(named: "variableBlur") else { return }
217+
guard let gradientMaskImage, let variableBlurFilter = BlurFilterProvider.blurFilter(named: "variableBlur") else { return }
221218
variableBlurFilter.setValue(gradientMaskImage, forKey: "inputMaskImage")
222219
variableBlurFilter.setValue(maximumBlurRadius, forKey: "inputRadius")
223220
variableBlurFilter.setValue(true, forKey: "inputNormalizeEdges")

0 commit comments

Comments
 (0)