From 45a4f5de6db10af0c17e32f6f9ae2734398cd1c1 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Tue, 10 Sep 2024 10:46:31 +0200 Subject: [PATCH] feat(account): update AccountView.swift --- .../AccountScreen/AccountViewController.swift | 77 +------------------ .../AccountScreen/View/AccountView.swift | 16 ++++ .../Utilities/Extensions/UIView+Ext.swift | 62 +++++++++++++++ 3 files changed, 79 insertions(+), 76 deletions(-) diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 9ca8c6a14..0168cec15 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -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 } @@ -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() - } - } - } - -} diff --git a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift index a86739d4d..5c6089720 100644 --- a/IVPNClient/Scenes/AccountScreen/View/AccountView.swift +++ b/IVPNClient/Scenes/AccountScreen/View/AccountView.swift @@ -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 + } + } + } diff --git a/IVPNClient/Utilities/Extensions/UIView+Ext.swift b/IVPNClient/Utilities/Extensions/UIView+Ext.swift index b6f721a43..7df47390e 100644 --- a/IVPNClient/Utilities/Extensions/UIView+Ext.swift +++ b/IVPNClient/Utilities/Extensions/UIView+Ext.swift @@ -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) + } + +}