Stop/reload button

This commit is contained in:
James Magahern
2020-07-28 11:37:10 -07:00
parent 5e80faac62
commit 9f506c879f
2 changed files with 17 additions and 8 deletions

View File

@@ -24,6 +24,9 @@ class URLBar: UIView
private let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial))
private let progressIndicatorView = ProgressIndicatorView()
private let refreshImage = UIImage(systemName: "arrow.clockwise")
private let stopImage = UIImage(systemName: "xmark")
convenience init() {
self.init(frame: .zero)
@@ -48,7 +51,7 @@ class URLBar: UIView
addSubview(textField)
refreshButton.tintColor = .secondaryLabel
refreshButton.setImage(UIImage(systemName: "arrow.clockwise"), for: .normal)
refreshButton.setImage(refreshImage, for: .normal)
addSubview(refreshButton)
}
@@ -56,17 +59,19 @@ class URLBar: UIView
UIView.animate(withDuration: 0.4) {
switch self.loadProgress {
case .complete:
self.refreshButton.setImage(self.refreshImage, for: .normal)
self.progressIndicatorView.progress = 1.0
self.progressIndicatorView.alpha = 0.0
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
}
case .loading(let progress):
self.refreshButton.setImage(self.stopImage, for: .normal)
self.progressIndicatorView.progress = progress
self.progressIndicatorView.alpha = 1.0
}
} completion: { _ in
if case LoadProgress.complete = self.loadProgress {
// Reset back to zero
self.progressIndicatorView.progress = 0.0
}
}
}