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

Fix #916: Add pull to refresh #3769

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ extension Strings {
public static let defaultBrowserCalloutCloseAccesabilityLabel =
NSLocalizedString("defaultBrowserCalloutCloseAccesabilityLabel", tableName: "BraveShared",
bundle: .braveShared, value: "Close default browser callout", comment: "")
public static let enablePullToRefresh =
NSLocalizedString("enablePullToRefresh", tableName: "BraveShared",
bundle: .braveShared, value: "Enable Pull-to-refresh", comment: "Describes whether or not the feature that allows the user to pull down from the top of a web page a certain amount before it triggers a page refresh")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this real text value? Enable Pull-to-refresh looks not matching with rest of the options because of dash usage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's real, James proposed it

}

extension Strings {
Expand Down
3 changes: 3 additions & 0 deletions Client/Application/ClientPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ extension Preferences {

/// Whether or not the app (in regular browsing mode) will follow universal links
static let followUniversalLinks = Option<Bool>(key: "general.follow-universal-links", default: true)

/// Whether or not the pull-to-refresh control is added to web views
static let enablePullToRefresh = Option<Bool>(key: "general.enable-pull-to-refresh", default: true)
}

final class DefaultBrowserIntro {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class BrowserViewController: UIViewController {
Preferences.Privacy.privateBrowsingOnly.observe(from: self)
Preferences.General.tabBarVisibility.observe(from: self)
Preferences.General.alwaysRequestDesktopSite.observe(from: self)
Preferences.General.enablePullToRefresh.observe(from: self)
Preferences.Shields.allShields.forEach { $0.observe(from: self) }
Preferences.Privacy.blockAllCookies.observe(from: self)
Preferences.Rewards.hideRewardsIcon.observe(from: self)
Expand Down Expand Up @@ -2149,7 +2150,8 @@ extension BrowserViewController: TabManagerDelegate {

updateFindInPageVisibility(visible: false, tab: previous)
updateTabsBarVisibility()

selected?.updatePullToRefreshVisibility()

topToolbar.locationView.loading = selected?.loading ?? false
navigationToolbar.updateBackStatus(selected?.canGoBack ?? false)
navigationToolbar.updateForwardStatus(selected?.canGoForward ?? false)
Expand Down Expand Up @@ -2745,6 +2747,8 @@ extension BrowserViewController: PreferencesObserver {
case Preferences.General.alwaysRequestDesktopSite.key:
tabManager.reset()
self.tabManager.reloadSelectedTab()
case Preferences.General.enablePullToRefresh.key:
tabManager.selectedTab?.updatePullToRefreshVisibility()
case Preferences.Shields.blockAdsAndTracking.key,
Preferences.Shields.httpsEverywhere.key,
Preferences.Shields.blockScripts.key,
Expand Down
20 changes: 19 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,8 +559,15 @@ class Tab: NSObject {
return
}

updatePullToRefreshVisibility()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we already covering this case inside BVC preferencesDidChange ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this call happens whenever a URL changes in the tab's web view (since we dont want pull to refresh on local pages at all). The BVC pref observation only ensures that it updates any visible tabs refresh control when a user flips that pref on/off


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

func updatePullToRefreshVisibility() {
guard let url = webView?.url, let webView = webView else { return }
webView.scrollView.refreshControl = url.isLocalUtility || !Preferences.General.enablePullToRefresh.value ? nil : refreshControl
}

func isDescendentOf(_ ancestor: Tab) -> Bool {
return sequence(first: parent) { $0?.parent }.contains { $0 == ancestor }
Expand Down
6 changes: 6 additions & 0 deletions Client/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ class SettingsViewController: TableViewController {
}, cellClass: MultilineButtonCell.self))
}

general.rows.append(
.boolRow(title: Strings.enablePullToRefresh,
option: Preferences.General.enablePullToRefresh,
image: #imageLiteral(resourceName: "settings-pull-to-refresh").template)
)

return general
}()

Expand Down