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

review

  • Loading branch information
iccub committed Apr 23, 2019
commit bc45a120d79e7d8b3b81ff2f52c5fffeef865022
@@ -103,9 +103,11 @@ extension UIView {
/// Returns a line with height of 1pt. Used to imitate a separator line in custom views.
static var separatorLine: UIView {
let view = UIView().then {
$0.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
$0.translatesAutoresizingMaskIntoConstraints = false
$0.addConstraint(NSLayoutConstraint(item: $0, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 0.5))
$0.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
$0.translatesAutoresizingMaskIntoConstraints = false
$0.addConstraint(NSLayoutConstraint(item: $0, attribute: .height, relatedBy: .equal,
toItem: nil, attribute: .notAnAttribute, multiplier: 1,
constant: 0.5))
}

return view
@@ -35,10 +35,11 @@ class AddEditBookmarkTableViewController: UITableViewController {
// MARK: - View setup
private lazy var saveButton: UIBarButtonItem = {

This comment has been minimized.

Copy link
@jhreis

jhreis Apr 22, 2019

Contributor

then?

let button = UIBarButtonItem()
button.target = self
button.action = #selector(save)
button.title = Strings.SaveButtonTitle
let button = UIBarButtonItem().then {
$0.target = self
$0.action = #selector(save)
$0.title = Strings.SaveButtonTitle
}

return button
}()
@@ -25,6 +25,10 @@ class AddEditHeaderView: UIView {

backgroundColor = .white
addSubview(mainStackView)

This comment has been minimized.

Copy link
@jhreis

jhreis Apr 22, 2019

Contributor

Does this consume the entire UI (e.g. 100% width/height)?

This comment has been minimized.

Copy link
@iccub

iccub Apr 23, 2019

Author Contributor

Kind of, we set frame in AddEditBookmarkTableViewController like this
header.frame = CGRect(x: 0, y: 0, width: tableView.bounds.width, height: tableView.bounds.height)

but then we use systemLayoutSizeFitting(UILayoutFittingCompressedSize) to resize its height

So it uses full tableview width, plus system fitting height


mainStackView.snp.makeConstraints {
$0.edges.equalTo(self)
}
}

@available(*, unavailable)
@@ -20,7 +20,7 @@ class BookmarkDetailsView: AddEditHeaderView, BookmarkFormFieldsProtocol {

let urlTextField: UITextField? = UITextField().then {

This comment has been minimized.

Copy link
@jhreis

jhreis Apr 22, 2019

Contributor

Don't think this needs to be optional, does it? We can then remove the this check.

This comment has been minimized.

Copy link
@iccub

iccub Apr 23, 2019

Author Contributor

This is optional by a BookmarkFormFieldsProtocol so I could abstract validateFields() for both Bookmark(url and title) and folder(title only)

$0.placeholder = Strings.BookmarkUrlPlaceholderText
$0.keyboardType = .webSearch
$0.keyboardType = .URL
$0.autocorrectionType = .no
$0.autocapitalizationType = .none
$0.smartDashesType = .no
@@ -56,21 +56,18 @@ class BookmarkDetailsView: AddEditHeaderView, BookmarkFormFieldsProtocol {

guard let urlTextField = urlTextField else { fatalError("Url text field must be set up") }

[UIView.separatorLine, contentStackView, UIView.separatorLine].forEach {
mainStackView.addArrangedSubview($0)
}
[UIView.separatorLine, contentStackView, UIView.separatorLine]
.forEach(mainStackView.addArrangedSubview)

[titleTextField, UIView.separatorLine, urlTextField].forEach {
textFieldsStackView.addArrangedSubview($0)
}
[titleTextField, UIView.separatorLine, urlTextField]
.forEach(textFieldsStackView.addArrangedSubview)

// Adding spacer view with zero width, UIStackView's spacing will take care
// about adding a left margin to the content stack view.
let emptySpacer = UIView.spacer(.horizontal, amount: 0)

[emptySpacer, faviconImageView, textFieldsStackView].forEach {
contentStackView.addArrangedSubview($0)
}
[emptySpacer, faviconImageView, textFieldsStackView]
.forEach(contentStackView.addArrangedSubview)

if let url = url, let favUrl = URL(string: url) {
faviconImageView.setIcon(nil, forURL: favUrl)
@@ -79,10 +76,6 @@ class BookmarkDetailsView: AddEditHeaderView, BookmarkFormFieldsProtocol {
titleTextField.text = title ?? Strings.NewBookmarkDefaultName
urlTextField.text = url ?? Strings.NewFolderDefaultName

mainStackView.snp.makeConstraints {
$0.edges.equalTo(self)
}

setupTextFieldTargets()
}

@@ -5,9 +5,8 @@
import Foundation
import Shared

protocol BookmarkFormFieldsProtocol where Self: UIView {
protocol BookmarkFormFieldsProtocol: UIView {
var titleTextField: UITextField { get }
/// Nil by default
var urlTextField: UITextField? { get }

var delegate: BookmarkDetailsViewDelegate? { get set }
@@ -19,18 +18,20 @@ extension BookmarkFormFieldsProtocol {
var urlTextField: UITextField? { return nil }

func validateFields() -> Bool {
let title = titleTextField.text

// Only title field is implemented
if urlTextField == nil {
guard let titleText = titleTextField.text else { return false }
return validateTitle(titleText)
return validateTitle(title)
}

guard let title = titleTextField.text, let url = urlTextField?.text else { return false }
guard let url = urlTextField?.text else { return false }

return validateTitle(title) && validateUrl(url)
}

private func validateTitle(_ title: String) -> Bool {
private func validateTitle(_ title: String?) -> Bool {
guard let title = title else { return false }
return !title.isEmpty
}

@@ -24,13 +24,12 @@ class FolderDetailsViewTableViewCell: AddEditHeaderView, BookmarkFormFieldsProto
convenience init(title: String?, viewHeight: CGFloat) {
self.init(frame: .zero)

[UIView.separatorLine, titleTextField, UIView.separatorLine].forEach {
mainStackView.addArrangedSubview($0)
}
[UIView.separatorLine, titleTextField, UIView.separatorLine]
.forEach(mainStackView.addArrangedSubview)

titleTextField.text = title ?? Strings.NewFolderDefaultName

mainStackView.snp.makeConstraints {
mainStackView.snp.remakeConstraints {
$0.edges.equalTo(self)
$0.height.equalTo(viewHeight)
}
@@ -6,12 +6,12 @@ import UIKit

class IndentedImageTableViewCell: UITableViewCell {

let mainStackView = UIStackView().then {
private let mainStackView = UIStackView().then {
$0.spacing = 8
$0.alignment = .fill
}

let folderNameStackView = UIStackView().then {
private let folderNameStackView = UIStackView().then {
$0.axis = .vertical
$0.distribution = .equalSpacing
}
@@ -27,11 +27,12 @@ class IndentedImageTableViewCell: UITableViewCell {
$0.textAlignment = .left
}

var spacerLine: UIView {
let view = UIView()
view.backgroundColor = .lightGray
view.translatesAutoresizingMaskIntoConstraints = false
view.addConstraint(NSLayoutConstraint(item: view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 0.5))
private var spacerLine: UIView {
let view = UIView().then {
$0.backgroundColor = .lightGray
$0.translatesAutoresizingMaskIntoConstraints = false
$0.addConstraint(NSLayoutConstraint(item: $0, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 0.5))
}

return view
}
@@ -50,9 +51,8 @@ class IndentedImageTableViewCell: UITableViewCell {

let transparentLine = spacerLine
transparentLine.backgroundColor = .clear
folderNameStackView.addArrangedSubview(transparentLine)
folderNameStackView.addArrangedSubview(folderName)
folderNameStackView.addArrangedSubview(spacerLine)

[transparentLine, folderName, spacerLine].forEach(folderNameStackView.addArrangedSubview)

mainStackView.addArrangedSubview(folderNameStackView)

@@ -14,7 +14,7 @@ class MenuViewController: UITableViewController {
static let topBottomInset: CGFloat = 5
}

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

var title: String {
@@ -36,9 +36,6 @@ class MenuViewController: UITableViewController {
case .share: return #imageLiteral(resourceName: "nav-share")
}
}

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

private let bvc: BrowserViewController
@@ -104,15 +101,17 @@ class MenuViewController: UITableViewController {

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.add.rawValue: openAddBookmark()
case MenuButtons.share.rawValue: openShareSheet()

default:
guard let button = MenuButtons(rawValue: cell.tag) else {
assertionFailure("No cell with \(cell.tag) tag.")
return
}

switch button {
case .bookmarks: openBookmarks()
case .history: openHistory()
case .settings: openSettings()
case .add: openAddBookmark()
case .share: openShareSheet()
}
}

@@ -148,7 +147,7 @@ class MenuViewController: UITableViewController {
case .right: nav.navigationBar.topItem?.rightBarButtonItem = button
}

dismiss(animated: true)
dismissView()
bvc.present(nav, animated: true)
}

@@ -182,7 +181,7 @@ class MenuViewController: UITableViewController {
}

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

@@ -8,7 +8,7 @@ import BraveShared
import Data

private struct URLBarViewUX {
static let LocationLeftPadding: CGFloat = 8
static let LocationPadding: CGFloat = 8
static let Padding: CGFloat = 10
static let LocationHeight: CGFloat = 34
static let ButtonHeight: CGFloat = 44
@@ -279,8 +279,8 @@ class URLBarView: UIView {
locationTextField.attributedPlaceholder = self.locationView.placeholder
locationContainer.addSubview(locationTextField)
locationTextField.snp.remakeConstraints { make in
let insets = UIEdgeInsets(top: 0, left: URLBarViewUX.LocationLeftPadding,
bottom: 0, right: URLBarViewUX.LocationLeftPadding)
let insets = UIEdgeInsets(top: 0, left: URLBarViewUX.LocationPadding,
bottom: 0, right: URLBarViewUX.LocationPadding)
make.edges.equalTo(self.locationView).inset(insets)
}

@@ -124,8 +124,6 @@ public final class Bookmark: NSManagedObject, WebsitePresentable, Syncable, CRUD

fetchRequest.predicate = predicate

//"parentFolder == %@"
return NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context,
sectionNameKeyPath: nil, cacheName: nil)
}
@@ -146,9 +144,7 @@ public final class Bookmark: NSManagedObject, WebsitePresentable, Syncable, CRUD
// MARK: Update
public func update(customTitle: String?, url: String?) {
// Title can't be empty, except when coming from Sync
let isTitleEmpty = customTitle?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true
if customTitle == nil || isTitleEmpty { return }
if !containsCustomTitle { return }
updateInternal(customTitle: customTitle, url: url)
}

@@ -158,11 +154,16 @@ public final class Bookmark: NSManagedObject, WebsitePresentable, Syncable, CRUD
}

public func updateWithNewLocation(customTitle: String?, url: String?, location: Bookmark?) {

This comment has been minimized.

Copy link
@jhreis

jhreis Apr 22, 2019

Contributor

This is almost identical to update( above. Should abstract implementation. This could honestly even be a string helper.
Something super generic would be:
containsCharacters(in: CharacterSet) -> Bool

and could call:
myText.containsCharacters(in: .whitespacesAndNewlines.invert())

Otherwise could do something more like:
hasVisibleCharacters

Lastly, since this logic is only really used in this class, could just create a private function 😆

This comment has been minimized.

Copy link
@iccub

iccub Apr 23, 2019

Author Contributor

Made a private function

let isTitleEmpty = customTitle?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true
if customTitle == nil || isTitleEmpty { return }
if !containsCustomTitle { return }

updateInternal(customTitle: customTitle, url: url, location: .new(location: location))
}

// Title can't be empty, except when coming from Sync
private var containsCustomTitle: Bool {
return customTitle?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false
}

public class func migrateBookmarkOrders() {
DataController.perform { context in
migrateOrder(forFavorites: true, context: context)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.