Fix progress indicator animation glitch

This commit is contained in:
James Magahern
2020-09-22 11:27:32 -07:00
parent 55ab759bf7
commit d081a1c3f8

View File

@@ -25,9 +25,11 @@ class URLBar: UIView
private let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial)) private let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial))
private let shadowView = UIView(frame: .zero) private let shadowView = UIView(frame: .zero)
private let progressIndicatorView = ProgressIndicatorView()
private let fadeMaskView = UIImageView(frame: .zero) private let fadeMaskView = UIImageView(frame: .zero)
private let progressIndicatorView = ProgressIndicatorView()
private var progressIndicatorAnimating = false
private let refreshImage = UIImage(systemName: "arrow.clockwise") private let refreshImage = UIImage(systemName: "arrow.clockwise")
private let stopImage = UIImage(systemName: "xmark") private let stopImage = UIImage(systemName: "xmark")
@@ -83,16 +85,22 @@ class URLBar: UIView
private func updateProgressIndicator() { private func updateProgressIndicator() {
setErrorButtonAnimating(false) setErrorButtonAnimating(false)
UIView.animate(withDuration: 0.4) { if progressIndicatorAnimating {
return
}
UIView.animate(withDuration: 0.4) { [unowned self] in
switch self.loadProgress { switch self.loadProgress {
case .complete: case .complete:
self.refreshButton.setImage(self.refreshImage, for: .normal) self.refreshButton.setImage(self.refreshImage, for: .normal)
self.progressIndicatorView.progress = 1.0 self.progressIndicatorView.progress = 1.0
self.progressIndicatorAnimating = true
UIView.animate(withDuration: 0.5, delay: 0.5, options: AnimationOptions()) { UIView.animate(withDuration: 0.5, delay: 0.5, options: AnimationOptions()) {
self.progressIndicatorView.alpha = 0.0 self.progressIndicatorView.alpha = 0.0
} completion: { _ in } completion: { _ in
// Reset back to zero // Reset back to zero
self.progressIndicatorView.progress = 0.0 self.progressIndicatorView.progress = 0.0
self.progressIndicatorAnimating = false
} }
case .loading(let progress): case .loading(let progress):