Add pull to refresh
This commit is contained in:
parent
86719b4528
commit
e470d7b58e
|
@ -74,6 +74,7 @@ class BrowserWebViewController: UIViewController {
|
|||
// this doesn't default to .default :S
|
||||
webView.scrollView.indicatorStyle = .default
|
||||
webView.scrollView.keyboardDismissMode = .interactive
|
||||
configureWebViewRefreshControl()
|
||||
webView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(webView)
|
||||
NSLayoutConstraint.activate([
|
||||
|
@ -154,14 +155,28 @@ class BrowserWebViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
|
||||
private func configureWebViewRefreshControl(pullToRefreshEnabled: Bool = Preferences.shared.pullToRefreshEnabled) {
|
||||
if pullToRefreshEnabled {
|
||||
let refreshControl = UIRefreshControl()
|
||||
refreshControl.addTarget(navigator, action: #selector(NavigationManager.reload), for: .valueChanged)
|
||||
webView.scrollView.refreshControl = refreshControl
|
||||
} else {
|
||||
webView.scrollView.refreshControl = nil
|
||||
}
|
||||
}
|
||||
|
||||
func reload() {
|
||||
loaded = false
|
||||
loadedFallback = false
|
||||
document = nil
|
||||
loadDocument()
|
||||
loadDocument() {
|
||||
DispatchQueue.main.async {
|
||||
self.webView.scrollView.refreshControl?.endRefreshing()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func loadDocument() {
|
||||
private func loadDocument(completion: (() -> Void)? = nil) {
|
||||
guard !loaded else { return }
|
||||
|
||||
webView.isHidden = true
|
||||
|
@ -207,6 +222,8 @@ class BrowserWebViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
completion?()
|
||||
}
|
||||
if #available(iOS 15.0, *) {
|
||||
task!.attribution = .user
|
||||
|
|
|
@ -49,6 +49,9 @@ class Preferences: Codable, ObservableObject {
|
|||
if let stored = try container.decodeIfPresent(Bool.self, forKey: .hideToolbarsWhenScrolling) {
|
||||
hideToolbarsWhenScrolling = stored
|
||||
}
|
||||
if let stored = try container.decodeIfPresent(Bool.self, forKey: .pullToRefreshEnabled) {
|
||||
pullToRefreshEnabled = stored
|
||||
}
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
|
@ -63,6 +66,7 @@ class Preferences: Codable, ObservableObject {
|
|||
try container.encode(useReaderMode, forKey: .useReaderMode)
|
||||
|
||||
try container.encode(hideToolbarsWhenScrolling, forKey: .hideToolbarsWhenScrolling)
|
||||
try container.encode(pullToRefreshEnabled, forKey: .pullToRefreshEnabled)
|
||||
}
|
||||
|
||||
@Published var homepage = AppDelegate.defaultHomepage
|
||||
|
@ -74,6 +78,7 @@ class Preferences: Codable, ObservableObject {
|
|||
@Published var useReaderMode = false
|
||||
|
||||
@Published var hideToolbarsWhenScrolling = true
|
||||
@Published var pullToRefreshEnabled = true
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case homepage
|
||||
|
@ -85,6 +90,7 @@ class Preferences: Codable, ObservableObject {
|
|||
case useReaderMode
|
||||
|
||||
case hideToolbarsWhenScrolling
|
||||
case pullToRefreshEnabled
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ struct PreferencesView: View {
|
|||
|
||||
private var behaviorSection: some View {
|
||||
Section(header: Text("Behavior")) {
|
||||
Toggle("Pull to Refresh", isOn: $preferences.pullToRefreshEnabled)
|
||||
Toggle("Hide Toolbars When Scrolling", isOn: $preferences.hideToolbarsWhenScrolling)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue