Skip to content

Commit

Permalink
feat(account): update AccountView.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Sep 10, 2024
1 parent 629c156 commit 45a4f5d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 76 deletions.
77 changes: 1 addition & 76 deletions IVPNClient/Scenes/AccountScreen/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,7 @@ class AccountViewController: UITableViewController {
}

@IBAction func toggleAccountHidden(_ sender: Any) {
if accountHidden {
accountView.hideAccountButton.setImage(UIImage.init(systemName: "eye.fill"), for: .normal)
accountView.accountIdLabel.removeBlur()
accountView.accountIdLabel.alpha = 1
accountView.qrCodeImage.removeBlur()
accountView.qrCodeImage.alpha = 1
} else {
accountView.hideAccountButton.setImage(UIImage.init(systemName: "eye.slash.fill"), for: .normal)
accountView.accountIdLabel.addBlur(2)
accountView.accountIdLabel.alpha = 0.7
accountView.qrCodeImage.addBlur(2)
accountView.qrCodeImage.alpha = 0.5
}

accountView.toggleAccountVisibility(hide: accountHidden)
accountHidden = !accountHidden
}

Expand Down Expand Up @@ -238,65 +225,3 @@ extension AccountViewController: JGProgressHUDDelegate {
}

}

class BlurEffectView: UIVisualEffectView {

var animator = UIViewPropertyAnimator(duration: 1, curve: .linear)

var intensity = 1.0

override func layoutSubviews() {
super.layoutSubviews()
frame = superview?.bounds ?? CGRect.zero
setupBlur()
}

override func didMoveToSuperview() {
guard superview != nil else { return }
backgroundColor = .clear
setupBlur()
}

private func setupBlur() {
animator.stopAnimation(true)
effect = nil

animator.addAnimations { [weak self] in
self?.effect = UIBlurEffect(style: .regular)
}

if intensity > 0 && intensity <= 10 {

let value = CGFloat(intensity)/10
animator.fractionComplete = value

}
else {
animator.fractionComplete = 0.05
}

}

deinit {
animator.stopAnimation(true)
}

}

extension UIView {

func addBlur(_ intensity: Double = 1.0) {
let blurEffectView = BlurEffectView()
blurEffectView.intensity = intensity
self.addSubview(blurEffectView)
}

func removeBlur() {
for subview in self.subviews {
if subview is UIVisualEffectView {
subview.removeFromSuperview()
}
}
}

}
16 changes: 16 additions & 0 deletions IVPNClient/Scenes/AccountScreen/View/AccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,20 @@ class AccountView: UITableView {
qrCodeImage.image = UIImage.generateQRCode(from: viewModel.accountId)
}

func toggleAccountVisibility(hide: Bool) {
if hide {
hideAccountButton.setImage(UIImage.init(systemName: "eye.fill"), for: .normal)
accountIdLabel.removeBlur()
accountIdLabel.alpha = 1
qrCodeImage.removeBlur()
qrCodeImage.alpha = 1
} else {
hideAccountButton.setImage(UIImage.init(systemName: "eye.slash.fill"), for: .normal)
accountIdLabel.addBlur(2)
accountIdLabel.alpha = 0.7
qrCodeImage.addBlur(2)
qrCodeImage.alpha = 0.5
}
}

}
62 changes: 62 additions & 0 deletions IVPNClient/Utilities/Extensions/UIView+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,65 @@ extension UIView {
}

}

extension UIView {

func addBlur(_ intensity: Double = 1.0) {
let blurEffectView = BlurEffectView()
blurEffectView.intensity = intensity
self.addSubview(blurEffectView)
}

func removeBlur() {
for subview in self.subviews {
if subview is UIVisualEffectView {
subview.removeFromSuperview()
}
}
}

}

class BlurEffectView: UIVisualEffectView {

var animator = UIViewPropertyAnimator(duration: 1, curve: .linear)

var intensity = 1.0

override func layoutSubviews() {
super.layoutSubviews()
frame = superview?.bounds ?? CGRect.zero
setupBlur()
}

override func didMoveToSuperview() {
guard superview != nil else { return }
backgroundColor = .clear
setupBlur()
}

private func setupBlur() {
animator.stopAnimation(true)
effect = nil

animator.addAnimations { [weak self] in
self?.effect = UIBlurEffect(style: .regular)
}

if intensity > 0 && intensity <= 10 {

let value = CGFloat(intensity)/10
animator.fractionComplete = value

}
else {
animator.fractionComplete = 0.05
}

}

deinit {
animator.stopAnimation(true)
}

}

0 comments on commit 45a4f5d

Please sign in to comment.