Commit 8376eb4a authored by sczs's avatar sczs Committed by Commit Bot

[ios] Moves EditBookmark InvalidURL label to footer.

As per UX request, this is being moved to a tableView footer instead of the cell itself.

Screenshot:
https://drive.google.com/open?id=1zK2X9e-__l3CurjcB7Z3zgUIxTgSxXuJ

Bug: 843827
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I977a625d10c108efa4f0794a2aafd77a32b8e495
Reviewed-on: https://chromium-review.googlesource.com/1142527Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576394}
parent faee83df
......@@ -30,8 +30,10 @@
#import "ios/chrome/browser/ui/image_util/image_util.h"
#import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
......@@ -71,7 +73,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeName = kItemTypeEnumZero,
ItemTypeFolder,
ItemTypeURL,
ItemTypeInvalidURLFooter,
};
// The text color for the invalid URL label.
const CGFloat kInvalidURLTextColor = 0xEA4335;
} // namespace
@interface BookmarkEditViewController ()<BookmarkFolderViewControllerDelegate,
......@@ -114,6 +120,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
@property(nonatomic, strong) BookmarkParentFolderItem* folderItem;
@property(nonatomic, strong) BookmarkTextFieldItem* URLItem;
// YES if the URL item is displaying a valid URL.
@property(nonatomic, assign) BOOL displayingValidURL;
// Reports the changes to the delegate, that has the responsibility to save the
// bookmark.
- (void)commitBookmarkChanges;
......@@ -153,6 +162,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
@synthesize bookmark = _bookmark;
@synthesize bookmarkModel = _bookmarkModel;
@synthesize delegate = _delegate;
@synthesize displayingValidURL = _displayingValidURL;
@synthesize folder = _folder;
@synthesize folderViewController = _folderViewController;
@synthesize browserState = _browserState;
......@@ -207,7 +217,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
self.tableView.estimatedRowHeight = 88.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.sectionHeaderHeight = 0;
self.tableView.sectionFooterHeight = 0;
self.view.accessibilityIdentifier = kBookmarkEditViewContainerIdentifier;
if (experimental_flags::IsBookmarksUIRebootEnabled()) {
......@@ -406,6 +415,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
self.URLItem.delegate = self;
[model addItem:self.URLItem toSectionWithIdentifier:SectionIdentifierInfo];
TableViewHeaderFooterItem* errorFooter =
[[TableViewHeaderFooterItem alloc] initWithType:ItemTypeInvalidURLFooter];
[model setFooter:errorFooter forSectionWithIdentifier:SectionIdentifierInfo];
self.displayingValidURL = YES;
// Save button state.
[self updateSaveButtonState];
}
......@@ -472,21 +486,20 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)textDidChangeForItem:(BookmarkTextFieldItem*)item {
[self updateSaveButtonState];
if (experimental_flags::IsBookmarksUIRebootEnabled()) {
NSIndexPath* textFieldIndexPath =
[self.tableViewModel indexPathForItemType:item.type
sectionIdentifier:SectionIdentifierInfo];
UITableViewCell* cell =
[self.tableView cellForRowAtIndexPath:textFieldIndexPath];
BookmarkTextFieldCell* URLCell =
base::mac::ObjCCastStrict<BookmarkTextFieldCell>(cell);
// Update the URLCell valid state if it has changed.
if ([self inputURLIsValid] != URLCell.validState) {
[self.tableView beginUpdates];
URLCell.validState = [self inputURLIsValid];
[self.tableView endUpdates];
}
if (experimental_flags::IsBookmarksUIRebootEnabled() &&
(self.displayingValidURL != [self inputURLIsValid])) {
self.displayingValidURL = [self inputURLIsValid];
UITableViewHeaderFooterView* footer = [self.tableView
footerViewForSection:[self.tableViewModel sectionForSectionIdentifier:
SectionIdentifierInfo]];
NSString* footerText =
[self inputURLIsValid]
? @""
: l10n_util::GetNSString(
IDS_IOS_BOOKMARK_URL_FIELD_VALIDATION_FAILED);
[self.tableView beginUpdates];
footer.textLabel.text = footerText;
[self.tableView endUpdates];
}
}
......@@ -542,6 +555,21 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self moveBookmark];
}
- (UIView*)tableView:(UITableView*)tableView
viewForFooterInSection:(NSInteger)section {
UIView* footerView =
[super tableView:tableView viewForFooterInSection:section];
if (section ==
[self.tableViewModel sectionForSectionIdentifier:SectionIdentifierInfo]) {
UITableViewHeaderFooterView* headerFooterView =
base::mac::ObjCCastStrict<UITableViewHeaderFooterView>(footerView);
headerFooterView.textLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
headerFooterView.textLabel.textColor = UIColorFromRGB(kInvalidURLTextColor);
}
return footerView;
}
#pragma mark - BookmarkFolderViewControllerDelegate
- (void)folderPicker:(BookmarkFolderViewController*)folderPicker
......
......@@ -42,10 +42,6 @@
// Text field to display the title or the URL of the bookmark node.
@property(nonatomic, strong) UITextField* textField;
// If |NO| changes the cell appearance to reflect that |self.textfield| is on an
// invalid state.
@property(nonatomic, assign) BOOL validState;
@end
@interface LegacyBookmarkTextFieldCell : UITableViewCell
......
......@@ -56,7 +56,6 @@
cell.textField.accessibilityLabel = self.text;
cell.textField.accessibilityIdentifier = [NSString
stringWithFormat:@"%@_textField", self.accessibilityIdentifier];
cell.validState = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else {
LegacyBookmarkTextFieldCell* cell =
......@@ -86,15 +85,9 @@
#pragma mark - BookmarkTextFieldCell
@interface BookmarkTextFieldCell ()
@property(nonatomic, strong) UILabel* invalidURLLabel;
@end
@implementation BookmarkTextFieldCell
@synthesize textField = _textField;
@synthesize titleLabel = _titleLabel;
@synthesize invalidURLLabel = _invalidURLLabel;
@synthesize validState = _validState;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
......@@ -138,44 +131,21 @@
[horizontalStack
setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
// Invalid URL label
self.invalidURLLabel = [[UILabel alloc] init];
self.invalidURLLabel.text =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_URL_FIELD_VALIDATION_FAILED);
self.invalidURLLabel.textColor = [UIColor redColor];
self.invalidURLLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
self.invalidURLLabel.adjustsFontForContentSizeCategory = YES;
[self.invalidURLLabel
setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
[self.invalidURLLabel
setContentHuggingPriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
// Vertical StackView.
UIStackView* verticalStack = [[UIStackView alloc]
initWithArrangedSubviews:@[ horizontalStack, self.invalidURLLabel ]];
verticalStack.axis = UILayoutConstraintAxisVertical;
verticalStack.translatesAutoresizingMaskIntoConstraints = NO;
[verticalStack
setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
[self.contentView addSubview:verticalStack];
horizontalStack.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:horizontalStack];
// Set up constraints.
[NSLayoutConstraint activateConstraints:@[
[verticalStack.topAnchor
[horizontalStack.topAnchor
constraintEqualToAnchor:self.contentView.topAnchor
constant:kBookmarkCellVerticalInset],
[verticalStack.bottomAnchor
[horizontalStack.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor
constant:-kBookmarkCellVerticalInset],
[verticalStack.leadingAnchor
[horizontalStack.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kBookmarkCellHorizontalLeadingInset],
[verticalStack.trailingAnchor
[horizontalStack.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kBookmarkCellHorizontalTrailingInset],
]];
......@@ -183,24 +153,12 @@
return self;
}
- (void)setValidState:(BOOL)validState {
_validState = validState;
if (validState) {
self.invalidURLLabel.hidden = YES;
self.textField.textColor = [UIColor lightGrayColor];
} else {
self.invalidURLLabel.hidden = NO;
self.textField.textColor = [UIColor redColor];
}
}
- (void)prepareForReuse {
[super prepareForReuse];
[self.textField resignFirstResponder];
[self.textField removeTarget:nil
action:NULL
forControlEvents:UIControlEventAllEvents];
self.validState = YES;
self.textField.delegate = nil;
self.textField.text = nil;
}
......
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