Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #916: Add pull to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Jun 9, 2021
1 parent 294c87a commit fcac446
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Client/Frontend/Browser/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ class Tab: NSObject {

/// A helper property that handles native to Brave Search communication.
var braveSearchManager: BraveSearchManager?

private lazy var refreshControl = UIRefreshControl().then {
$0.addTarget(self, action: #selector(reload), for: .valueChanged)
}

func createWebview() {
if webView == nil {
Expand Down Expand Up @@ -417,13 +421,20 @@ class Tab: NSObject {
webView?.stopLoading()
}

func reload() {
@objc func reload() {
// Clear the user agent before further navigation.
// Proper User Agent setting happens in BVC's WKNavigationDelegate.
// This prevents a bug with back-forward list, going back or forward and reloading the tab
// loaded wrong user agent.
webView?.customUserAgent = nil

defer {
if let refreshControl = webView?.scrollView.refreshControl,
refreshControl.isRefreshing {
refreshControl.endRefreshing()
}
}

// Refreshing error, safe browsing warning pages.
if let originalUrlFromErrorUrl = webView?.url?.originalURLFromErrorURL {
webView?.load(URLRequest(url: originalUrlFromErrorUrl))
Expand Down Expand Up @@ -548,6 +559,8 @@ class Tab: NSObject {
return
}

webView.scrollView.refreshControl = url.isLocalUtility ? nil : refreshControl

self.urlDidChangeDelegate?.tab(self, urlDidChangeTo: url)
}

Expand Down

0 comments on commit fcac446

Please sign in to comment.