Skip to content

Commit

Permalink
🚨 Refactor for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed Apr 11, 2023
1 parent f10cc85 commit 49d8eaa
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,7 @@ private extension UIViewController {
addSubview(imageView)
imageView.center(in: self)
} else {
let blurEffect = UIBlurEffect(style: .systemThinMaterial)
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)

let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
vibrancyEffectView.contentView.addSubview(imageView)
imageView.center(in: vibrancyEffectView.contentView)

let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.layer.cornerRadius = layer.cornerRadius
blurredEffectView.layer.masksToBounds = true
blurredEffectView.isUserInteractionEnabled = false
blurredEffectView.contentView.addSubview(vibrancyEffectView)
vibrancyEffectView.pin(to: blurredEffectView.contentView)

let blurredEffectView = wrapInSystemMaterials(view: imageView)
addSubview(blurredEffectView)
blurredEffectView.pin(to: self)
}
Expand Down Expand Up @@ -228,5 +215,23 @@ private extension UIViewController {
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func wrapInSystemMaterials(view: UIView) -> UIView {
let blurEffect = UIBlurEffect(style: .systemThinMaterial)
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)

let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
vibrancyEffectView.contentView.addSubview(view)
view.center(in: vibrancyEffectView.contentView)

let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.layer.cornerRadius = layer.cornerRadius
blurredEffectView.layer.masksToBounds = true
blurredEffectView.isUserInteractionEnabled = false
blurredEffectView.contentView.addSubview(vibrancyEffectView)
vibrancyEffectView.pin(to: blurredEffectView.contentView)

return blurredEffectView
}
}
}

0 comments on commit 49d8eaa

Please sign in to comment.