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

Next

MVP for iPhone

  • Loading branch information
iccub committed Apr 2, 2019
commit 57860c2e97effab2154a64e3c3668964da7a67e8
@@ -131,6 +131,7 @@ public extension Strings {
public static let TabToolbarBackButtonAccessibilityLabel = NSLocalizedString("TabToolbarBackButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Back", comment: "Accessibility label for the Back button in the tab toolbar.")
public static let TabToolbarForwardButtonAccessibilityLabel = NSLocalizedString("TabToolbarForwardButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Forward", comment: "Accessibility Label for the tab toolbar Forward button")
public static let TabToolbarShareButtonAccessibilityLabel = NSLocalizedString("TabToolbarShareButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Share", comment: "Accessibility Label for the browser toolbar Share button")
public static let TabToolbarMenuButtonAccessibilityLabel = NSLocalizedString("TabToolbarMenuButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Menu", comment: "Accessibility Label for the browser toolbar Menu button")
public static let TabToolbarAddTabButtonAccessibilityLabel = NSLocalizedString("TabToolbarAddTabButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Add Tab", comment: "Accessibility label for the Add Tab button in the Tab Tray.")
public static let TabToolbarAccessibilityLabel = NSLocalizedString("TabToolbarAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Navigation Toolbar", comment: "Accessibility label for the navigation toolbar displayed at the bottom of the screen.")
}
@@ -416,6 +416,7 @@
4422D57321BFFB7F00BF1855 /* stringpiece.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4422D54121BFFB7E00BF1855 /* stringpiece.cc */; };
4422D57421BFFB7F00BF1855 /* prog.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4422D54221BFFB7E00BF1855 /* prog.cc */; };
4422D57621C05DE600BF1855 /* httpse.leveldb.tgz in Resources */ = {isa = PBXBuildFile; fileRef = 4422D57521C05DE500BF1855 /* httpse.leveldb.tgz */; };
44331DBB22521013007E3E93 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44331DBA22521013007E3E93 /* MenuViewController.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 */; };
@@ -1539,6 +1540,7 @@
4422D54121BFFB7E00BF1855 /* stringpiece.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stringpiece.cc; sourceTree = "<group>"; };
4422D54221BFFB7E00BF1855 /* prog.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = prog.cc; sourceTree = "<group>"; };
4422D57521C05DE500BF1855 /* httpse.leveldb.tgz */ = {isa = PBXFileReference; lastKnownFileType = file; path = httpse.leveldb.tgz; sourceTree = "<group>"; };
44331DBA22521013007E3E93 /* MenuViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuViewController.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>"; };
@@ -3386,6 +3388,7 @@
A1FEEE0220BEE6BF00298DA2 /* HomeMenuController.swift */,
A1AD4BCE20BF3E8C007A6EA1 /* BookmarksViewController.swift */,
A198E75020C701ED00334C11 /* HistoryViewController.swift */,
44331DBA22521013007E3E93 /* MenuViewController.swift */,
);
path = Menu;
sourceTree = "<group>";
@@ -5789,6 +5792,7 @@
D04D1B862097859B0074B35F /* DownloadToast.swift in Sources */,
4422D4F721BFFB7600BF1855 /* dbformat.cc in Sources */,
7B844E3D1BBDDB9D00E733A2 /* ChevronView.swift in Sources */,
44331DBB22521013007E3E93 /* MenuViewController.swift in Sources */,
4422D4BC21BFFB7600BF1855 /* testharness.cc in Sources */,
3BE7275D1CCFE8B60099189F /* CustomSearchHandler.swift in Sources */,
A1FEEE2020BF28D900298DA2 /* Then.swift in Sources */,
@@ -1679,7 +1679,7 @@ extension BrowserViewController: TabToolbarDelegate {
tabManager.selectedTab?.goForward()
}

func tabToolbarDidPressShare(_ tabToolbar: TabToolbarProtocol, button: UIButton) {
func tabToolbarDidPressShare() {
func share(url: URL) {
presentActivityViewController(
url,
@@ -1707,6 +1707,12 @@ extension BrowserViewController: TabToolbarDelegate {
}
}

func tabToolbarDidPressMenu(_ tabToolbar: TabToolbarProtocol, button: UIButton) {
let homePanel = MenuViewController(bvc: self)
let popover = PopoverController(contentController: homePanel, contentSizeBehavior: .preferredContentSize)
popover.present(from: tabToolbar.menuButton, on: self)
}

func tabToolbarDidPressAddTab(_ tabToolbar: TabToolbarProtocol, button: UIButton) {
self.openBlankNewTab(focusLocationField: true, isPrivate: PrivateBrowsingManager.shared.isPrivateBrowsing)
}
@@ -14,6 +14,7 @@ protocol TabToolbarProtocol: class {
var backButton: ToolbarButton { get }
var shareButton: ToolbarButton { get }
var addTabButton: ToolbarButton { get }
var menuButton: ToolbarButton { get }
var actionButtons: [Themeable & UIButton] { get }

func updateBackStatus(_ canGoBack: Bool)
@@ -28,8 +29,9 @@ protocol TabToolbarDelegate: class {
func tabToolbarDidLongPressBack(_ tabToolbar: TabToolbarProtocol, button: UIButton)
func tabToolbarDidLongPressForward(_ tabToolbar: TabToolbarProtocol, button: UIButton)
func tabToolbarDidPressTabs(_ tabToolbar: TabToolbarProtocol, button: UIButton)
func tabToolbarDidPressMenu(_ tabToolbar: TabToolbarProtocol, button: UIButton)
func tabToolbarDidLongPressTabs(_ tabToolbar: TabToolbarProtocol, button: UIButton)
func tabToolbarDidPressShare(_ tabToolbar: TabToolbarProtocol, button: UIButton)
func tabToolbarDidPressShare()
func tabToolbarDidPressAddTab(_ tabToolbar: TabToolbarProtocol, button: UIButton)
func tabToolbarDidLongPressAddTab(_ tabToolbar: TabToolbarProtocol, button: UIButton)
func tabToolbarDidSwipeToChangeTabs(_ tabToolbar: TabToolbarProtocol, direction: UISwipeGestureRecognizer.Direction)
@@ -71,9 +73,17 @@ open class TabToolbarHelper: NSObject {
toolbar.addTabButton.accessibilityLabel = Strings.TabToolbarAddTabButtonAccessibilityLabel
toolbar.addTabButton.addTarget(self, action: #selector(didClickAddTab), for: UIControlEvents.touchUpInside)
toolbar.addTabButton.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(didLongPressAddTab(_:))))

toolbar.menuButton.setImage(#imageLiteral(resourceName: "menu-More-Options").template, for: .normal)
toolbar.menuButton.accessibilityLabel = Strings.TabToolbarMenuButtonAccessibilityLabel
toolbar.menuButton.addTarget(self, action: #selector(didClickMenu), for: UIControlEvents.touchUpInside)

setTheme(theme: .regular, forButtons: toolbar.actionButtons)
}

func didClickMenu() {
toolbar.tabToolbarDelegate?.tabToolbarDidPressMenu(toolbar, button: toolbar.backButton)
}

func didClickBack() {
toolbar.tabToolbarDelegate?.tabToolbarDidPressBack(toolbar, button: toolbar.backButton)
@@ -104,7 +114,7 @@ open class TabToolbarHelper: NSObject {
}

func didClickShare() {
toolbar.tabToolbarDelegate?.tabToolbarDidPressShare(toolbar, button: toolbar.shareButton)
toolbar.tabToolbarDelegate?.tabToolbarDidPressShare()
}

func didClickAddTab() {
@@ -174,13 +184,14 @@ class TabToolbar: UIView {
let backButton = ToolbarButton()
let shareButton = ToolbarButton()
let addTabButton = ToolbarButton()
let menuButton = ToolbarButton()
let actionButtons: [Themeable & UIButton]

var helper: TabToolbarHelper?
private let contentView = UIStackView()

fileprivate override init(frame: CGRect) {
actionButtons = [backButton, forwardButton, shareButton, addTabButton, tabsButton]
actionButtons = [backButton, forwardButton, addTabButton, tabsButton, menuButton]
super.init(frame: frame)
setupAccessibility()

@@ -117,10 +117,11 @@ class BookmarksViewController: SiteTableViewController {
var isEditingIndividualBookmark: Bool = false

var currentFolder: Bookmark?
let tabState: TabState
/// Certain bookmark actions are different in private browsing mode.
let isPrivateBrowsing: Bool

init(folder: Bookmark?, tabState: TabState) {
self.tabState = tabState
init(folder: Bookmark?, isPrivateBrowsing: Bool) {
self.isPrivateBrowsing = isPrivateBrowsing

super.init(nibName: nil, bundle: nil)

@@ -143,12 +144,6 @@ class BookmarksViewController: SiteTableViewController {

tableView.allowsSelectionDuringEditing = true

let navBar = self.navigationController?.navigationBar
navBar?.barTintColor = BraveUX.BackgroundColorForSideToolbars
navBar?.isTranslucent = false
navBar?.titleTextAttributes = [.font: UIFont.systemFont(ofSize: UIConstants.DefaultChromeSize, weight: .medium), .foregroundColor: BraveUX.GreyJ]
navBar?.clipsToBounds = true

let width = self.view.bounds.size.width
let toolbarHeight = CGFloat(44)

@@ -426,7 +421,7 @@ class BookmarksViewController: SiteTableViewController {
//show editing view for bookmark item
self.showEditBookmarkController(tableView, indexPath: indexPath)
} else {
let nextController = BookmarksViewController(folder: bookmark, tabState: tabState)
let nextController = BookmarksViewController(folder: bookmark, isPrivateBrowsing: isPrivateBrowsing)
nextController.profile = profile
nextController.bookmarksDidChange = bookmarksDidChange
nextController.linkNavigationDelegate = linkNavigationDelegate
@@ -629,7 +624,7 @@ extension BookmarksViewController {
actionsForFolder(bookmark).forEach { alert.addAction($0) }
} else {
alert.title = bookmark.url?.replacingOccurrences(of: "mailto:", with: "").ellipsize(maxLength: ActionSheetTitleMaxLength)
actionsForBookmark(bookmark, currentTabIsPrivate: tabState.type.isPrivate).forEach { alert.addAction($0) }
actionsForBookmark(bookmark, currentTabIsPrivate: isPrivateBrowsing).forEach { alert.addAction($0) }
}

let cancelAction = UIAlertAction(title: Strings.CancelButtonTitle, style: .cancel, handler: nil)
@@ -20,10 +20,10 @@ class HistoryViewController: SiteTableViewController {
fileprivate lazy var emptyStateOverlayView: UIView = self.createEmptyStateOverview()
var frc: NSFetchedResultsController<History>?

let tabState: TabState
let isPrivateBrowsing: Bool

init(tabState: TabState) {
self.tabState = tabState
init(isPrivateBrowsing: Bool) {
self.isPrivateBrowsing = isPrivateBrowsing

super.init(nibName: nil, bundle: nil)

@@ -224,7 +224,7 @@ extension HistoryViewController {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

alert.title = history.url?.replacingOccurrences(of: "mailto:", with: "").ellipsize(maxLength: ActionSheetTitleMaxLength)
actionsForHistory(history, currentTabIsPrivate: tabState.type.isPrivate).forEach { alert.addAction($0) }
actionsForHistory(history, currentTabIsPrivate: isPrivateBrowsing).forEach { alert.addAction($0) }

let cancelAction = UIAlertAction(title: Strings.CancelButtonTitle, style: .cancel, handler: nil)
alert.addAction(cancelAction)
@@ -83,8 +83,9 @@ class HomeMenuController: UIViewController, PopoverContentComponent {
init(profile: Profile, tabState: TabState) {
self.profile = profile
self.tabState = tabState
self.bookmarksController = BookmarksViewController(folder: nil, tabState: tabState)
self.historyController = HistoryViewController(tabState: tabState)
let isPrivateBrowsing = PrivateBrowsingManager.shared.isPrivateBrowsing
self.bookmarksController = BookmarksViewController(folder: nil, isPrivateBrowsing: isPrivateBrowsing)
self.historyController = HistoryViewController(isPrivateBrowsing: isPrivateBrowsing)

super.init(nibName: nil, bundle: nil)
bookmarksController.profile = profile
@@ -0,0 +1,138 @@
// 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

class MenuViewController: UITableViewController {

enum MenuButtons: Int {
case bookmarks, history, settings, share

var title: String {
switch self {
case .bookmarks: return "Bookmarks"
case .history: return "History"
case .settings: return "Settings"
case .share: return "Share with..."
}
}

var icon: UIImage {
switch self {
case .bookmarks: return #imageLiteral(resourceName: "menu-add-bookmark")
case .history: return #imageLiteral(resourceName: "menu-history")
case .settings: return #imageLiteral(resourceName: "menu-settings")
case .share: return #imageLiteral(resourceName: "nav-share")
}
}

// TODO: Remove when we can use Swift 4.2/`CaseIterable`
static let allCases: [MenuButtons] = [.bookmarks, .history, .settings, .share]
}

let bvc: BrowserViewController

init(bvc: BrowserViewController) {
self.bvc = bvc

super.init(nibName: nil, bundle: nil)
}

@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError()
}

override func viewDidLoad() {
super.viewDidLoad()

let size = CGSize(width: 200, height: tableView.rect(forSection: 0).height)

preferredContentSize = size
tableView.tableFooterView = UIView()
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

guard let cell = tableView.cellForRow(at: indexPath) else { return }

switch cell.tag {
case MenuButtons.bookmarks.rawValue: openBookmarks()
case MenuButtons.history.rawValue: openHistory()
case MenuButtons.settings.rawValue: openSettings()
case MenuButtons.share.rawValue: openShareSheet()

default:
assertionFailure("No cell with \(cell.tag) tag.")
}
}

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

let nc = SettingsNavigationController(rootViewController: vc)
nc.modalPresentationStyle = .formSheet

nc.navigationBar.topItem?.leftBarButtonItem =
UIBarButtonItem(barButtonSystemItem: .done, target: nc, action: #selector(SettingsNavigationController.done))

dismiss(animated: true)
bvc.present(nc, animated: true)
}

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

let nc = SettingsNavigationController(rootViewController: vc)
nc.modalPresentationStyle = .formSheet

nc.navigationBar.topItem?.leftBarButtonItem =
UIBarButtonItem(barButtonSystemItem: .done, target: nc, action: #selector(SettingsNavigationController.done))

dismiss(animated: true)
bvc.present(nc, animated: true)
}

func openSettings() {
let vc = SettingsViewController(profile: bvc.profile, tabManager: bvc.tabManager)

let nc = SettingsNavigationController(rootViewController: vc)
nc.modalPresentationStyle = .formSheet

nc.navigationBar.topItem?.leftBarButtonItem =
UIBarButtonItem(barButtonSystemItem: .done, target: nc, action: #selector(SettingsNavigationController.done))

dismiss(animated: true)
bvc.present(nc, animated: true)
}

func openShareSheet() {
dismiss(animated: true)
bvc.tabToolbarDidPressShare()
}

@objc func dismissView() {
dismiss(animated: true)
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return MenuButtons.allCases.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let button = MenuButtons.allCases[indexPath.row]
let cell = UITableViewCell()

cell.textLabel?.text = button.title
cell.imageView?.image = button.icon
cell.tag = button.rawValue

return cell
}
}

extension MenuViewController: PopoverContentComponent {
var isPanToDismissEnabled: Bool { return false }

}
@@ -98,9 +98,6 @@ class SettingsViewController: TableViewController {
override func viewDidLoad() {

navigationItem.title = Strings.Settings
navigationItem.rightBarButtonItem = UIBarButtonItem(title: Strings.Done, style: .done, target: self, action: #selector(tappedDone))
navigationItem.rightBarButtonItem?.accessibilityIdentifier = "SettingsViewController.navigationItem.rightBarButtonItem"
navigationItem.rightBarButtonItem?.tintColor = BraveUX.BraveOrange

tableView.accessibilityIdentifier = "SettingsViewController.tableView"
tableView.separatorColor = UIConstants.TableViewSeparatorColor
@@ -128,10 +125,6 @@ class SettingsViewController: TableViewController {
return list
}

@objc private func tappedDone() {
settingsDelegate?.settingsDidFinish(self)
}

// MARK: - Sections
private lazy var generalSection: Section = {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.