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

New Tab Page & Favicons Refactor #2490

Merged
merged 64 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6ebf1a4
WIP: New Tab Page Refactor
kylehickinson Apr 14, 2020
531d6d3
iOS 12 long-press support
kylehickinson Apr 28, 2020
8277ec8
Share favourites count logic for overflow section + small feedback fixes
kylehickinson Apr 29, 2020
1fd02b0
WIP: Favorites overlay
kylehickinson Apr 29, 2020
bf2b452
Merge development into new-tab-page-refactor
kylehickinson Apr 30, 2020
2e1e4a5
Support for custom themes changes & merge fixes
kylehickinson Apr 30, 2020
e8acd37
Fix background focal point calculation offsets
kylehickinson May 1, 2020
e3aaf3a
Fix crash if NTP section updates before dataSource is setup
kylehickinson May 1, 2020
83b074d
Don't log warning about Rewards favicon on for local pages
kylehickinson May 1, 2020
b892d9a
Anchor favorites overlay & NTP to layout guide
kylehickinson May 2, 2020
cc7bc2a
Add drag & drop reorder to favorites overlay
kylehickinson May 2, 2020
7bec53a
Remove animation for hiding NTP;
kylehickinson May 2, 2020
9b4b78d
Add interactive keyboard dismiss to fav overlay
kylehickinson May 2, 2020
d2e13f5
Fix height of favs on NTP
kylehickinson May 4, 2020
94c8367
Finish up favourites reordering
kylehickinson May 4, 2020
67e7915
Move NTP to Tab
kylehickinson May 5, 2020
02815f4
Show correct favicon on tab tray for NTP
kylehickinson May 5, 2020
1004913
Cleanup & remove old FavoritesViewController
kylehickinson May 5, 2020
e7d6502
Rename favorites view controller
kylehickinson May 5, 2020
77cf228
Favorites overlay now hides toolbar
kylehickinson May 6, 2020
bbcd23a
Fix NTP Memory Leak
kylehickinson May 6, 2020
08e7e12
Fix bug where an NTP would remain in view hierarchy when switching modes
kylehickinson May 6, 2020
421bd41
Don't reset background image when switching private modes
kylehickinson May 6, 2020
0531815
Update NTP favicon layout to look better on iPad portrait & multitasking
kylehickinson May 6, 2020
92e7d2b
Adjust favorite cell pointer interaction
kylehickinson May 6, 2020
4a74de7
Add FRC batch updates for favs overlay
kylehickinson May 7, 2020
7972a52
Remove favs data source & old favs tests
kylehickinson May 7, 2020
ac0ed58
WIP: Favicon fetching improvements
kylehickinson May 8, 2020
94bf66b
Merge development into new-tab-page-refactor
kylehickinson May 19, 2020
0fa3112
Fix background colors on default favicons
kylehickinson May 19, 2020
3939a38
More favicon fixes
kylehickinson May 19, 2020
168d8a1
Fix browser tray animations
kylehickinson May 19, 2020
9363ff3
Dump NTP's from Tabs when receiving a memory warning
kylehickinson May 19, 2020
c8856f2
Use monogram fallback on smaller images as well (bookmark, history, e…
kylehickinson May 19, 2020
271503c
Rename `NewFaviconFetcher` back to `FaviconFetcher`
kylehickinson May 19, 2020
90e08ce
Unify monogram fallback character selection
kylehickinson May 19, 2020
3d8456c
Fix UITableViewCell image shenanigans
kylehickinson May 20, 2020
dd80966
Fix #2516: Dismiss NTP SI notification when SI/backgrounds are disabled
kylehickinson May 20, 2020
33eb65d
Fix unit tests
kylehickinson May 20, 2020
ffa3e33
Fix issue that could overwrite FaviconMO's when downloading stored icons
kylehickinson May 21, 2020
9beddbf
Move SI/QR code on landscape to bottom left instead of centered on iPad
kylehickinson May 21, 2020
6a9f8fb
Fix Domain grabbing for add bookmarks UI
kylehickinson May 21, 2020
0de8abf
Fix order of favorites after more than 10 favs are added
kylehickinson May 21, 2020
9b9088a
Fix reorder favs drag & drop animations
kylehickinson May 21, 2020
ea14774
Merge development into new-tab-page-refactor
kylehickinson May 25, 2020
5a797e3
Fix favicons on Rewards UI
kylehickinson May 25, 2020
6d970f6
Restrict drag & drop to Brave
kylehickinson May 25, 2020
52e3597
Add whitespace between functions in NTP section providers
kylehickinson May 25, 2020
6eaa3f1
Add some documentation & cleanup.
kylehickinson May 26, 2020
5eeaf8d
Adjust the DDG callout top section inset to account for smaller devices
kylehickinson May 26, 2020
459ad04
Remove redundant check for URL on favicon image view extension
kylehickinson May 26, 2020
b459c5a
Fix favorites overlay text color on dark themes in iOS 12
kylehickinson May 26, 2020
dd3cd33
Merge development into new-tab-page-refactor
kylehickinson May 26, 2020
d8c1767
Consolidate monogram letter logic
kylehickinson May 26, 2020
aa60e3f
Consolidate handling bookmark actions logic
kylehickinson May 26, 2020
3d7c870
Add additional documentation in favicon fetcher
kylehickinson May 26, 2020
070d693
Remove code that deletes all Domain's regardless of Bookmark association
kylehickinson May 27, 2020
52ddef0
Fix monogram appearing on top of folders when scrolling in Bookmarks
kylehickinson May 28, 2020
190260f
Ensure monogram favicons are cleared before resetting image
kylehickinson May 28, 2020
b5a0d62
Fully-clear monogram favicons at start of favicon load
kylehickinson May 28, 2020
39e855c
Merge development into new-tab-page-refactor
kylehickinson May 29, 2020
994c3cc
Fix favorites bleeding under safe area (and padding on bg buttons)
kylehickinson Jun 4, 2020
dfaa3b5
Fix issue where fresh install would not show favourites overflow
kylehickinson Jun 4, 2020
b388de3
Also pull precomposed apple-touch-icon's during metadata parse
kylehickinson Jun 5, 2020
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
7 changes: 6 additions & 1 deletion BraveRewardsUI/Common/PublisherIconCircleImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import BraveUI

class PublisherIconCircleImageView: UIView {

private var imageView = UIImageView()
private(set) var imageView = UIImageView()
private var backgroundColorObserver: NSKeyValueObservation?

init(size: CGFloat, inset: CGFloat = 7.0) {
super.init(frame: .zero)
Expand All @@ -33,6 +34,10 @@ class PublisherIconCircleImageView: UIView {
$0.borderColor = Colors.neutral100.cgColor
$0.borderWidth = 1.0 / UIScreen.main.scale
}

backgroundColorObserver = imageView.observe(\.backgroundColor, options: [.initial, .new], changeHandler: { [weak self] imageView, _ in
self?.backgroundColor = imageView.backgroundColor ?? .white
kylehickinson marked this conversation as resolved.
Show resolved Hide resolved
})
}

@available(*, unavailable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PendingContributionCell: UITableViewCell, TableViewReusable {

private let siteStackView = UIStackView()

let siteImageView = PublisherIconCircleImageView(size: 28)
let siteImageView = PublisherIconCircleImageView(size: 28, inset: 4)

let verifiedStatusImageView = UIImageView(image: UIImage(frameworkResourceNamed: "icn-verify")).then {
$0.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ extension PendingContributionListController: UITableViewDataSource {
cell.accessoryType = .disclosureIndicator

if let url = URL(string: contribution.url) {
state.dataSource?.retrieveFavicon(for: url, faviconURL: URL(string: contribution.faviconUrl)) { data in
cell.siteImageView.image = data?.image ?? UIImage(frameworkResourceNamed: "defaultFavicon")
cell.siteImageView.backgroundColor = data?.backgroundColor
}
state.dataSource?.retrieveFavicon(for: url, on: cell.siteImageView.imageView)
}

cell.verifiedStatusImageView.isHidden = contribution.status == .notVerified
Expand Down
3 changes: 1 addition & 2 deletions BraveRewardsUI/RewardsDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public protocol RewardsDataSource: AnyObject {
///
/// Execute completionBlock with FaviconData
func retrieveFavicon(for pageURL: URL,
faviconURL: URL?,
completion: @escaping (FaviconData?) -> Void)
on imageView: UIImageView)

/// Get the page HTML for the given tab id if its available
func pageHTML(for tabId: UInt64, completionHandler: @escaping (String?) -> Void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ extension AutoContributeExclusionListController: UITableViewDataSource {
}
let cell = tableView.dequeueReusableCell(for: indexPath) as ExclusionListCell
if let url = URL(string: publisher.url) {
state.dataSource?.retrieveFavicon(for: url, faviconURL: URL(string: publisher.faviconUrl)) { data in
cell.siteImageView.image = data?.image ?? UIImage(frameworkResourceNamed: "defaultFavicon")
cell.siteImageView.backgroundColor = data?.backgroundColor
}
state.dataSource?.retrieveFavicon(for: url, on: cell.siteImageView.imageView)
}

cell.verifiedStatusImageView.isHidden = publisher.status == .notVerified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ExclusionListCell: UITableViewCell, TableViewReusable {

private let siteStackView = UIStackView()

let siteImageView = PublisherIconCircleImageView(size: 28)
let siteImageView = PublisherIconCircleImageView(size: 28, inset: 4)

let verifiedStatusImageView = UIImageView(image: UIImage(frameworkResourceNamed: "icn-verify")).then {
$0.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AutoContributeCell: UITableViewCell, TableViewReusable {
$0.backgroundColor = Colors.blurple100
}

let siteImageView = PublisherIconCircleImageView(size: 28)
let siteImageView = PublisherIconCircleImageView(size: 28, inset: 4)

let verifiedStatusImageView = UIImageView(image: UIImage(frameworkResourceNamed: "icn-verify")).then {
$0.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ extension AutoContributeSupportedListController: UITableViewDataSource {
}
let cell = tableView.dequeueReusableCell(for: indexPath) as AutoContributeCell
if let url = URL(string: publisher.url) {
state.dataSource?.retrieveFavicon(for: url, faviconURL: URL(string: publisher.faviconUrl)) { data in
cell.siteImageView.image = data?.image ?? UIImage(frameworkResourceNamed: "defaultFavicon")
cell.siteImageView.backgroundColor = data?.backgroundColor
}
state.dataSource?.retrieveFavicon(for: url, on: cell.siteImageView.imageView)
}

cell.verifiedStatusImageView.isHidden = publisher.status == .notVerified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ extension MonthlyTipsDetailViewController: UITableViewDataSource {
cell.siteNameLabel.attributedText = attrName
cell.siteImageView.image = UIImage(frameworkResourceNamed: "defaultFavicon")
if let url = URL(string: publisher.url) {
state.dataSource?.retrieveFavicon(for: url, faviconURL: URL(string: publisher.faviconUrl)) { data in
cell.siteImageView.image = data?.image ?? UIImage(frameworkResourceNamed: "defaultFavicon")
cell.siteImageView.backgroundColor = data?.backgroundColor
}
state.dataSource?.retrieveFavicon(for: url, on: cell.siteImageView)
}
cell.verifiedStatusImageView.isHidden = publisher.status == .notVerified
let contribution = publisher.weight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ extension TipsDetailViewController: UITableViewDataSource, UITableViewDelegate {
cell.siteNameLabel.attributedText = attrName

cell.siteImageView.image = UIImage(frameworkResourceNamed: "defaultFavicon")
setFavicon(identifier: tip.id, pageURL: tip.url, faviconURL: tip.faviconUrl)
if let url = URL(string: tip.url) {
state.dataSource?.retrieveFavicon(for: url, on: cell.siteImageView)
}
cell.verifiedStatusImageView.isHidden = tip.status == .notVerified
cell.typeNameLabel.text = Strings.oneTimeText + Date.stringFrom(reconcileStamp: tip.reconcileStamp)
cell.tokenView.batContainer.amountLabel.text = "\(tip.weight)"
Expand All @@ -171,30 +173,6 @@ extension TipsDetailViewController {
return report
}

fileprivate func setFavicon(identifier: String, pageURL: String, faviconURL: String?) {
if let pageURL = URL(string: pageURL) {
state.dataSource?.retrieveFavicon(for: pageURL, faviconURL: URL(string: faviconURL ?? ""), completion: {[weak self] favData in
guard let self = self,
let image = favData?.image else {
return
}

let indices = self.tipsList.enumerated().compactMap({ $0.element.id == identifier ? $0.offset : nil })
if indices.isEmpty {
return
}

if let tableView = (self.view as? SettingsTableView)?.tableView {
for index in indices {
if let cell = tableView.cellForRow(at: IndexPath(row: index, section: Section.tips.rawValue)) as? TipsTableCell {
cell.siteImageView.image = image
}
}
}
})
}
}

func setupLedgerObservers() {
ledgerObserver.recurringTipRemoved = { [weak self] key in
guard let self = self, self.isViewLoaded else {
Expand Down
9 changes: 2 additions & 7 deletions BraveRewardsUI/Tipping/TippingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,8 @@ class TippingViewController: UIViewController, UIViewControllerTransitioningDele
})

if let dataSource = self.state.dataSource,
let pageURL = URL(string: self.publisherInfo.url),
let faviconURL = self.state.faviconURL {
dataSource.retrieveFavicon(for: pageURL, faviconURL: faviconURL, completion: { faviconData in
guard let faviconData = faviconData else { return }
self.tippingView.overviewView.faviconImageView.image = faviconData.image
self.tippingView.overviewView.faviconImageView.backgroundColor = faviconData.backgroundColor
})
let pageURL = URL(string: self.publisherInfo.url) {
dataSource.retrieveFavicon(for: pageURL, on: self.tippingView.overviewView.faviconImageView.imageView)
}

self.tippingView.overviewView.socialStackView.arrangedSubviews.forEach({ $0.removeFromSuperview() })
Expand Down
9 changes: 1 addition & 8 deletions BraveRewardsUI/Wallet/WalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,7 @@ class WalletViewController: UIViewController, RewardsSummaryProtocol {
publisherView.checkAgainButton.isHidden = publisher != nil
publisherView.setCheckAgainIsLoading(state.ledger.isLoadingPublisherList)

state.dataSource?.retrieveFavicon(for: state.url, faviconURL: URL(string: publisher?.faviconUrl ?? "") ?? state.faviconURL, completion: { [weak self] faviconData in
guard let data = faviconData else { return }

self?.publisherSummaryView.publisherView.faviconImageView.do {
$0.image = data.image
$0.backgroundColor = data.backgroundColor
}
})
state.dataSource?.retrieveFavicon(for: state.url, on: publisherSummaryView.publisherView.faviconImageView.imageView)

guard let publisher = publisher else {
publisherView.updatePublisherName(state.dataSource?.displayString(for: state.url) ?? "", provider: "")
Expand Down
31 changes: 31 additions & 0 deletions BraveUI/Buttons/SpringButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2020 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update license for all newly added files.
#2441

// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import UIKit

/// A control that scales down when highlighted and back up when not
open class SpringButton: UIControl {
/// The scale to adjust to when the control is highlighted
open var highlightScale: CGFloat = 0.95

override open var isHighlighted: Bool {
didSet {
UIViewPropertyAnimator(duration: 0.3, dampingRatio: 0.8) {
let scale = self.isHighlighted ? self.highlightScale : 1.0
self.transform = CGAffineTransform(scaleX: scale, y: scale)
}
.startAnimation()
}
}

public override init(frame: CGRect) {
super.init(frame: frame)
}

@available(*, unavailable)
public required init(coder: NSCoder) {
fatalError()
}
}
25 changes: 25 additions & 0 deletions BraveUI/Extensions/UICollectionViewExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import UIKit

public protocol CollectionViewReusable { }

extension CollectionViewReusable {
fileprivate static var identifier: String {
return String(describing: type(of: self))
}
}

extension UICollectionView {
/// Register a UICollectionViewCell subclass as a dequeable cell
public func register<T: UICollectionViewCell & CollectionViewReusable>(_ cellClass: T.Type) {
register(cellClass, forCellWithReuseIdentifier: cellClass.identifier)
}
// swiftlint:disable force_cast
public func dequeueReusableCell<T: UICollectionViewCell & CollectionViewReusable>(for indexPath: IndexPath) -> T {
return dequeueReusableCell(withReuseIdentifier: T.identifier, for: indexPath) as! T
}
// swiftlint:enable force_cast
}
Loading