Commit b1d6cfe1 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Add disclosure accessory view to Recent Tabs section headers.

Only adds the accessory. No rotation happens when toggling between collapsing/showing the sections.
Rotation will be in future CL.

Bug: 825017
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Idca5bd47ca06db6ef394b40690e2c3dd0c83345b
Reviewed-on: https://chromium-review.googlesource.com/987094
Commit-Queue: Chris Lu <thegreenfrog@google.com>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548593}
parent d271f4b2
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
#include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h"
#import "ios/chrome/browser/ui/settings/sync_utils/sync_presenter.h" #import "ios/chrome/browser/ui/settings/sync_utils/sync_presenter.h"
#import "ios/chrome/browser/ui/signin_interaction/public/signin_presenter.h" #import "ios/chrome/browser/ui/signin_interaction/public/signin_presenter.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_disclosure_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_signin_promo_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_signin_promo_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_url_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_url_item.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
...@@ -178,8 +178,9 @@ const int kRelativeTimeMaxHours = 4; ...@@ -178,8 +178,9 @@ const int kRelativeTimeMaxHours = 4;
[model addSectionWithIdentifier:SectionIdentifierRecentlyClosedTabs]; [model addSectionWithIdentifier:SectionIdentifierRecentlyClosedTabs];
[model setSectionIdentifier:SectionIdentifierRecentlyClosedTabs [model setSectionIdentifier:SectionIdentifierRecentlyClosedTabs
collapsedKey:kRecentlyClosedCollapsedKey]; collapsedKey:kRecentlyClosedCollapsedKey];
TableViewTextHeaderFooterItem* header = [[TableViewTextHeaderFooterItem alloc] TableViewDisclosureHeaderFooterItem* header =
initWithType:ItemTypeRecentlyClosedHeader]; [[TableViewDisclosureHeaderFooterItem alloc]
initWithType:ItemTypeRecentlyClosedHeader];
header.text = l10n_util::GetNSString(IDS_IOS_RECENT_TABS_RECENTLY_CLOSED); header.text = l10n_util::GetNSString(IDS_IOS_RECENT_TABS_RECENTLY_CLOSED);
[model setHeader:header [model setHeader:header
forSectionWithIdentifier:SectionIdentifierRecentlyClosedTabs]; forSectionWithIdentifier:SectionIdentifierRecentlyClosedTabs];
...@@ -283,8 +284,8 @@ const int kRelativeTimeMaxHours = 4; ...@@ -283,8 +284,8 @@ const int kRelativeTimeMaxHours = 4;
NSString* sessionCollapsedKey = base::SysUTF8ToNSString(session->tag); NSString* sessionCollapsedKey = base::SysUTF8ToNSString(session->tag);
[model setSectionIdentifier:sessionIdentifier [model setSectionIdentifier:sessionIdentifier
collapsedKey:sessionCollapsedKey]; collapsedKey:sessionCollapsedKey];
TableViewTextHeaderFooterItem* header = TableViewDisclosureHeaderFooterItem* header =
[[TableViewTextHeaderFooterItem alloc] [[TableViewDisclosureHeaderFooterItem alloc]
initWithType:ItemTypeSessionHeader]; initWithType:ItemTypeSessionHeader];
header.text = base::SysUTF8ToNSString(session->name); header.text = base::SysUTF8ToNSString(session->name);
header.subtitleText = l10n_util::GetNSStringF( header.subtitleText = l10n_util::GetNSStringF(
...@@ -374,8 +375,9 @@ const int kRelativeTimeMaxHours = 4; ...@@ -374,8 +375,9 @@ const int kRelativeTimeMaxHours = 4;
[model addSectionWithIdentifier:SectionIdentifierOtherDevices]; [model addSectionWithIdentifier:SectionIdentifierOtherDevices];
[model setSectionIdentifier:SectionIdentifierOtherDevices [model setSectionIdentifier:SectionIdentifierOtherDevices
collapsedKey:kOtherDeviceCollapsedKey]; collapsedKey:kOtherDeviceCollapsedKey];
TableViewTextHeaderFooterItem* header = [[TableViewTextHeaderFooterItem alloc] TableViewDisclosureHeaderFooterItem* header =
initWithType:ItemTypeRecentlyClosedHeader]; [[TableViewDisclosureHeaderFooterItem alloc]
initWithType:ItemTypeRecentlyClosedHeader];
header.text = l10n_util::GetNSString(IDS_IOS_RECENT_TABS_OTHER_DEVICES); header.text = l10n_util::GetNSString(IDS_IOS_RECENT_TABS_OTHER_DEVICES);
[model setHeader:header [model setHeader:header
forSectionWithIdentifier:SectionIdentifierOtherDevices]; forSectionWithIdentifier:SectionIdentifierOtherDevices];
...@@ -776,8 +778,9 @@ const int kRelativeTimeMaxHours = 4; ...@@ -776,8 +778,9 @@ const int kRelativeTimeMaxHours = 4;
sectionForSectionIdentifier:self.lastTappedHeaderSectionIdentifier]; sectionForSectionIdentifier:self.lastTappedHeaderSectionIdentifier];
UITableViewHeaderFooterView* headerView = UITableViewHeaderFooterView* headerView =
[self.tableView headerViewForSection:section]; [self.tableView headerViewForSection:section];
TableViewTextHeaderFooterView* headerTextView = TableViewDisclosureHeaderFooterView* headerTextView =
base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerView); base::mac::ObjCCastStrict<TableViewDisclosureHeaderFooterView>(
headerView);
[headerTextView animateHighlight]; [headerTextView animateHighlight];
} }
} }
...@@ -832,8 +835,9 @@ const int kRelativeTimeMaxHours = 4; ...@@ -832,8 +835,9 @@ const int kRelativeTimeMaxHours = 4;
sectionForSectionIdentifier:self.lastTappedHeaderSectionIdentifier]; sectionForSectionIdentifier:self.lastTappedHeaderSectionIdentifier];
UITableViewHeaderFooterView* headerView = UITableViewHeaderFooterView* headerView =
[self.tableView headerViewForSection:section]; [self.tableView headerViewForSection:section];
TableViewTextHeaderFooterView* headerTextView = TableViewDisclosureHeaderFooterView* headerTextView =
base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerView); base::mac::ObjCCastStrict<TableViewDisclosureHeaderFooterView>(
headerView);
[headerTextView animateHighlight]; [headerTextView animateHighlight];
web::ContextMenuParams params; web::ContextMenuParams params;
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
source_set("cells") { source_set("cells") {
sources = [ sources = [
"table_view_cells_constants.h",
"table_view_cells_constants.mm",
"table_view_disclosure_header_footer_item.h",
"table_view_disclosure_header_footer_item.mm",
"table_view_header_footer_item.h", "table_view_header_footer_item.h",
"table_view_header_footer_item.mm", "table_view_header_footer_item.mm",
"table_view_item.h", "table_view_item.h",
...@@ -19,7 +23,9 @@ source_set("cells") { ...@@ -19,7 +23,9 @@ source_set("cells") {
] ]
deps = [ deps = [
"resources:table_view_cell_chevron",
"//base", "//base",
"//ios/chrome/browser/ui:ui_util",
"//ios/chrome/browser/ui/authentication:authentication_ui", "//ios/chrome/browser/ui/authentication:authentication_ui",
"//ios/chrome/browser/ui/list_model", "//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/table_view:styler", "//ios/chrome/browser/ui/table_view:styler",
......
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
{ {
"idiom": "universal", "idiom": "universal",
"scale": "2x", "scale": "2x",
"filename": "table_view_cell_chevron_@2x.png" "filename": "table_view_cell_chevron@2x.png"
}, },
{ {
"idiom": "universal", "idiom": "universal",
"scale": "3x", "scale": "3x",
"filename": "table_view_cell_chevron_@3x.png" "filename": "table_view_cell_chevron@3x.png"
} }
], ],
"info": { "info": {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_CELLS_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_CELLS_CONSTANTS_H_
#import <UIKit/UIKit.h>
// The spacing between views inside of a cell.
extern const CGFloat kTableViewCellViewSpacing;
// The vertical spacing between text labels in a stackView.
extern const CGFloat kTableViewVerticalLabelStackSpacing;
// Animation Duration for highlighting selected section header.
extern const CGFloat kTableViewCellSelectionAnimationDuration;
// Color and alpha used to highlight a cell with a middle gray color to
// represent a user tap.
extern const CGFloat kTableViewHighlightedCellColor;
extern const CGFloat kTableViewHighlightedCellColorAlpha;
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_CELLS_CONSTANTS_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
const CGFloat kTableViewCellViewSpacing = 16.0;
const CGFloat kTableViewVerticalLabelStackSpacing = 2.0;
const CGFloat kTableViewCellSelectionAnimationDuration = 0.15;
const CGFloat kTableViewHighlightedCellColor = 0xA6A6A6;
const CGFloat kTableViewHighlightedCellColorAlpha = 0.5;
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_DISCLOSURE_HEADER_FOOTER_ITEM_H_
#define IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_DISCLOSURE_HEADER_FOOTER_ITEM_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/table_view/cells/table_view_header_footer_item.h"
// TableViewDisclosureHeaderFooterItem contains the model data for a
// TableViewDisclosureHeaderFooterView.
@interface TableViewDisclosureHeaderFooterItem : TableViewHeaderFooterItem
// Title of Header.
@property(nonatomic, readwrite, strong) NSString* text;
// Header subtitle displayed as a smaller font under title.
@property(nonatomic, readwrite, strong) NSString* subtitleText;
@end
// UITableViewHeaderFooterView that displays a text label, subtitle, and a
// disclosure accessory view.
@interface TableViewDisclosureHeaderFooterView : UITableViewHeaderFooterView
// Shows the text of the TableViewDisclosureHeaderFooterItem.
@property(nonatomic, readwrite, strong) UILabel* titleLabel;
// Shows the subtitleText of the TableViewDisclosureHeaderFooterItem.
@property(nonatomic, readwrite, strong) UILabel* subtitleLabel;
// Animates a change in the backgroundView color and then changes it back to the
// original backGround color in order to simulate a selection highlight.
- (void)animateHighlight;
@end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_DISCLOSURE_HEADER_FOOTER_ITEM_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/table_view/cells/table_view_disclosure_header_footer_item.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation TableViewDisclosureHeaderFooterItem
@synthesize subtitleText = _subtitleText;
@synthesize text = _text;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.cellClass = [TableViewDisclosureHeaderFooterView class];
}
return self;
}
- (void)configureHeaderFooterView:(UITableViewHeaderFooterView*)headerFooter
withStyler:(ChromeTableViewStyler*)styler {
[super configureHeaderFooterView:headerFooter withStyler:styler];
// Set the contentView backgroundColor, not the header's.
headerFooter.contentView.backgroundColor = styler.tableViewBackgroundColor;
TableViewDisclosureHeaderFooterView* header =
base::mac::ObjCCastStrict<TableViewDisclosureHeaderFooterView>(
headerFooter);
header.titleLabel.text = self.text;
header.subtitleLabel.text = self.subtitleText;
}
@end
#pragma mark - TableViewDisclosureHeaderFooterView
@interface TableViewDisclosureHeaderFooterView ()
// Animator that handles all cell animations.
@property(strong, nonatomic) UIViewPropertyAnimator* cellAnimator;
@end
@implementation TableViewDisclosureHeaderFooterView
@synthesize cellAnimator = _cellAnimator;
@synthesize subtitleLabel = _subtitleLabel;
@synthesize titleLabel = _titleLabel;
- (instancetype)initWithReuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithReuseIdentifier:reuseIdentifier];
if (self) {
// Labels, set font sizes using dynamic type.
_titleLabel = [[UILabel alloc] init];
_titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
_subtitleLabel = [[UILabel alloc] init];
_subtitleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
_subtitleLabel.textColor = [UIColor lightGrayColor];
// Vertical StackView.
UIStackView* verticalStack = [[UIStackView alloc]
initWithArrangedSubviews:@[ _titleLabel, _subtitleLabel ]];
verticalStack.axis = UILayoutConstraintAxisVertical;
verticalStack.spacing = kTableViewVerticalLabelStackSpacing;
// Disclosure ImageView.
UIImageView* disclosureImageView = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"table_view_cell_chevron"]];
[disclosureImageView
setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal];
// Horizontal StackView.
UIStackView* horizontalStack = [[UIStackView alloc]
initWithArrangedSubviews:@[ verticalStack, disclosureImageView ]];
horizontalStack.axis = UILayoutConstraintAxisHorizontal;
horizontalStack.spacing = kTableViewCellViewSpacing;
horizontalStack.translatesAutoresizingMaskIntoConstraints = NO;
horizontalStack.alignment = UIStackViewAlignmentCenter;
// Add subviews to View Hierarchy.
[self.contentView addSubview:horizontalStack];
// Set and activate constraints.
[NSLayoutConstraint activateConstraints:@[
// Horizontal Stack Constraints.
[horizontalStack.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kTableViewCellViewSpacing],
[horizontalStack.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kTableViewCellViewSpacing],
[horizontalStack.topAnchor
constraintGreaterThanOrEqualToAnchor:self.contentView.topAnchor
constant:kTableViewCellViewSpacing],
[horizontalStack.bottomAnchor
constraintLessThanOrEqualToAnchor:self.contentView.bottomAnchor
constant:-kTableViewCellViewSpacing],
[horizontalStack.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor]
]];
}
return self;
}
- (void)animateHighlight {
UIColor* originalBackgroundColor = self.contentView.backgroundColor;
self.cellAnimator = [[UIViewPropertyAnimator alloc]
initWithDuration:kTableViewCellSelectionAnimationDuration
curve:UIViewAnimationCurveLinear
animations:^{
self.contentView.backgroundColor =
UIColorFromRGB(kTableViewHighlightedCellColor,
kTableViewHighlightedCellColorAlpha);
}];
__weak TableViewDisclosureHeaderFooterView* weakSelf = self;
[self.cellAnimator addCompletion:^(UIViewAnimatingPosition finalPosition) {
weakSelf.contentView.backgroundColor = originalBackgroundColor;
}];
[self.cellAnimator startAnimation];
}
- (void)prepareForReuse {
[super prepareForReuse];
if (self.cellAnimator.isRunning)
[self.cellAnimator stopAnimation:YES];
}
@end
...@@ -5,19 +5,14 @@ ...@@ -5,19 +5,14 @@
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace {
// The inner insets of the View content.
const CGFloat kMargin = 16;
// The vertical spacing between text labels.
const CGFloat kVerticalSpacing = 2.0;
}
@implementation TableViewTextHeaderFooterItem @implementation TableViewTextHeaderFooterItem
@synthesize subtitleText = _subtitleText; @synthesize subtitleText = _subtitleText;
...@@ -76,7 +71,7 @@ const CGFloat kVerticalSpacing = 2.0; ...@@ -76,7 +71,7 @@ const CGFloat kVerticalSpacing = 2.0;
UIStackView* verticalStack = [[UIStackView alloc] UIStackView* verticalStack = [[UIStackView alloc]
initWithArrangedSubviews:@[ _textLabel, _subtitleLabel ]]; initWithArrangedSubviews:@[ _textLabel, _subtitleLabel ]];
verticalStack.axis = UILayoutConstraintAxisVertical; verticalStack.axis = UILayoutConstraintAxisVertical;
verticalStack.spacing = kVerticalSpacing; verticalStack.spacing = kTableViewVerticalLabelStackSpacing;
verticalStack.translatesAutoresizingMaskIntoConstraints = NO; verticalStack.translatesAutoresizingMaskIntoConstraints = NO;
// Container View. // Container View.
...@@ -92,16 +87,16 @@ const CGFloat kVerticalSpacing = 2.0; ...@@ -92,16 +87,16 @@ const CGFloat kVerticalSpacing = 2.0;
// Container Constraints. // Container Constraints.
[containerView.leadingAnchor [containerView.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kMargin], constant:kTableViewCellViewSpacing],
[containerView.trailingAnchor [containerView.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kMargin], constant:-kTableViewCellViewSpacing],
[containerView.topAnchor [containerView.topAnchor
constraintGreaterThanOrEqualToAnchor:self.contentView.topAnchor constraintGreaterThanOrEqualToAnchor:self.contentView.topAnchor
constant:kMargin], constant:kTableViewCellViewSpacing],
[containerView.bottomAnchor [containerView.bottomAnchor
constraintLessThanOrEqualToAnchor:self.contentView.bottomAnchor constraintLessThanOrEqualToAnchor:self.contentView.bottomAnchor
constant:-kMargin], constant:-kTableViewCellViewSpacing],
[containerView.centerYAnchor [containerView.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor], constraintEqualToAnchor:self.contentView.centerYAnchor],
// Vertical StackView Constraints. // Vertical StackView Constraints.
...@@ -120,11 +115,12 @@ const CGFloat kVerticalSpacing = 2.0; ...@@ -120,11 +115,12 @@ const CGFloat kVerticalSpacing = 2.0;
- (void)animateHighlight { - (void)animateHighlight {
UIColor* originalBackgroundColor = self.contentView.backgroundColor; UIColor* originalBackgroundColor = self.contentView.backgroundColor;
self.cellAnimator = [[UIViewPropertyAnimator alloc] self.cellAnimator = [[UIViewPropertyAnimator alloc]
initWithDuration:0.15 initWithDuration:kTableViewCellSelectionAnimationDuration
curve:UIViewAnimationCurveLinear curve:UIViewAnimationCurveLinear
animations:^{ animations:^{
self.contentView.backgroundColor = self.contentView.backgroundColor =
[[UIColor lightGrayColor] colorWithAlphaComponent:0.5]; UIColorFromRGB(kTableViewHighlightedCellColor,
kTableViewHighlightedCellColorAlpha);
}]; }];
__weak TableViewTextHeaderFooterView* weakSelf = self; __weak TableViewTextHeaderFooterView* weakSelf = self;
[self.cellAnimator addCompletion:^(UIViewAnimatingPosition finalPosition) { [self.cellAnimator addCompletion:^(UIViewAnimatingPosition finalPosition) {
......
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