Stop/reload button
This commit is contained in:
@@ -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
|
||||||
webView.reload()
|
if webView.isLoading {
|
||||||
|
webView.stopLoading()
|
||||||
|
} else {
|
||||||
|
webView.reload()
|
||||||
|
}
|
||||||
}), for: .touchUpInside)
|
}), for: .touchUpInside)
|
||||||
|
|
||||||
// Script button
|
// Script button
|
||||||
|
|||||||
@@ -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
|
||||||
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):
|
case .loading(let progress):
|
||||||
|
self.refreshButton.setImage(self.stopImage, for: .normal)
|
||||||
self.progressIndicatorView.progress = progress
|
self.progressIndicatorView.progress = progress
|
||||||
self.progressIndicatorView.alpha = 1.0
|
self.progressIndicatorView.alpha = 1.0
|
||||||
}
|
}
|
||||||
} completion: { _ in
|
|
||||||
if case LoadProgress.complete = self.loadProgress {
|
|
||||||
// Reset back to zero
|
|
||||||
self.progressIndicatorView.progress = 0.0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user