Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu 2.0 #1058

Merged
merged 42 commits into from Jun 6, 2019
Merged

Menu 2.0 #1058

Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
57860c2
MVP for iPhone
iccub Apr 2, 2019
d2a4044
Migrate urlbar items to stackview
iccub Apr 3, 2019
0e2a935
Better naming and file separation for toolbar objects
iccub Apr 3, 2019
799f2c7
WIP: menu actions
iccub Apr 6, 2019
1f25420
Long press actions: dismissal and refactor.
iccub Apr 8, 2019
2cb5750
Remove HomeViewController
iccub Apr 8, 2019
191f371
BookmarksVC cleanup: remove unused code
iccub Apr 8, 2019
7926cfe
folder hirerarchy alpha version
iccub Apr 11, 2019
17afd7d
Make separator line work.
iccub Apr 11, 2019
bbdaa80
Add bookmark mvp, can add at root level.
iccub Apr 14, 2019
7d19867
Merge branch 'development' of github.com:brave/brave-ios into feature…
iccub Apr 14, 2019
ea4f0d8
Adding bookmark works.
iccub Apr 15, 2019
c3a737a
Add folders mvp
iccub Apr 15, 2019
ee76b6a
xcode 10.2
iccub Apr 15, 2019
f06a617
Correct buttons when adding a folder.
iccub Apr 16, 2019
02dab4c
Dismiss view when bookmark is selected.
iccub Apr 16, 2019
c0d29cd
Support editing modes in AddEditBookmarkVC
iccub Apr 16, 2019
736fc5e
Edit without saving location mvp.
iccub Apr 16, 2019
5138870
Edit bookmark location mvp
iccub Apr 17, 2019
ada5f14
Fetch favicon to bookmark details
iccub Apr 17, 2019
134d4a9
whitespace
iccub Apr 17, 2019
d68cad8
Add localized strings
iccub Apr 17, 2019
c022eb5
Edit improvements, title for add/edit screen
iccub Apr 17, 2019
7e30962
Remove unused BookmarkEditViewController
iccub Apr 17, 2019
f781004
Update image assets.
iccub Apr 17, 2019
1d5d612
Make folder detail height equal to folder hierarchy cells height.
iccub Apr 17, 2019
e6c7a1c
Harden against sync changes.
iccub Apr 17, 2019
93c9a24
Make updated url bar work with safe area insets
iccub Apr 17, 2019
880de9e
Show share menu popover at correct location.
iccub Apr 17, 2019
40f11b9
Design feedback from James.
iccub Apr 18, 2019
99b171f
Bookmark/folder detail views refactor.
iccub Apr 18, 2019
0bf5ddc
Header view refactor.
iccub Apr 18, 2019
c57f709
AddEditBookmarkTableViewController refactor.
iccub Apr 19, 2019
1d9e0c3
MenuViewController refactor.
iccub Apr 19, 2019
de90bd1
final touches
iccub Apr 19, 2019
32e1e30
Fix unit tests.
iccub Apr 19, 2019
bc45a12
review
iccub Apr 23, 2019
f7fd274
Make folderCellTag private
iccub Apr 23, 2019
839602c
Merge branch 'development' of github.com:brave/brave-ios into feature…
iccub Apr 23, 2019
8ad53f3
Swift 4.2 conformance
iccub Apr 23, 2019
21d08ed
Fix title helper function
iccub Apr 23, 2019
76ab847
Set syncParentUUID when updating location.
iccub Apr 23, 2019
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

WIP: menu actions

  • Loading branch information
iccub committed Apr 6, 2019
commit 799f2c750df89dd71c95e5fe2a57ab7c39bb59e3
@@ -422,6 +422,7 @@
44331DD622551E15007E3E93 /* ToolbarProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44331DD522551E15007E3E93 /* ToolbarProtocols.swift */; };
44331DD8225521B6007E3E93 /* UrlBarTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44331DD7225521B6007E3E93 /* UrlBarTextField.swift */; };
44331DDA22552313007E3E93 /* LocationContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44331DD922552313007E3E93 /* LocationContainerView.swift */; };
44331DDC22561F34007E3E93 /* ToolbarUrlActionsDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44331DDB22561F34007E3E93 /* ToolbarUrlActionsDelegate.swift */; };
44FA2F3021F8DB1000EFA86A /* DataPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44FA2F2F21F8DB1000EFA86A /* DataPreferences.swift */; };
4F514FD41ACD8F2C0022D7EA /* HistoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F514FD31ACD8F2C0022D7EA /* HistoryTests.swift */; };
4F97573B1AFA6F37006ECC24 /* readerContent.html in Resources */ = {isa = PBXBuildFile; fileRef = 4F9757391AFA6F37006ECC24 /* readerContent.html */; };
@@ -1551,6 +1552,7 @@
44331DD522551E15007E3E93 /* ToolbarProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolbarProtocols.swift; sourceTree = "<group>"; };
44331DD7225521B6007E3E93 /* UrlBarTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlBarTextField.swift; sourceTree = "<group>"; };
44331DD922552313007E3E93 /* LocationContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationContainerView.swift; sourceTree = "<group>"; };
44331DDB22561F34007E3E93 /* ToolbarUrlActionsDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolbarUrlActionsDelegate.swift; sourceTree = "<group>"; };
44FA2F2F21F8DB1000EFA86A /* DataPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataPreferences.swift; sourceTree = "<group>"; };
4F514FD31ACD8F2C0022D7EA /* HistoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryTests.swift; sourceTree = "<group>"; };
4F9757391AFA6F37006ECC24 /* readerContent.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = readerContent.html; sourceTree = "<group>"; };
@@ -3210,13 +3212,15 @@
44331DD122551AFE007E3E93 /* ToolbarButton.swift */,
44331DD322551CC0007E3E93 /* ToolbarHelper.swift */,
44331DD522551E15007E3E93 /* ToolbarProtocols.swift */,
44331DDB22561F34007E3E93 /* ToolbarUrlActionsDelegate.swift */,
);
path = Toolbars;
sourceTree = "<group>";
};
44331DCF225519D3007E3E93 /* BottomToolbar */ = {
isa = PBXGroup;
children = (
7BC7B4571C903A6A0046E9D2 /* Menu */,
D314E7F51A37B98700426A76 /* BottomToolbarView.swift */,
);
path = BottomToolbar;
@@ -4175,7 +4179,6 @@
7B0B1B9C1C1B69F500DF4AB5 /* Extensions */,
A104E190210A380E00D2323E /* Shields */,
E63ED8DF1BFD254E0097D08E /* Login Management */,
7BC7B4571C903A6A0046E9D2 /* Menu */,
F84B21F51A0910F600AAB793 /* Reader */,
2F44FC551A9E83E200FD20CC /* Settings */,
D3972BF01C22412B00035B87 /* Share */,
@@ -5656,6 +5659,7 @@
D0C95EF6201A55A800E4E51C /* BrowserViewController+UIDropInteractionDelegate.swift in Sources */,
44331DD622551E15007E3E93 /* ToolbarProtocols.swift in Sources */,
0A1E84422190A57F0042F782 /* SyncPairCameraViewController.swift in Sources */,
44331DDC22561F34007E3E93 /* ToolbarUrlActionsDelegate.swift in Sources */,
4422D43721BFD29E00BF1855 /* NSData+GZIP.m in Sources */,
D31CF65C1CC1959A001D0BD0 /* PrivilegedRequest.swift in Sources */,
D8D33A7D1FBD080300A20A28 /* SnapKitExtensions.swift in Sources */,
@@ -1647,11 +1647,7 @@ extension BrowserViewController: URLBarDelegate {
}

func urlBarDidTapMenuButton(_ urlBar: URLBarView) {
guard let selectedTab = tabManager.selectedTab else { return }

let homePanel = HomeMenuController(profile: profile, tabState: selectedTab.tabState)
homePanel.preferredContentSize = CGSize(width: PopoverController.preferredPopoverWidth, height: 600.0)
homePanel.delegate = self
let homePanel = MenuViewController(bvc: self)
let popover = PopoverController(contentController: homePanel, contentSizeBehavior: .preferredContentSize)
popover.present(from: urlBar.menuButton, on: self)
}
@@ -2837,7 +2833,7 @@ extension BrowserViewController: JSPromptAlertControllerDelegate {

extension BrowserViewController: HomeMenuControllerDelegate {

func menuDidOpenSettings(_ menu: HomeMenuController) {
func menuDidOpenSettings(_ menu: UIViewController) {
menu.dismiss(animated: true) { [weak self] in
guard let `self` = self else { return }
let settingsController = SettingsViewController(profile: self.profile, tabManager: self.tabManager)
@@ -2848,14 +2844,14 @@ extension BrowserViewController: HomeMenuControllerDelegate {
}
}

func menuDidSelectURL(_ menu: HomeMenuController, url: URL, visitType: VisitType, action: MenuURLAction) {
func menuDidSelectURL(_ menu: UIViewController, url: URL, visitType: VisitType, action: MenuURLAction) {
switch action {
case .openInCurrentTab:
menu.dismiss(animated: true)
//menu.dismiss(animated: true)
finishEditingAndSubmit(url, visitType: visitType)

case .openInNewTab(let isPrivate):
menu.dismiss(animated: true)
//menu.dismiss(animated: true)
let tab = self.tabManager.addTab(PrivilegedRequest(url: url) as URLRequest, afterTab: self.tabManager.selectedTab, isPrivate: isPrivate)
if isPrivate && !PrivateBrowsingManager.shared.isPrivateBrowsing {
@@ -2889,12 +2885,35 @@ extension BrowserViewController: HomeMenuControllerDelegate {
}
}

func menuDidBatchOpenURLs(_ menu: HomeMenuController, urls: [URL]) {
func menuDidBatchOpenURLs(_ menu: UIViewController, urls: [URL]) {
let tabIsPrivate = TabType.of(tabManager.selectedTab).isPrivate
self.tabManager.addTabsForURLs(urls, zombie: false, isPrivate: tabIsPrivate)
}
}

extension BrowserViewController: ToolbarUrlActionsDelegate {

func openInNewTab(_ url: URL, isPrivate: Bool) {
menuDidSelectURL(self, url: url, visitType: .unknown, action: .openInNewTab(isPrivate: isPrivate))
}

func copy(_ url: URL) {
menuDidSelectURL(self, url: url, visitType: .unknown, action: .copy)
}

func share(_ url: URL) {
menuDidSelectURL(self, url: url, visitType: .unknown, action: .share)
}

func batchOpen(_ urls: [URL]) {
menuDidBatchOpenURLs(self, urls: urls)
}

func select(url: URL, visitType: VisitType) {
menuDidSelectURL(self, url: url, visitType: visitType, action: .openInCurrentTab)
}
}

extension BrowserViewController: TopSitesDelegate {

func didSelect(input: String) {
@@ -23,7 +23,7 @@ class FavoritesViewController: UIViewController, Themeable {
static let statsBottomMargin: CGFloat = 5
static let searchEngineCalloutPadding: CGFloat = 30.0
}
weak var linkNavigationDelegate: LinkNavigationDelegate?

weak var delegate: TopSitesDelegate?

// MARK: - Favorites collection view properties
@@ -105,7 +105,7 @@ class BookmarksViewController: SiteTableViewController {
/// Called when the bookmarks are updated via some user input (i.e. Delete, edit, etc.)
var bookmarksDidChange: (() -> Void)?

weak var linkNavigationDelegate: LinkNavigationDelegate?
weak var toolbarUrlActionsDelegate: ToolbarUrlActionsDelegate?

var bookmarksFRC: NSFetchedResultsController<Bookmark>?

@@ -413,7 +413,7 @@ class BookmarksViewController: SiteTableViewController {
self.showEditBookmarkController(tableView, indexPath: indexPath)
} else {
if let url = URL(string: bookmark.url ?? "") {
linkNavigationDelegate?.linkNavigatorDidSelectURL(url: url, visitType: .bookmark)
toolbarUrlActionsDelegate?.select(url: url, visitType: .bookmark)
}
}
} else {
@@ -424,7 +424,7 @@ class BookmarksViewController: SiteTableViewController {
let nextController = BookmarksViewController(folder: bookmark, isPrivateBrowsing: isPrivateBrowsing)
nextController.profile = profile
nextController.bookmarksDidChange = bookmarksDidChange
nextController.linkNavigationDelegate = linkNavigationDelegate
nextController.toolbarUrlActionsDelegate = toolbarUrlActionsDelegate

self.navigationController?.pushViewController(nextController, animated: true)
}
@@ -653,7 +653,7 @@ extension BookmarksViewController {
title: String(format: Strings.Open_All_Bookmarks, children.count),
style: .default,
handler: { [weak self] _ in
self?.linkNavigationDelegate?.linkNavigatorDidRequestToBatchOpenURLs(urls)
self?.toolbarUrlActionsDelegate?.batchOpen(urls)
}
)
]
@@ -666,24 +666,24 @@ extension BookmarksViewController {
// New Tab
items.append(UIAlertAction(title: Strings.OpenNewTabButtonTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.linkNavigationDelegate?.linkNavigatorDidRequestToOpenInNewTab(url, isPrivate: currentTabIsPrivate)
self.toolbarUrlActionsDelegate?.openInNewTab(url, isPrivate: currentTabIsPrivate)
}))
if !currentTabIsPrivate {
// New Private Tab
items.append(UIAlertAction(title: Strings.OpenNewPrivateTabButtonTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.linkNavigationDelegate?.linkNavigatorDidRequestToOpenInNewTab(url, isPrivate: true)
self.toolbarUrlActionsDelegate?.openInNewTab(url, isPrivate: true)
}))
}
// Copy
items.append(UIAlertAction(title: Strings.CopyLinkActionTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.linkNavigationDelegate?.linkNavigatorDidRequestToCopyURL(url)
self.toolbarUrlActionsDelegate?.copy(url)
}))
// Share
items.append(UIAlertAction(title: Strings.ShareLinkActionTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.linkNavigationDelegate?.linkNavigatorDidRequestToShareURL(url)
self.toolbarUrlActionsDelegate?.share(url)
}))

return items
@@ -16,7 +16,7 @@ private struct HistoryViewControllerUX {
}

class HistoryViewController: SiteTableViewController {
weak var linkNavigationDelegate: LinkNavigationDelegate?
weak var toolbarUrlActionsDelegate: ToolbarUrlActionsDelegate?
fileprivate lazy var emptyStateOverlayView: UIView = self.createEmptyStateOverview()
var frc: NSFetchedResultsController<History>?

@@ -129,7 +129,7 @@ class HistoryViewController: SiteTableViewController {
let site = frc?.object(at: indexPath)

if let u = site?.url, let url = URL(string: u) {
linkNavigationDelegate?.linkNavigatorDidSelectURL(url: url, visitType: .typed)
toolbarUrlActionsDelegate?.select(url: url, visitType: .typed)
}
tableView.deselectRow(at: indexPath, animated: true)
}
@@ -246,24 +246,24 @@ extension HistoryViewController {
// New Tab
items.append(UIAlertAction(title: Strings.OpenNewTabButtonTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.linkNavigationDelegate?.linkNavigatorDidRequestToOpenInNewTab(url, isPrivate: currentTabIsPrivate)
self.toolbarUrlActionsDelegate?.openInNewTab(url, isPrivate: currentTabIsPrivate)
}))
if !currentTabIsPrivate {
// New Private Tab
items.append(UIAlertAction(title: Strings.OpenNewPrivateTabButtonTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.linkNavigationDelegate?.linkNavigatorDidRequestToOpenInNewTab(url, isPrivate: true)
self.toolbarUrlActionsDelegate?.openInNewTab(url, isPrivate: true)
}))
}
// Copy
items.append(UIAlertAction(title: Strings.CopyLinkActionTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.linkNavigationDelegate?.linkNavigatorDidRequestToCopyURL(url)
self.toolbarUrlActionsDelegate?.copy(url)
}))
// Share
items.append(UIAlertAction(title: Strings.ShareLinkActionTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.linkNavigationDelegate?.linkNavigatorDidRequestToShareURL(url)
self.toolbarUrlActionsDelegate?.share(url)
}))

return items
@@ -23,20 +23,11 @@ enum MenuURLAction {
}

protocol HomeMenuControllerDelegate: class {
func menuDidOpenSettings(_ menu: HomeMenuController)
func menuDidOpenSettings(_ menu: UIViewController)
/// The user selected a url in one of the menu panels (i.e. bookmarks or history)
func menuDidSelectURL(_ menu: HomeMenuController, url: URL, visitType: VisitType, action: MenuURLAction)
func menuDidSelectURL(_ menu: UIViewController, url: URL, visitType: VisitType, action: MenuURLAction)
/// The user tapped "Open All" on a folder
func menuDidBatchOpenURLs(_ menu: HomeMenuController, urls: [URL])
}

protocol LinkNavigationDelegate: class {
func linkNavigatorDidRequestToOpenInNewTab(_ url: URL, isPrivate: Bool)
func linkNavigatorDidRequestToCopyURL(_ url: URL)
func linkNavigatorDidRequestToShareURL(_ url: URL)
func linkNavigatorDidRequestToBatchOpenURLs(_ urls: [URL])
func linkNavigatorDidSelectURL(url: URL, visitType: VisitType)
func linkNavigatorDidSelectURLString(url: String, visitType: VisitType)
func menuDidBatchOpenURLs(_ menu: UIViewController, urls: [URL])
}

class HomeMenuController: UIViewController, PopoverContentComponent {
@@ -91,12 +82,9 @@ class HomeMenuController: UIViewController, PopoverContentComponent {
bookmarksController.profile = profile
historyController.profile = profile

bookmarksController.linkNavigationDelegate = self
bookmarksController.bookmarksDidChange = { [weak self] in
self?.updateBookmarkStatus()
}

historyController.linkNavigationDelegate = self
}

@available(*, unavailable)
@@ -266,43 +254,3 @@ class HomeMenuController: UIViewController, PopoverContentComponent {
addBookmarkButton.isSelected = Bookmark.contains(url: url)
}
}

extension HomeMenuController: LinkNavigationDelegate {

func linkNavigatorDidRequestToOpenInNewTab(_ url: URL, isPrivate: Bool) {
delegate?.menuDidSelectURL(self, url: url, visitType: .unknown, action: .openInNewTab(isPrivate: isPrivate))
}

func linkNavigatorDidRequestToCopyURL(_ url: URL) {
delegate?.menuDidSelectURL(self, url: url, visitType: .unknown, action: .copy)
}

func linkNavigatorDidRequestToShareURL(_ url: URL) {
delegate?.menuDidSelectURL(self, url: url, visitType: .unknown, action: .share)
}

func linkNavigatorDidRequestToBatchOpenURLs(_ urls: [URL]) {
delegate?.menuDidBatchOpenURLs(self, urls: urls)
}

func linkNavigatorDidSelectURL(url: URL, visitType: VisitType) {
delegate?.menuDidSelectURL(self, url: url, visitType: visitType, action: .openInCurrentTab)
}

func linkNavigatorDidSelectURLString(url: String, visitType: VisitType) {
guard let profile = profile else { return }

// If we can't get a real URL out of what should be a URL, we let the user's
// default search engine give it a shot.
// Typically we'll be in this state if the user has tapped a bookmarked search template
// (e.g., "http://foo.com/bar/?query=%s"), and this will get them the same behavior as if
// they'd copied and pasted into the URL bar.
// See BrowserViewController.urlBar:didSubmitText:.
guard let url = URIFixup.getURL(url) ?? profile.searchEngines.defaultEngine().searchURLForQuery(url) else {
Logger.browserLogger.warning("Invalid URL, and couldn't generate a search URL for it.")
return
}

return self.linkNavigatorDidSelectURL(url: url, visitType: visitType)
}
}
@@ -3,6 +3,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
import UIKit
import Storage

class MenuViewController: UITableViewController {

@@ -70,6 +71,7 @@ class MenuViewController: UITableViewController {

func openBookmarks() {
let vc = BookmarksViewController(folder: nil, isPrivateBrowsing: PrivateBrowsingManager.shared.isPrivateBrowsing)
vc.toolbarUrlActionsDelegate = bvc

let nc = SettingsNavigationController(rootViewController: vc)
nc.modalPresentationStyle = .formSheet
@@ -83,6 +85,7 @@ class MenuViewController: UITableViewController {

func openHistory() {
let vc = HistoryViewController(isPrivateBrowsing: PrivateBrowsingManager.shared.isPrivateBrowsing)
vc.toolbarUrlActionsDelegate = bvc

let nc = SettingsNavigationController(rootViewController: vc)
nc.modalPresentationStyle = .formSheet
@@ -136,3 +139,5 @@ extension MenuViewController: PopoverContentComponent {
var isPanToDismissEnabled: Bool { return false }

}


@@ -0,0 +1,14 @@
// 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 Foundation
import Storage

protocol ToolbarUrlActionsDelegate: class {
func openInNewTab(_ url: URL, isPrivate: Bool)
func copy(_ url: URL)
func share(_ url: URL)
func batchOpen(_ urls: [URL])
func select(url: URL, visitType: VisitType)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.