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

@@ -40,7 +40,11 @@ class BrowserViewController: UIViewController,
// Refresh button // Refresh button
toolbarController.urlBar.refreshButton.addAction(UIAction(handler: { action in toolbarController.urlBar.refreshButton.addAction(UIAction(handler: { action in
if webView.isLoading {
webView.stopLoading()
} else {
webView.reload() webView.reload()
}
}), for: .touchUpInside) }), for: .touchUpInside)
// Script button // Script button

View File

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