Commit 008cb81f authored by sczs's avatar sczs Committed by Commit Bot

[ios] Changes BookmarkFolderVC style to UIRefresh.

- Adds the new Folder assets. (For the regular folder I replaced some un-used assets)
- Changes BookmarkFolderVC to match the UIRefresh styling.
- Creates TableViewBookmarkFolderCell with the UIRefresh styling.

Screenshot:
https://drive.google.com/open?id=1Pq5CtxhnfjA3FDyWEN-E4KzE43kJt0LZ

Bug: 839451
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ia76fd4173f5f1c4f9ff9e75a4e87b675d20c81c2
Reviewed-on: https://chromium-review.googlesource.com/1066939Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560746}
parent cdb05770
......@@ -53,6 +53,7 @@ source_set("bookmarks") {
"resources:bookmark_black_select",
"resources:bookmark_blue_check",
"resources:bookmark_blue_folder",
"resources:bookmark_blue_new_folder",
"resources:bookmark_gray_back",
"resources:bookmark_gray_check",
"resources:bookmark_gray_close",
......
......@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h"
#import "ios/chrome/browser/experimental_flags.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_navigation_controller.h"
......@@ -113,9 +114,15 @@ using bookmarks::BookmarkNode;
DCHECK(bookmarkModel);
DCHECK(bookmarkModel->loaded());
DCHECK(selectedFolder == NULL || selectedFolder->is_folder());
self =
[super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleWithAppBar];
if (experimental_flags::IsBookmarksUIRebootEnabled()) {
self =
[super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
} else {
self =
[super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleWithAppBar];
}
if (self) {
_allowsCancel = allowsCancel;
_allowsNewFolders = allowsNewFolders;
......@@ -187,12 +194,17 @@ using bookmarks::BookmarkNode;
// Configure the table view.
self.tableView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// To support the pre UIRefresh we need to set the insets since
// UITableViewCell lines itself up with the tableView separator insets. The
// following line won't be needed for UIRefresh.
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 51, 0, 0)];
if (experimental_flags::IsBookmarksUIRebootEnabled()) {
// Add a tableFooterView in order to disable separators at the bottom of the
// tableView.
self.tableView.tableFooterView = [[UIView alloc] init];
} else {
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// To support the pre UIRefresh we need to set the insets since
// UITableViewCell lines itself up with the tableView separator insets. The
// following line won't be needed for UIRefresh.
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 51, 0, 0)];
}
}
- (void)viewWillAppear:(BOOL)animated {
......@@ -391,19 +403,30 @@ using bookmarks::BookmarkNode;
[self.tableViewModel
removeSectionWithIdentifier:SectionIdentifierBookmarkFolders];
// Add default add Folder section if needed.
// Creates Folders Section
[self.tableViewModel
addSectionWithIdentifier:SectionIdentifierBookmarkFolders];
// Adds default "Add Folder" item if needed.
if ([self shouldShowDefaultSection]) {
[self.tableViewModel addSectionWithIdentifier:SectionIdentifierAddFolder];
BookmarkFolderItem* createFolderItem =
[[BookmarkFolderItem alloc] initWithType:ItemTypeBookmarkFolder
style:BookmarkFolderStyleNewFolder];
[self.tableViewModel addItem:createFolderItem
toSectionWithIdentifier:SectionIdentifierAddFolder];
// On UIRefresh we add the "Add Folder" Item to the same section as the rest
// of the folder entries.
if (experimental_flags::IsBookmarksUIRebootEnabled()) {
[self.tableViewModel addItem:createFolderItem
toSectionWithIdentifier:SectionIdentifierBookmarkFolders];
} else {
[self.tableViewModel
insertSectionWithIdentifier:SectionIdentifierAddFolder
atIndex:0];
[self.tableViewModel addItem:createFolderItem
toSectionWithIdentifier:SectionIdentifierAddFolder];
}
}
// Add Folders entries.
[self.tableViewModel
addSectionWithIdentifier:SectionIdentifierBookmarkFolders];
for (NSUInteger row = 0; row < _folders.size(); row++) {
const BookmarkNode* folderNode = self.folders[row];
BookmarkFolderItem* folderItem = [[BookmarkFolderItem alloc]
......
......@@ -8,6 +8,8 @@
#import <CoreGraphics/CoreGraphics.h>
#import <Foundation/Foundation.h>
// UIToolbar accessibility constants.
// Accessibility identifier of the BookmarkEditVC toolbar delete button.
extern NSString* const kBookmarkEditDeleteButtonIdentifier;
// Accessibility identifier of the BookmarkFolderEditorVC toolbar delete button.
......@@ -21,7 +23,7 @@ extern NSString* const kBookmarkHomeTrailingButtonIdentifier;
// Accessibility identifier of the BookmarkHomeVC UIToolbar.
extern NSString* const kBookmarkHomeUIToolbarIdentifier;
// Cell constants.
// Cell Layout constants.
// The space between UIViews inside the cell.
extern const CGFloat kBookmarkCellViewSpacing;
......@@ -34,4 +36,9 @@ extern const CGFloat kBookmarkCellHorizontalTrailingInset;
// The horizontal space between the Cell content and its accessory view.
extern const CGFloat kBookmarkCellHorizontalAccessoryViewSpacing;
// Cell accessibility constants.
// Accessibility identifier of the BookmarkHomeVC UIToolbar.
extern NSString* const kBookmarkCreateNewFolderCellIdentifier;
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UI_CONSTANTS_H_
......@@ -26,3 +26,6 @@ const CGFloat kBookmarkCellVerticalInset = 11.0f;
const CGFloat kBookmarkCellHorizontalLeadingInset = 16.0f;
const CGFloat kBookmarkCellHorizontalTrailingInset = 24.0f;
const CGFloat kBookmarkCellHorizontalAccessoryViewSpacing = 11.0f;
NSString* const kBookmarkCreateNewFolderCellIdentifier =
@"kBookmarkCreateNewFolderCellIdentifier";
......@@ -33,6 +33,23 @@ typedef NS_ENUM(NSInteger, BookmarkFolderStyle) {
@end
// TableViewCell that displays BookmarkFolderItem data.
@interface TableViewBookmarkFolderCell : UITableViewCell
// The leading constraint used to set the cell's leading indentation. The
// default indentationLevel property doesn't affect any custom Cell subviews,
// changing |indentationConstraint| constant property will.
@property(nonatomic, strong, readonly)
NSLayoutConstraint* indentationConstraint;
// The folder image displayed by this cell.
@property(nonatomic, strong) UIImageView* folderImageView;
// The folder title displayed by this cell.
@property(nonatomic, strong) UILabel* folderTitleLabel;
// Whether the cell is displaying a checkmark.
@property(nonatomic, assign, getter=isChecked) BOOL checked;
@end
// TableViewCell that displays BookmarkFolderItem data.
@interface LegacyTableViewBookmarkFolderCell : UITableViewCell
......
......@@ -5,6 +5,8 @@
#import "ios/chrome/browser/ui/bookmarks/cells/bookmark_folder_item.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/experimental_flags.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#import "ios/chrome/browser/ui/rtl_geometry.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -23,6 +25,8 @@ const CGFloat kImageViewLeadingOffset = 1.0;
// Width by which to indent folder cell's content. This is multiplied by the
// |indentationLevel| of the cell.
const CGFloat kFolderCellIndentationWidth = 32.0;
// The amount in points by which to inset horizontally the cell contents.
const CGFloat kFolderCellHorizonalInset = 17.0;
} // namespace
#pragma mark - BookmarkFolderItem
......@@ -39,7 +43,11 @@ const CGFloat kFolderCellIndentationWidth = 32.0;
- (instancetype)initWithType:(NSInteger)type style:(BookmarkFolderStyle)style {
if ((self = [super initWithType:type])) {
self.cellClass = [LegacyTableViewBookmarkFolderCell class];
if (experimental_flags::IsBookmarksUIRebootEnabled()) {
self.cellClass = [TableViewBookmarkFolderCell class];
} else {
self.cellClass = [LegacyTableViewBookmarkFolderCell class];
}
self.style = style;
}
return self;
......@@ -48,34 +56,154 @@ const CGFloat kFolderCellIndentationWidth = 32.0;
- (void)configureCell:(UITableViewCell*)cell
withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:cell withStyler:styler];
LegacyTableViewBookmarkFolderCell* folderCell =
base::mac::ObjCCastStrict<LegacyTableViewBookmarkFolderCell>(cell);
switch (self.style) {
case BookmarkFolderStyleNewFolder: {
folderCell.textLabel.text =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_CREATE_GROUP);
folderCell.imageView.image =
[UIImage imageNamed:@"bookmark_gray_new_folder"];
folderCell.accessibilityIdentifier = @"Create New Folder";
break;
if (experimental_flags::IsBookmarksUIRebootEnabled()) {
TableViewBookmarkFolderCell* folderCell =
base::mac::ObjCCastStrict<TableViewBookmarkFolderCell>(cell);
switch (self.style) {
case BookmarkFolderStyleNewFolder: {
folderCell.folderTitleLabel.text =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_CREATE_GROUP);
folderCell.folderImageView.image =
[UIImage imageNamed:@"bookmark_blue_new_folder"];
folderCell.accessibilityIdentifier =
kBookmarkCreateNewFolderCellIdentifier;
break;
}
case BookmarkFolderStyleFolderEntry: {
folderCell.folderTitleLabel.text = self.title;
folderCell.accessibilityIdentifier = self.title;
folderCell.accessibilityLabel = self.title;
folderCell.checked = self.isCurrentFolder;
// In order to indent the cell's content we need to modify its
// indentation constraint.
folderCell.indentationConstraint.constant =
folderCell.indentationConstraint.constant +
kFolderCellIndentationWidth * self.indentationLevel;
folderCell.folderImageView.image =
[UIImage imageNamed:@"bookmark_blue_folder"];
break;
}
}
case BookmarkFolderStyleFolderEntry: {
folderCell.textLabel.text = self.title;
folderCell.accessibilityIdentifier = self.title;
folderCell.accessibilityLabel = self.title;
folderCell.checked = self.isCurrentFolder;
folderCell.indentationLevel = self.indentationLevel;
folderCell.indentationWidth = kFolderCellIndentationWidth;
folderCell.imageView.image =
[UIImage imageNamed:@"bookmark_gray_folder_new"];
break;
} else {
LegacyTableViewBookmarkFolderCell* folderCell =
base::mac::ObjCCastStrict<LegacyTableViewBookmarkFolderCell>(cell);
switch (self.style) {
case BookmarkFolderStyleNewFolder: {
folderCell.textLabel.text =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_CREATE_GROUP);
folderCell.imageView.image =
[UIImage imageNamed:@"bookmark_gray_new_folder"];
folderCell.accessibilityIdentifier = @"Create New Folder";
break;
}
case BookmarkFolderStyleFolderEntry: {
folderCell.textLabel.text = self.title;
folderCell.accessibilityIdentifier = self.title;
folderCell.accessibilityLabel = self.title;
folderCell.checked = self.isCurrentFolder;
folderCell.indentationLevel = self.indentationLevel;
folderCell.indentationWidth = kFolderCellIndentationWidth;
folderCell.imageView.image =
[UIImage imageNamed:@"bookmark_gray_folder_new"];
break;
}
}
}
}
@end
#pragma mark - TableViewBookmarkFolderCell
@interface TableViewBookmarkFolderCell ()
@property(nonatomic, strong, readwrite)
NSLayoutConstraint* indentationConstraint;
@end
@implementation TableViewBookmarkFolderCell
@synthesize checked = _checked;
@synthesize folderImageView = _folderImageView;
@synthesize folderTitleLabel = _folderTitleLabel;
@synthesize indentationConstraint = _indentationConstraint;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleGray;
self.accessibilityTraits |= UIAccessibilityTraitButton;
self.folderImageView = [[UIImageView alloc] init];
self.folderImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.folderImageView
setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
[self.folderImageView
setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:
UILayoutConstraintAxisHorizontal];
self.folderTitleLabel = [[UILabel alloc] init];
self.folderTitleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
self.folderTitleLabel.adjustsFontForContentSizeCategory = YES;
[self.folderTitleLabel
setContentHuggingPriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
// Container StackView.
UIStackView* horizontalStack =
[[UIStackView alloc] initWithArrangedSubviews:@[
self.folderImageView, self.folderTitleLabel
]];
horizontalStack.axis = UILayoutConstraintAxisHorizontal;
horizontalStack.spacing = kBookmarkCellViewSpacing;
horizontalStack.distribution = UIStackViewDistributionFill;
horizontalStack.alignment = UIStackViewAlignmentCenter;
horizontalStack.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:horizontalStack];
// Set up constraints.
self.indentationConstraint = [horizontalStack.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kFolderCellHorizonalInset];
[NSLayoutConstraint activateConstraints:@[
[horizontalStack.topAnchor
constraintEqualToAnchor:self.contentView.topAnchor
constant:kBookmarkCellVerticalInset],
[horizontalStack.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor
constant:-kBookmarkCellVerticalInset],
[horizontalStack.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kFolderCellHorizonalInset],
self.indentationConstraint,
]];
}
return self;
}
- (void)setChecked:(BOOL)checked {
if (checked != _checked) {
_checked = checked;
UIImageView* checkImageView =
checked ? [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"bookmark_blue_check"]]
: nil;
self.accessoryView = checkImageView;
}
}
- (void)prepareForReuse {
[super prepareForReuse];
self.checked = NO;
self.indentationWidth = 0;
self.imageView.image = nil;
self.indentationConstraint.constant = kFolderCellHorizonalInset;
}
@end
#pragma mark - LegacyTableViewBookmarkFolderCell
@implementation LegacyTableViewBookmarkFolderCell
......
......@@ -76,6 +76,15 @@ imageset("bookmark_blue_folder") {
]
}
imageset("bookmark_blue_new_folder") {
sources = [
"bookmark_blue_new_folder.imageset/Contents.json",
"bookmark_blue_new_folder.imageset/bookmark_blue_new_folder.png",
"bookmark_blue_new_folder.imageset/bookmark_blue_new_folder@2x.png",
"bookmark_blue_new_folder.imageset/bookmark_blue_new_folder@3x.png",
]
}
imageset("bookmark_gray_back") {
sources = [
"bookmark_gray_back.imageset/Contents.json",
......
{
"images": [
{
"idiom": "universal",
"scale": "1x",
"filename": "bookmark_blue_new_folder.png"
},
{
"idiom": "universal",
"scale": "2x",
"filename": "bookmark_blue_new_folder@2x.png"
},
{
"idiom": "universal",
"scale": "3x",
"filename": "bookmark_blue_new_folder@3x.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment