From d081a1c3f8664c4006716112e82f25f719ff8840 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Tue, 22 Sep 2020 11:27:32 -0700 Subject: [PATCH] Fix progress indicator animation glitch --- App/Titlebar and URL Bar/URLBar.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/App/Titlebar and URL Bar/URLBar.swift b/App/Titlebar and URL Bar/URLBar.swift index ea05e8e..70f097f 100644 --- a/App/Titlebar and URL Bar/URLBar.swift +++ b/App/Titlebar and URL Bar/URLBar.swift @@ -25,9 +25,11 @@ class URLBar: UIView private let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial)) private let shadowView = UIView(frame: .zero) - private let progressIndicatorView = ProgressIndicatorView() private let fadeMaskView = UIImageView(frame: .zero) + private let progressIndicatorView = ProgressIndicatorView() + private var progressIndicatorAnimating = false + private let refreshImage = UIImage(systemName: "arrow.clockwise") private let stopImage = UIImage(systemName: "xmark") @@ -83,16 +85,22 @@ class URLBar: UIView private func updateProgressIndicator() { setErrorButtonAnimating(false) - UIView.animate(withDuration: 0.4) { + if progressIndicatorAnimating { + return + } + + UIView.animate(withDuration: 0.4) { [unowned self] in switch self.loadProgress { case .complete: self.refreshButton.setImage(self.refreshImage, for: .normal) self.progressIndicatorView.progress = 1.0 + self.progressIndicatorAnimating = true UIView.animate(withDuration: 0.5, delay: 0.5, options: AnimationOptions()) { self.progressIndicatorView.alpha = 0.0 } completion: { _ in // Reset back to zero self.progressIndicatorView.progress = 0.0 + self.progressIndicatorAnimating = false } case .loading(let progress):