Commit 5d4b9370 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Polish tab grid (part 1)

This CL moves magic numbers to constants files:

- Various dimensions in GridCell
- Margins and height of TabGridTopToolbar
- Margins and height of TabGridBottomToolbar

This CL also changes the toolbar classes to use
|-willMoveToSuperview:| to setup views instead of
|-init|.

Bug: 818198, 822524

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ib4dcfd344c29c3e0ccee103b6002dd6e1d14fb30
Reviewed-on: https://chromium-review.googlesource.com/965576
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543790}
parent 5ea50535
...@@ -53,6 +53,8 @@ source_set("tab_grid_ui") { ...@@ -53,6 +53,8 @@ source_set("tab_grid_ui") {
"grid_view_controller.mm", "grid_view_controller.mm",
"tab_grid_bottom_toolbar.h", "tab_grid_bottom_toolbar.h",
"tab_grid_bottom_toolbar.mm", "tab_grid_bottom_toolbar.mm",
"tab_grid_constants.h",
"tab_grid_constants.mm",
"tab_grid_page_control.h", "tab_grid_page_control.h",
"tab_grid_page_control.mm", "tab_grid_page_control.mm",
"tab_grid_paging.h", "tab_grid_paging.h",
......
...@@ -15,15 +15,6 @@ ...@@ -15,15 +15,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace {
// Height of the top bar containing the icon, title, and close button.
const CGFloat kTopBarHeight = 28.0f;
// Width and height of the icon.
const CGFloat kIconDiameter = 20.0f;
// Width of selection border.
const CGFloat kBorderWidth = 6.0f;
} // namespace
@interface GridCell () @interface GridCell ()
// Visual components of the cell. // Visual components of the cell.
@property(nonatomic, weak) UIView* topBar; @property(nonatomic, weak) UIView* topBar;
...@@ -57,7 +48,7 @@ const CGFloat kBorderWidth = 6.0f; ...@@ -57,7 +48,7 @@ const CGFloat kBorderWidth = 6.0f;
if (self) { if (self) {
[self setupSelectedBackgroundView]; [self setupSelectedBackgroundView];
UIView* contentView = self.contentView; UIView* contentView = self.contentView;
contentView.layer.cornerRadius = 11.0f; contentView.layer.cornerRadius = kGridCellCornerRadius;
contentView.layer.masksToBounds = YES; contentView.layer.masksToBounds = YES;
UIView* topBar = [self setupTopBar]; UIView* topBar = [self setupTopBar];
TopAlignedImageView* snapshotView = [[TopAlignedImageView alloc] init]; TopAlignedImageView* snapshotView = [[TopAlignedImageView alloc] init];
...@@ -71,7 +62,7 @@ const CGFloat kBorderWidth = 6.0f; ...@@ -71,7 +62,7 @@ const CGFloat kBorderWidth = 6.0f;
[topBar.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor], [topBar.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor],
[topBar.trailingAnchor [topBar.trailingAnchor
constraintEqualToAnchor:contentView.trailingAnchor], constraintEqualToAnchor:contentView.trailingAnchor],
[topBar.heightAnchor constraintEqualToConstant:kTopBarHeight], [topBar.heightAnchor constraintEqualToConstant:kGridCellHeaderHeight],
[snapshotView.topAnchor constraintEqualToAnchor:topBar.bottomAnchor], [snapshotView.topAnchor constraintEqualToAnchor:topBar.bottomAnchor],
[snapshotView.leadingAnchor [snapshotView.leadingAnchor
constraintEqualToAnchor:contentView.leadingAnchor], constraintEqualToAnchor:contentView.leadingAnchor],
...@@ -177,7 +168,7 @@ const CGFloat kBorderWidth = 6.0f; ...@@ -177,7 +168,7 @@ const CGFloat kBorderWidth = 6.0f;
UIImageView* iconView = [[UIImageView alloc] init]; UIImageView* iconView = [[UIImageView alloc] init];
iconView.translatesAutoresizingMaskIntoConstraints = NO; iconView.translatesAutoresizingMaskIntoConstraints = NO;
iconView.contentMode = UIViewContentModeScaleAspectFill; iconView.contentMode = UIViewContentModeScaleAspectFill;
iconView.layer.cornerRadius = 4.0f; iconView.layer.cornerRadius = kGridCellIconCornerRadius;
iconView.layer.masksToBounds = YES; iconView.layer.masksToBounds = YES;
UILabel* titleLabel = [[UILabel alloc] init]; UILabel* titleLabel = [[UILabel alloc] init];
...@@ -203,19 +194,22 @@ const CGFloat kBorderWidth = 6.0f; ...@@ -203,19 +194,22 @@ const CGFloat kBorderWidth = 6.0f;
_closeButton = closeButton; _closeButton = closeButton;
NSArray* constraints = @[ NSArray* constraints = @[
[iconView.leadingAnchor constraintEqualToAnchor:topBar.leadingAnchor [iconView.leadingAnchor
constant:4.0f], constraintEqualToAnchor:topBar.leadingAnchor
constant:kGridCellHeaderLeadingInset],
[iconView.centerYAnchor constraintEqualToAnchor:topBar.centerYAnchor], [iconView.centerYAnchor constraintEqualToAnchor:topBar.centerYAnchor],
[iconView.widthAnchor constraintEqualToConstant:kIconDiameter], [iconView.widthAnchor constraintEqualToConstant:kGridCellIconDiameter],
[iconView.heightAnchor constraintEqualToConstant:kIconDiameter], [iconView.heightAnchor constraintEqualToConstant:kGridCellIconDiameter],
[titleLabel.leadingAnchor constraintEqualToAnchor:iconView.trailingAnchor [titleLabel.leadingAnchor
constant:4.0f], constraintEqualToAnchor:iconView.trailingAnchor
constant:kGridCellHeaderLeadingInset],
[titleLabel.centerYAnchor constraintEqualToAnchor:topBar.centerYAnchor], [titleLabel.centerYAnchor constraintEqualToAnchor:topBar.centerYAnchor],
[closeButton.leadingAnchor [closeButton.leadingAnchor
constraintEqualToAnchor:titleLabel.trailingAnchor], constraintEqualToAnchor:titleLabel.trailingAnchor],
[closeButton.centerYAnchor constraintEqualToAnchor:topBar.centerYAnchor], [closeButton.centerYAnchor constraintEqualToAnchor:topBar.centerYAnchor],
[closeButton.trailingAnchor constraintEqualToAnchor:topBar.trailingAnchor [closeButton.trailingAnchor
constant:-6.0f], constraintEqualToAnchor:topBar.trailingAnchor
constant:-kGridCellHeaderTrailingInset],
]; ];
[NSLayoutConstraint activateConstraints:constraints]; [NSLayoutConstraint activateConstraints:constraints];
[titleLabel setContentHuggingPriority:UILayoutPriorityDefaultLow [titleLabel setContentHuggingPriority:UILayoutPriorityDefaultLow
...@@ -232,27 +226,34 @@ const CGFloat kBorderWidth = 6.0f; ...@@ -232,27 +226,34 @@ const CGFloat kBorderWidth = 6.0f;
// selected. // selected.
- (void)setupSelectedBackgroundView { - (void)setupSelectedBackgroundView {
self.selectedBackgroundView = [[UIView alloc] init]; self.selectedBackgroundView = [[UIView alloc] init];
self.selectedBackgroundView.backgroundColor = [UIColor blackColor]; self.selectedBackgroundView.backgroundColor =
UIColorFromRGB(kGridBackgroundColor);
UIView* border = [[UIView alloc] init]; UIView* border = [[UIView alloc] init];
border.translatesAutoresizingMaskIntoConstraints = NO; border.translatesAutoresizingMaskIntoConstraints = NO;
border.backgroundColor = [UIColor blackColor]; border.backgroundColor = UIColorFromRGB(kGridBackgroundColor);
border.layer.cornerRadius = 17.0f; border.layer.cornerRadius = kGridCellCornerRadius +
border.layer.borderWidth = 4.0f; kGridCellSelectionRingGapWidth +
kGridCellSelectionRingTintWidth;
border.layer.borderWidth = kGridCellSelectionRingTintWidth;
[self.selectedBackgroundView addSubview:border]; [self.selectedBackgroundView addSubview:border];
_border = border; _border = border;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[border.topAnchor [border.topAnchor
constraintEqualToAnchor:self.selectedBackgroundView.topAnchor constraintEqualToAnchor:self.selectedBackgroundView.topAnchor
constant:-kBorderWidth], constant:-kGridCellSelectionRingTintWidth -
kGridCellSelectionRingGapWidth],
[border.leadingAnchor [border.leadingAnchor
constraintEqualToAnchor:self.selectedBackgroundView.leadingAnchor constraintEqualToAnchor:self.selectedBackgroundView.leadingAnchor
constant:-kBorderWidth], constant:-kGridCellSelectionRingTintWidth -
kGridCellSelectionRingGapWidth],
[border.trailingAnchor [border.trailingAnchor
constraintEqualToAnchor:self.selectedBackgroundView.trailingAnchor constraintEqualToAnchor:self.selectedBackgroundView.trailingAnchor
constant:kBorderWidth], constant:kGridCellSelectionRingTintWidth +
kGridCellSelectionRingGapWidth],
[border.bottomAnchor [border.bottomAnchor
constraintEqualToAnchor:self.selectedBackgroundView.bottomAnchor constraintEqualToAnchor:self.selectedBackgroundView.bottomAnchor
constant:kBorderWidth] constant:kGridCellSelectionRingTintWidth +
kGridCellSelectionRingGapWidth]
]]; ]];
} }
......
...@@ -20,19 +20,33 @@ extern NSString* const kGridCellCloseButtonIdentifier; ...@@ -20,19 +20,33 @@ extern NSString* const kGridCellCloseButtonIdentifier;
// converted into UIColors using the UIColorFromRGB() function, from // converted into UIColors using the UIColorFromRGB() function, from
// uikit_ui_util.h // uikit_ui_util.h
// Grid styling.
extern const int kGridBackgroundColor;
// GridCell styling. // GridCell styling.
// Common colors. // Common colors.
extern const CGFloat kGridCellIconBackgroundColor; extern const int kGridCellIconBackgroundColor;
extern const CGFloat kGridCellSnapshotBackgroundColor; extern const int kGridCellSnapshotBackgroundColor;
// Light theme colors. // Light theme colors.
extern const CGFloat kGridLightThemeCellTitleColor; extern const int kGridLightThemeCellTitleColor;
extern const CGFloat kGridLightThemeCellHeaderColor; extern const int kGridLightThemeCellHeaderColor;
extern const CGFloat kGridLightThemeCellSelectionColor; extern const int kGridLightThemeCellSelectionColor;
extern const CGFloat kGridLightThemeCellCloseButtonTintColor; extern const int kGridLightThemeCellCloseButtonTintColor;
// Dark theme colors. // Dark theme colors.
extern const CGFloat kGridDarkThemeCellTitleColor; extern const int kGridDarkThemeCellTitleColor;
extern const CGFloat kGridDarkThemeCellHeaderColor; extern const int kGridDarkThemeCellHeaderColor;
extern const CGFloat kGridDarkThemeCellSelectionColor; extern const int kGridDarkThemeCellSelectionColor;
extern const CGFloat kGridDarkThemeCellCloseButtonTintColor; extern const int kGridDarkThemeCellCloseButtonTintColor;
// GridCell dimensions.
extern const CGFloat kGridCellCornerRadius;
extern const CGFloat kGridCellIconCornerRadius;
// Height of the cell header containing the icon, title, and close button.
extern const CGFloat kGridCellHeaderHeight;
extern const CGFloat kGridCellHeaderLeadingInset;
extern const CGFloat kGridCellHeaderTrailingInset;
extern const CGFloat kGridCellIconDiameter;
extern const CGFloat kGridCellSelectionRingGapWidth;
extern const CGFloat kGridCellSelectionRingTintWidth;
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_CONSTANTS_H_ #endif // IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_CONSTANTS_H_
...@@ -15,17 +15,31 @@ NSString* const kGridCellIdentifierPrefix = @"GridCellIdentifierPrefix"; ...@@ -15,17 +15,31 @@ NSString* const kGridCellIdentifierPrefix = @"GridCellIdentifierPrefix";
NSString* const kGridCellCloseButtonIdentifier = NSString* const kGridCellCloseButtonIdentifier =
@"GridCellCloseButtonIdentifier"; @"GridCellCloseButtonIdentifier";
// Grid styling.
const int kGridBackgroundColor = 0x222222;
// GridCell styling. // GridCell styling.
// Common colors. // Common colors.
const CGFloat kGridCellIconBackgroundColor = 0xF1F3F4; const int kGridCellIconBackgroundColor = 0xF1F3F4;
const CGFloat kGridCellSnapshotBackgroundColor = 0xE8EAED; const int kGridCellSnapshotBackgroundColor = 0xE8EAED;
// Light theme colors. // Light theme colors.
const CGFloat kGridLightThemeCellTitleColor = 0x000000; const int kGridLightThemeCellTitleColor = 0x000000;
const CGFloat kGridLightThemeCellHeaderColor = 0xF8F9FA; const int kGridLightThemeCellHeaderColor = 0xF8F9FA;
const CGFloat kGridLightThemeCellSelectionColor = 0x1A73E8; const int kGridLightThemeCellSelectionColor = 0x1A73E8;
const CGFloat kGridLightThemeCellCloseButtonTintColor = 0x3C4043; const int kGridLightThemeCellCloseButtonTintColor = 0x3C4043;
// Dark theme colors. // Dark theme colors.
const CGFloat kGridDarkThemeCellTitleColor = 0xFFFFFF; const int kGridDarkThemeCellTitleColor = 0xFFFFFF;
const CGFloat kGridDarkThemeCellHeaderColor = 0x5F6368; const int kGridDarkThemeCellHeaderColor = 0x5F6368;
const CGFloat kGridDarkThemeCellSelectionColor = 0x9AA0A6; const int kGridDarkThemeCellSelectionColor = 0x9AA0A6;
const CGFloat kGridDarkThemeCellCloseButtonTintColor = 0xFFFFFF; const int kGridDarkThemeCellCloseButtonTintColor = 0xFFFFFF;
// GridCell dimensions.
const CGFloat kGridCellCornerRadius = 13.0f;
const CGFloat kGridCellIconCornerRadius = 3.0f;
// The cell header contains the icon, title, and close button.
const CGFloat kGridCellHeaderHeight = 32.0f;
const CGFloat kGridCellHeaderLeadingInset = 5.0f;
const CGFloat kGridCellHeaderTrailingInset = 8.5f;
const CGFloat kGridCellIconDiameter = 22.0f;
const CGFloat kGridCellSelectionRingGapWidth = 2.0f;
const CGFloat kGridCellSelectionRingTintWidth = 5.0f;
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
@property(nonatomic, weak, readonly) UIButton* leadingButton; @property(nonatomic, weak, readonly) UIButton* leadingButton;
@property(nonatomic, weak, readonly) UIButton* trailingButton; @property(nonatomic, weak, readonly) UIButton* trailingButton;
@property(nonatomic, weak, readonly) UIButton* centerButton; @property(nonatomic, weak, readonly) UIButton* centerButton;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_BOTTOM_TOOLBAR_H_ #endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_BOTTOM_TOOLBAR_H_
...@@ -4,24 +4,37 @@ ...@@ -4,24 +4,37 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_bottom_toolbar.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_bottom_toolbar.h"
#include "base/logging.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_constants.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 {
// Height of the toolbar.
const CGFloat kToolbarHeight = 44.0f;
} // namespace
@implementation TabGridBottomToolbar @implementation TabGridBottomToolbar
@synthesize leadingButton = _leadingButton; @synthesize leadingButton = _leadingButton;
@synthesize trailingButton = _trailingButton; @synthesize trailingButton = _trailingButton;
@synthesize centerButton = _centerButton; @synthesize centerButton = _centerButton;
- (instancetype)init { #pragma mark - UIView
if (self = [super initWithFrame:CGRectZero]) {
- (CGSize)intrinsicContentSize {
return CGSizeMake(UIViewNoIntrinsicMetric, kTabGridBottomToolbarHeight);
}
- (void)willMoveToSuperview:(UIView*)newSuperview {
// The first time this moves to a superview, perform the view setup.
if (newSuperview && self.subviews.count == 0) {
[self setupViews];
}
}
#pragma mark - Private
- (void)setupViews {
self.layoutMargins = UIEdgeInsetsMake(0, kTabGridToolbarHorizontalInset, 0,
kTabGridToolbarHorizontalInset);
UIVisualEffect* blurEffect = UIVisualEffect* blurEffect =
[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView* toolbar = UIVisualEffectView* toolbar =
...@@ -34,13 +47,13 @@ const CGFloat kToolbarHeight = 44.0f; ...@@ -34,13 +47,13 @@ const CGFloat kToolbarHeight = 44.0f;
leadingButton.titleLabel.font = leadingButton.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
leadingButton.titleLabel.adjustsFontForContentSizeCategory = YES; leadingButton.titleLabel.adjustsFontForContentSizeCategory = YES;
leadingButton.tintColor = [UIColor whiteColor]; leadingButton.tintColor = UIColorFromRGB(kTabGridToolbarTextButtonColor);
UIButton* trailingButton = [UIButton buttonWithType:UIButtonTypeSystem]; UIButton* trailingButton = [UIButton buttonWithType:UIButtonTypeSystem];
trailingButton.translatesAutoresizingMaskIntoConstraints = NO; trailingButton.translatesAutoresizingMaskIntoConstraints = NO;
trailingButton.titleLabel.font = trailingButton.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleBody]; [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
trailingButton.titleLabel.adjustsFontForContentSizeCategory = YES; trailingButton.titleLabel.adjustsFontForContentSizeCategory = YES;
trailingButton.tintColor = [UIColor whiteColor]; trailingButton.tintColor = UIColorFromRGB(kTabGridToolbarTextButtonColor);
UIButton* centerButton = [UIButton buttonWithType:UIButtonTypeSystem]; UIButton* centerButton = [UIButton buttonWithType:UIButtonTypeSystem];
centerButton.translatesAutoresizingMaskIntoConstraints = NO; centerButton.translatesAutoresizingMaskIntoConstraints = NO;
...@@ -56,25 +69,22 @@ const CGFloat kToolbarHeight = 44.0f; ...@@ -56,25 +69,22 @@ const CGFloat kToolbarHeight = 44.0f;
[toolbar.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], [toolbar.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
[toolbar.leadingAnchor constraintEqualToAnchor:self.leadingAnchor], [toolbar.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[toolbar.trailingAnchor constraintEqualToAnchor:self.trailingAnchor], [toolbar.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
[leadingButton.heightAnchor constraintEqualToConstant:kToolbarHeight], [leadingButton.heightAnchor
constraintEqualToConstant:kTabGridBottomToolbarHeight],
[leadingButton.leadingAnchor [leadingButton.leadingAnchor
constraintEqualToAnchor:toolbar.layoutMarginsGuide.leadingAnchor], constraintEqualToAnchor:self.layoutMarginsGuide.leadingAnchor],
[leadingButton.topAnchor constraintEqualToAnchor:toolbar.topAnchor], [leadingButton.topAnchor constraintEqualToAnchor:toolbar.topAnchor],
[centerButton.centerXAnchor [centerButton.centerXAnchor constraintEqualToAnchor:toolbar.centerXAnchor],
constraintEqualToAnchor:toolbar.centerXAnchor], [centerButton.centerYAnchor
[centerButton.topAnchor constraintEqualToAnchor:toolbar.topAnchor], constraintEqualToAnchor:toolbar.topAnchor
[trailingButton.heightAnchor constraintEqualToConstant:kToolbarHeight], constant:kTabGridBottomToolbarHeight / 2.0f],
[trailingButton.heightAnchor
constraintEqualToConstant:kTabGridBottomToolbarHeight],
[trailingButton.trailingAnchor [trailingButton.trailingAnchor
constraintEqualToAnchor:toolbar.layoutMarginsGuide.trailingAnchor], constraintEqualToAnchor:self.layoutMarginsGuide.trailingAnchor],
[trailingButton.topAnchor constraintEqualToAnchor:toolbar.topAnchor], [trailingButton.topAnchor constraintEqualToAnchor:toolbar.topAnchor],
]; ];
[NSLayoutConstraint activateConstraints:constraints]; [NSLayoutConstraint activateConstraints:constraints];
}
return self;
}
- (CGSize)intrinsicContentSize {
return CGSizeMake(UIViewNoIntrinsicMetric, kToolbarHeight);
} }
@end @end
// 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_TAB_GRID_TAB_GRID_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_CONSTANTS_H_
#import <UIKit/UIKit.h>
// All kxxxColor constants are RGB values stored in a Hex integer. These will be
// converted into UIColors using the UIColorFromRGB() function, from
// uikit_ui_util.h
// The color of the text buttons in the toolbars.
extern const int kTabGridToolbarTextButtonColor;
// The distance the toolbar content is inset from either side.
extern const CGFloat kTabGridToolbarHorizontalInset;
// The distance between the title and body of the empty state view.
extern const CGFloat kTabGridEmptyStateVerticalMargin;
// Intrinsic heights of the tab grid toolbars.
extern const CGFloat kTabGridTopToolbarHeight;
extern const CGFloat kTabGridBottomToolbarHeight;
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_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/tab_grid/tab_grid_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// The color of the text buttons in the toolbars.
const int kTabGridToolbarTextButtonColor = 0xFFFFFF;
// The distance the toolbar content is inset from either side.
const CGFloat kTabGridToolbarHorizontalInset = 16.0f;
// The distance between the title and body of the empty state view.
const CGFloat kTabGridEmptyStateVerticalMargin = 4.0f;
// Intrinsic heights of the tab grid toolbars.
const CGFloat kTabGridTopToolbarHeight = 52.0f;
const CGFloat kTabGridBottomToolbarHeight = 44.0f;
...@@ -18,11 +18,6 @@ ...@@ -18,11 +18,6 @@
@property(nonatomic, weak, readonly) UIButton* leadingButton; @property(nonatomic, weak, readonly) UIButton* leadingButton;
@property(nonatomic, weak, readonly) UIButton* trailingButton; @property(nonatomic, weak, readonly) UIButton* trailingButton;
@property(nonatomic, weak, readonly) TabGridPageControl* pageControl; @property(nonatomic, weak, readonly) TabGridPageControl* pageControl;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_TOP_TOOLBAR_H_ #endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_TOP_TOOLBAR_H_
...@@ -4,24 +4,38 @@ ...@@ -4,24 +4,38 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_top_toolbar.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_top_toolbar.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_constants.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_page_control.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_page_control.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 {
// Height of the toolbar.
const CGFloat kToolbarHeight = 52.0f;
} // namespace
@implementation TabGridTopToolbar @implementation TabGridTopToolbar
@synthesize leadingButton = _leadingButton; @synthesize leadingButton = _leadingButton;
@synthesize trailingButton = _trailingButton; @synthesize trailingButton = _trailingButton;
@synthesize pageControl = _pageControl; @synthesize pageControl = _pageControl;
- (instancetype)init { #pragma mark - UIView
if (self = [super initWithFrame:CGRectZero]) {
- (CGSize)intrinsicContentSize {
return CGSizeMake(UIViewNoIntrinsicMetric, kTabGridTopToolbarHeight);
}
- (void)willMoveToSuperview:(UIView*)newSuperview {
// The first time this moves to a superview, perform the view setup.
if (newSuperview && self.subviews.count == 0) {
[self setupViews];
}
}
#pragma mark - Private
- (void)setupViews {
self.layoutMargins = UIEdgeInsetsMake(0, kTabGridToolbarHorizontalInset, 0,
kTabGridToolbarHorizontalInset);
UIVisualEffect* blurEffect = UIVisualEffect* blurEffect =
[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView* toolbar = UIVisualEffectView* toolbar =
...@@ -34,7 +48,7 @@ const CGFloat kToolbarHeight = 52.0f; ...@@ -34,7 +48,7 @@ const CGFloat kToolbarHeight = 52.0f;
leadingButton.titleLabel.font = leadingButton.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
leadingButton.titleLabel.adjustsFontForContentSizeCategory = YES; leadingButton.titleLabel.adjustsFontForContentSizeCategory = YES;
leadingButton.tintColor = [UIColor whiteColor]; leadingButton.tintColor = UIColorFromRGB(kTabGridToolbarTextButtonColor);
// The segmented control has an intrinsic size. // The segmented control has an intrinsic size.
TabGridPageControl* pageControl = [[TabGridPageControl alloc] init]; TabGridPageControl* pageControl = [[TabGridPageControl alloc] init];
...@@ -45,7 +59,7 @@ const CGFloat kToolbarHeight = 52.0f; ...@@ -45,7 +59,7 @@ const CGFloat kToolbarHeight = 52.0f;
trailingButton.titleLabel.font = trailingButton.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleBody]; [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
trailingButton.titleLabel.adjustsFontForContentSizeCategory = YES; trailingButton.titleLabel.adjustsFontForContentSizeCategory = YES;
trailingButton.tintColor = [UIColor whiteColor]; trailingButton.tintColor = UIColorFromRGB(kTabGridToolbarTextButtonColor);
[toolbar.contentView addSubview:leadingButton]; [toolbar.contentView addSubview:leadingButton];
[toolbar.contentView addSubview:trailingButton]; [toolbar.contentView addSubview:trailingButton];
...@@ -59,26 +73,22 @@ const CGFloat kToolbarHeight = 52.0f; ...@@ -59,26 +73,22 @@ const CGFloat kToolbarHeight = 52.0f;
[toolbar.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], [toolbar.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
[toolbar.leadingAnchor constraintEqualToAnchor:self.leadingAnchor], [toolbar.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[toolbar.trailingAnchor constraintEqualToAnchor:self.trailingAnchor], [toolbar.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
[leadingButton.heightAnchor constraintEqualToConstant:kToolbarHeight], [leadingButton.heightAnchor
constraintEqualToConstant:kTabGridTopToolbarHeight],
[leadingButton.leadingAnchor [leadingButton.leadingAnchor
constraintEqualToAnchor:toolbar.layoutMarginsGuide.leadingAnchor], constraintEqualToAnchor:self.layoutMarginsGuide.leadingAnchor],
[leadingButton.bottomAnchor constraintEqualToAnchor:toolbar.bottomAnchor], [leadingButton.bottomAnchor constraintEqualToAnchor:toolbar.bottomAnchor],
[pageControl.centerXAnchor constraintEqualToAnchor:toolbar.centerXAnchor], [pageControl.centerXAnchor constraintEqualToAnchor:toolbar.centerXAnchor],
[pageControl.bottomAnchor constraintEqualToAnchor:toolbar.bottomAnchor [pageControl.centerYAnchor
constant:-7.0f], constraintEqualToAnchor:toolbar.bottomAnchor
[trailingButton.heightAnchor constraintEqualToConstant:kToolbarHeight], constant:-kTabGridTopToolbarHeight / 2.0f],
[trailingButton.heightAnchor
constraintEqualToConstant:kTabGridTopToolbarHeight],
[trailingButton.trailingAnchor [trailingButton.trailingAnchor
constraintEqualToAnchor:toolbar.layoutMarginsGuide.trailingAnchor], constraintEqualToAnchor:self.layoutMarginsGuide.trailingAnchor],
[trailingButton.bottomAnchor [trailingButton.bottomAnchor constraintEqualToAnchor:toolbar.bottomAnchor],
constraintEqualToAnchor:toolbar.bottomAnchor],
]; ];
[NSLayoutConstraint activateConstraints:constraints]; [NSLayoutConstraint activateConstraints:constraints];
}
return self;
}
- (CGSize)intrinsicContentSize {
return CGSizeMake(UIViewNoIntrinsicMetric, kToolbarHeight);
} }
@end @end
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/tab_grid/grid_image_data_source.h" #import "ios/chrome/browser/ui/tab_grid/grid_image_data_source.h"
#import "ios/chrome/browser/ui/tab_grid/grid_view_controller.h" #import "ios/chrome/browser/ui/tab_grid/grid_view_controller.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_bottom_toolbar.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_bottom_toolbar.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_constants.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_page_control.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_page_control.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_top_toolbar.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_top_toolbar.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
...@@ -418,10 +419,12 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -418,10 +419,12 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
NSArray* constraints = @[ NSArray* constraints = @[
[topLabel.leadingAnchor constraintEqualToAnchor:view.leadingAnchor], [topLabel.leadingAnchor constraintEqualToAnchor:view.leadingAnchor],
[topLabel.trailingAnchor constraintEqualToAnchor:view.trailingAnchor], [topLabel.trailingAnchor constraintEqualToAnchor:view.trailingAnchor],
[topLabel.bottomAnchor constraintEqualToAnchor:view.centerYAnchor [topLabel.bottomAnchor
constant:-10.0f], constraintEqualToAnchor:view.centerYAnchor
[bottomLabel.topAnchor constraintEqualToAnchor:view.centerYAnchor constant:-kTabGridEmptyStateVerticalMargin / 2.0f],
constant:10.0f], [bottomLabel.topAnchor
constraintEqualToAnchor:view.centerYAnchor
constant:kTabGridEmptyStateVerticalMargin / 2.0f],
[bottomLabel.leadingAnchor constraintEqualToAnchor:view.leadingAnchor], [bottomLabel.leadingAnchor constraintEqualToAnchor:view.leadingAnchor],
[bottomLabel.trailingAnchor constraintEqualToAnchor:view.trailingAnchor], [bottomLabel.trailingAnchor constraintEqualToAnchor:view.trailingAnchor],
]; ];
......
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