Commit e580db86 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Adds Visual Effects to ChromeTableVC Headers and NavigationBars

- Adds a BlurEffect to the styler.
- Makes NavigationBar translucent.

Screenshot:
https://drive.google.com/open?id=1wW2bL4AP3TusA64yPVgAyGMg4_hncVQT
(The blue squares were added so the Visual effect is easier to see)

Bug: 838580
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I4e03b2dde5633716fbe131893433e6142abfa653
Reviewed-on: https://chromium-review.googlesource.com/1084321
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565698}
parent 81fcf533
...@@ -362,9 +362,6 @@ const CGFloat kShadowRadius = 12.0f; ...@@ -362,9 +362,6 @@ const CGFloat kShadowRadius = 12.0f;
if (experimental_flags::IsBookmarksUIRebootEnabled()) { if (experimental_flags::IsBookmarksUIRebootEnabled()) {
self.navigationController.navigationBarHidden = NO; self.navigationController.navigationBarHidden = NO;
self.navigationController.toolbar.translucent = YES; self.navigationController.toolbar.translucent = YES;
// If the NavigationBar is not translucent, set
// |self.extendedLayoutIncludesOpaqueBars| to YES.
self.extendedLayoutIncludesOpaqueBars = YES;
} else { } else {
self.navigationController.navigationBarHidden = YES; self.navigationController.navigationBarHidden = YES;
self.navigationController.toolbar.translucent = NO; self.navigationController.toolbar.translucent = NO;
......
...@@ -141,11 +141,6 @@ const CGFloat kSeparationSpaceBetweenSections = 9; ...@@ -141,11 +141,6 @@ const CGFloat kSeparationSpaceBetweenSections = 9;
action:@selector(displayContextMenuInvokedByGestureRecognizer:)]; action:@selector(displayContextMenuInvokedByGestureRecognizer:)];
[self.tableView addGestureRecognizer:longPressRecognizer]; [self.tableView addGestureRecognizer:longPressRecognizer];
// If the NavigationBar is not translucent, set
// |self.extendedLayoutIncludesOpaqueBars| to YES in order to avoid a top
// margin inset on the |_tableViewController| subview.
self.extendedLayoutIncludesOpaqueBars = YES;
// NavigationController configuration. // NavigationController configuration.
self.title = l10n_util::GetNSString(IDS_HISTORY_TITLE); self.title = l10n_util::GetNSString(IDS_HISTORY_TITLE);
// Configures NavigationController Toolbar buttons. // Configures NavigationController Toolbar buttons.
...@@ -167,7 +162,7 @@ const CGFloat kSeparationSpaceBetweenSections = 9; ...@@ -167,7 +162,7 @@ const CGFloat kSeparationSpaceBetweenSections = 9;
self.searchController.dimsBackgroundDuringPresentation = NO; self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self; self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self; self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.backgroundColor = [UIColor whiteColor]; self.searchController.searchBar.backgroundColor = [UIColor clearColor];
self.searchController.searchBar.accessibilityIdentifier = self.searchController.searchBar.accessibilityIdentifier =
kHistorySearchControllerSearchBarIdentifier; kHistorySearchControllerSearchBarIdentifier;
// UIKit needs to know which controller will be presenting the // UIKit needs to know which controller will be presenting the
......
...@@ -183,10 +183,6 @@ const CGFloat kDoubleLineSectionHeaderHeight = 56; ...@@ -183,10 +183,6 @@ const CGFloat kDoubleLineSectionHeaderHeight = 56;
tapGesture.delegate = self; tapGesture.delegate = self;
[self.tableView addGestureRecognizer:tapGesture]; [self.tableView addGestureRecognizer:tapGesture];
// If the NavigationBar is not translucent, set
// |self.extendedLayoutIncludesOpaqueBars| to YES in order to avoid a top
// margin inset on the |_tableViewController| subview.
self.extendedLayoutIncludesOpaqueBars = YES;
self.title = l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_RECENT_TABS); self.title = l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_RECENT_TABS);
} }
......
...@@ -36,6 +36,9 @@ source_set("styler") { ...@@ -36,6 +36,9 @@ source_set("styler") {
"chrome_table_view_styler.h", "chrome_table_view_styler.h",
"chrome_table_view_styler.mm", "chrome_table_view_styler.mm",
] ]
public_deps = [
"//ios/chrome/browser/ui:ui_util",
]
} }
source_set("presentation") { source_set("presentation") {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/table_view/cells/table_view_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_header_footer_item.h"
#import "base/logging.h" #import "base/logging.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.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."
...@@ -24,6 +25,9 @@ ...@@ -24,6 +25,9 @@
DCHECK([headerFooter class] == self.cellClass); DCHECK([headerFooter class] == self.cellClass);
headerFooter.accessibilityTraits = self.accessibilityTraits; headerFooter.accessibilityTraits = self.accessibilityTraits;
headerFooter.accessibilityIdentifier = self.accessibilityIdentifier; headerFooter.accessibilityIdentifier = self.accessibilityIdentifier;
UIVisualEffectView* visualEffect = [[UIVisualEffectView alloc]
initWithEffect:styler.tableViewSectionHeaderBlurEffect];
headerFooter.backgroundView = visualEffect;
} }
@end @end
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#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/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" #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)
...@@ -31,10 +30,6 @@ ...@@ -31,10 +30,6 @@
- (void)configureHeaderFooterView:(UITableViewHeaderFooterView*)headerFooter - (void)configureHeaderFooterView:(UITableViewHeaderFooterView*)headerFooter
withStyler:(ChromeTableViewStyler*)styler { withStyler:(ChromeTableViewStyler*)styler {
[super configureHeaderFooterView:headerFooter withStyler:styler]; [super configureHeaderFooterView:headerFooter withStyler:styler];
// Set the contentView backgroundColor, not the header's.
headerFooter.contentView.backgroundColor = styler.tableViewBackgroundColor;
TableViewTextHeaderFooterView* header = TableViewTextHeaderFooterView* header =
base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerFooter); base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerFooter);
header.textLabel.text = self.text; header.textLabel.text = self.text;
......
...@@ -39,19 +39,3 @@ TEST_F(TableViewTextHeaderFooterItemTest, HeaderFooterTextLabels) { ...@@ -39,19 +39,3 @@ TEST_F(TableViewTextHeaderFooterItemTest, HeaderFooterTextLabels) {
[item configureHeaderFooterView:textHeaderFooter withStyler:styler]; [item configureHeaderFooterView:textHeaderFooter withStyler:styler];
EXPECT_NSEQ(text, textHeaderFooter.textLabel.text); EXPECT_NSEQ(text, textHeaderFooter.textLabel.text);
} }
TEST_F(TableViewTextHeaderFooterItemTest, Styler) {
TableViewTextHeaderFooterItem* item =
[[TableViewTextHeaderFooterItem alloc] initWithType:0];
id headerFooter = [[[item cellClass] alloc] init];
ASSERT_TRUE(
[headerFooter isMemberOfClass:[TableViewTextHeaderFooterView class]]);
TableViewTextHeaderFooterView* textHeaderFooter =
base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerFooter);
ChromeTableViewStyler* styler = [[ChromeTableViewStyler alloc] init];
UIColor* testColor = [UIColor redColor];
styler.tableViewBackgroundColor = testColor;
[item configureHeaderFooterView:textHeaderFooter withStyler:styler];
EXPECT_NSEQ(testColor, textHeaderFooter.contentView.backgroundColor);
}
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
@interface ChromeTableViewStyler : NSObject @interface ChromeTableViewStyler : NSObject
// The BlurEffect used on the UITableView section headers.
@property(nonatomic, readwrite, strong)
UIBlurEffect* tableViewSectionHeaderBlurEffect;
// The background color for the table view and its cells. If this is set to an // The background color for the table view and its cells. If this is set to an
// opaque color, cells can choose to make themselves opaque and draw their own // opaque color, cells can choose to make themselves opaque and draw their own
// background as a performance optimization. // background as a performance optimization.
......
...@@ -4,19 +4,30 @@ ...@@ -4,19 +4,30 @@
#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
@implementation ChromeTableViewStyler namespace {
// The width and height of the favicon ImageView.
const int kTableViewBackgroundRGBColor = 0xF9F9F9;
}
@implementation ChromeTableViewStyler
@synthesize tableViewSectionHeaderBlurEffect =
_tableViewSectionHeaderBlurEffect;
@synthesize tableViewBackgroundColor = _tableViewBackgroundColor; @synthesize tableViewBackgroundColor = _tableViewBackgroundColor;
@synthesize cellTitleColor = _cellTitleColor; @synthesize cellTitleColor = _cellTitleColor;
@synthesize headerFooterTitleColor = _headerFooterTitleColor; @synthesize headerFooterTitleColor = _headerFooterTitleColor;
- (instancetype)init { - (instancetype)init {
if ((self = [super init])) { if ((self = [super init])) {
_tableViewBackgroundColor = [UIColor whiteColor]; _tableViewBackgroundColor = UIColorFromRGB(kTableViewBackgroundRGBColor, 1);
_tableViewSectionHeaderBlurEffect =
[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
} }
return self; return self;
} }
......
...@@ -28,16 +28,22 @@ ...@@ -28,16 +28,22 @@
#pragma mark - View Lifecycle #pragma mark - View Lifecycle
- (void)viewDidLoad { - (void)viewDidLoad {
[self.navigationBar setBackgroundImage:[UIImage new] [super viewDidLoad];
forBarMetrics:UIBarMetricsDefault];
if (self.tableViewController.styler.tableViewBackgroundColor != UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc]
[UIColor clearColor]) { initWithEffect:[UIBlurEffect
self.navigationBar.translucent = NO; effectWithStyle:UIBlurEffectStyleExtraLight]];
}
if (@available(iOS 11, *)) { self.navigationBar.translucent = YES;
self.navigationController.navigationBar.backgroundColor =
[UIColor clearColor];
[self.navigationController.navigationBar addSubview:visualEffectView];
if (@available(iOS 11, *))
self.navigationBar.prefersLargeTitles = YES; self.navigationBar.prefersLargeTitles = YES;
}
self.toolbar.clipsToBounds = YES;
self.toolbar.translucent = YES;
[self.toolbar addSubview:visualEffectView];
} }
@end @end
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