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

MenuViewController refactor.

  • Loading branch information
iccub committed Apr 19, 2019
commit 1d9e0c301564a67c69a0820f27313afc4d44f0c0
@@ -8,7 +8,13 @@ import Shared

class MenuViewController: UITableViewController {

enum MenuButtons: Int {
private struct UX {
static let rowHeight: CGFloat = 45
static let separatorColor = UIColor(white: 0.0, alpha: 0.1)
static let topBottomInset: CGFloat = 5
}

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

var title: String {
@@ -35,19 +41,22 @@ class MenuViewController: UITableViewController {
static let allCases: [MenuButtons] = [.bookmarks, .history, .settings, .add, .share]
}

let bvc: BrowserViewController
let tab: Tab?
private let bvc: BrowserViewController
private let tab: Tab?

lazy var visibleButtons: [MenuButtons] = {
private lazy var visibleButtons: [MenuButtons] = {
let allButtons = MenuButtons.allCases

var allWithoutAddButton = allButtons
allWithoutAddButton.removeAll { $0 == .add || $0 == .share }
// Don't show url buttons if there is no url to pick(like on home screen)
var allWithoutUrlButtons = allButtons
allWithoutUrlButtons.removeAll { $0 == .add || $0 == .share }

guard let url = tab?.url, !url.isLocal else { return allWithoutAddButton }
guard let url = tab?.url, !url.isLocal else { return allWithoutUrlButtons }
return allButtons
}()

// MARK: - Init
init(bvc: BrowserViewController, tab: Tab?) {
self.bvc = bvc
self.tab = tab
@@ -60,14 +69,16 @@ class MenuViewController: UITableViewController {
fatalError()
}

// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
let topBottomInset: CGFloat = 5

tableView.separatorColor = UIColor(white: 0.0, alpha: 0.1)
tableView.rowHeight = 45
tableView.separatorColor = UX.separatorColor
tableView.rowHeight = UX.rowHeight

tableView.contentInset = UIEdgeInsets(top: topBottomInset, left: 0, bottom: topBottomInset, right: 0)
tableView.contentInset = UIEdgeInsets(top: UX.topBottomInset, left: 0,
bottom: UX.topBottomInset, right: 0)

tableView.showsVerticalScrollIndicator = false

@@ -76,18 +87,19 @@ class MenuViewController: UITableViewController {
UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1))

// TODO: Make the background view transparent with alpha 0.6
// simple settings its alpha doesn't seem to work.
// simple setting its alpha doesn't seem to work.
tableView.backgroundColor = #colorLiteral(red: 0.9529411765, green: 0.9529411765, blue: 0.9647058824, alpha: 1)
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

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

let size = CGSize(width: 200, height: tableView.rect(forSection: 0).height + UX.topBottomInset * 2)
preferredContentSize = size
}

// MARK: - Table view data source
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

guard let cell = tableView.cellForRow(at: indexPath) else { return }
@@ -104,92 +116,83 @@ class MenuViewController: UITableViewController {
}
}

func openBookmarks() {
let vc = BookmarksViewController(folder: nil, isPrivateBrowsing: PrivateBrowsingManager.shared.isPrivateBrowsing)
vc.toolbarUrlActionsDelegate = bvc
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return visibleButtons.count
}

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

let nc = SettingsNavigationController(rootViewController: vc)
nc.modalPresentationStyle = .formSheet
cell.textLabel?.text = button.title
cell.imageView?.image = button.icon
cell.tag = button.rawValue
cell.backgroundColor = .clear

nc.navigationBar.topItem?.rightBarButtonItem =
UIBarButtonItem(barButtonSystemItem: .done, target: nc, action: #selector(SettingsNavigationController.done))
return cell
}

// MARK: - Actions
private enum DoneButtonPosition { case left, right }
private typealias DoneButton = (style: UIBarButtonItem.SystemItem, position: DoneButtonPosition)

private func open(_ viewController: UIViewController, doneButton: DoneButton) {
let nav = SettingsNavigationController(rootViewController: viewController)
nav.modalPresentationStyle = .formSheet

let button = UIBarButtonItem(barButtonSystemItem: doneButton.style, target: nav, action: #selector(SettingsNavigationController.done))

switch doneButton.position {
case .left: nav.navigationBar.topItem?.leftBarButtonItem = button
case .right: nav.navigationBar.topItem?.rightBarButtonItem = button
}

dismiss(animated: true)

This comment has been minimized.

Copy link
@jhreis

jhreis Apr 22, 2019

Contributor

Maybe just call dismissView()?

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

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

open(vc, doneButton: DoneButton(style: .done, position: .right))
}

private func openAddBookmark() {
guard let title = tab?.displayTitle, let url = tab?.url?.absoluteString else { return }

let mode = BookmarkEditMode.addBookmark(title: title, url: url)

let vc = AddEditBookmarkTableViewController(mode: mode)
//vc.toolbarUrlActionsDelegate = bvc
let nc = SettingsNavigationController(rootViewController: vc)
nc.modalPresentationStyle = .formSheet

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

dismiss(animated: true)
bvc.present(nc, animated: true)
open(vc, doneButton: DoneButton(style: .cancel, position: .left))

}

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

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

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

dismiss(animated: true)
bvc.present(nc, animated: true)
open(vc, doneButton: DoneButton(style: .done, position: .right))
}

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

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

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

dismiss(animated: true)
bvc.present(nc, animated: true)
open(vc, doneButton: DoneButton(style: .done, position: .right))
}

func openShareSheet() {
private func openShareSheet() {
dismiss(animated: true)

This comment has been minimized.

Copy link
@jhreis

jhreis Apr 22, 2019

Contributor

Maybe just call dismissView()?

bvc.tabToolbarDidPressShare()
}

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

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

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

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

return cell
}
}

// MARK: - PopoverContentComponent
extension MenuViewController: PopoverContentComponent {
var isPanToDismissEnabled: Bool { return false }

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.