Commit 977cd5be authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Converts TableContainerViewController into a UINavigationController.

The custom bottom toolbar is removed in favor of the toolbar already built into
UINavigationController. Showcase support is removed because this container is no
longer materially different from a stock UINavigationController.

BUG=805013,805201

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ib8e78793ea73c411ad8c72cabe18568c4cb71840
Reviewed-on: https://chromium-review.googlesource.com/1015541Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551709}
parent e674ba80
...@@ -9,15 +9,13 @@ ...@@ -9,15 +9,13 @@
#include "components/browser_sync/profile_sync_service.h" #include "components/browser_sync/profile_sync_service.h"
#include "components/history/core/browser/browsing_history_service.h" #include "components/history/core/browser/browsing_history_service.h"
#include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/core/service_access_type.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/history/history_service_factory.h" #include "ios/chrome/browser/history/history_service_factory.h"
#include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h"
#import "ios/chrome/browser/ui/history/history_table_container_view_controller.h" #import "ios/chrome/browser/ui/history/history_table_container_view_controller.h"
#include "ios/chrome/browser/ui/history/history_table_view_controller.h" #include "ios/chrome/browser/ui/history/history_table_view_controller.h"
#import "ios/chrome/browser/ui/history/history_transitioning_delegate.h" #import "ios/chrome/browser/ui/history/history_transitioning_delegate.h"
#include "ios/chrome/browser/ui/history/ios_browsing_history_driver.h" #include "ios/chrome/browser/ui/history/ios_browsing_history_driver.h"
#import "ios/chrome/browser/ui/util/form_sheet_navigation_controller.h" #import "ios/chrome/browser/ui/table_view/table_container_constants.h"
#include "ui/base/l10n/l10n_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."
...@@ -51,6 +49,14 @@ ...@@ -51,6 +49,14 @@
historyTableViewController.browserState = self.browserState; historyTableViewController.browserState = self.browserState;
historyTableViewController.loader = self.loader; historyTableViewController.loader = self.loader;
// Adds the "Done" button and hooks it up to |stop|.
UIBarButtonItem* dismissButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(stop)];
[dismissButton setAccessibilityIdentifier:kTableContainerDismissButtonId];
historyTableViewController.navigationItem.rightBarButtonItem = dismissButton;
// Initialize and configure HistoryServices. // Initialize and configure HistoryServices.
_browsingHistoryDriver = std::make_unique<IOSBrowsingHistoryDriver>( _browsingHistoryDriver = std::make_unique<IOSBrowsingHistoryDriver>(
self.browserState, historyTableViewController); self.browserState, historyTableViewController);
...@@ -63,34 +69,25 @@ ...@@ -63,34 +69,25 @@
historyTableViewController.historyService = _browsingHistoryService.get(); historyTableViewController.historyService = _browsingHistoryService.get();
// Initialize and configure HistoryContainerViewController. // Initialize and configure HistoryContainerViewController.
// Present HistoryContainerViewController.
self.historyContainerViewController = self.historyContainerViewController =
[[HistoryTableContainerViewController alloc] [[HistoryTableContainerViewController alloc]
initWithTable:historyTableViewController]; initWithTable:historyTableViewController];
self.historyContainerViewController.dispatcher = self.dispatcher; self.historyContainerViewController.dispatcher = self.dispatcher;
self.historyContainerViewController.title = self.historyContainerViewController.toolbarHidden = NO;
l10n_util::GetNSString(IDS_HISTORY_TITLE);
// TODO(crbug.com/805192): Move this configuration code to
// HistoryContainerVC once its created, we will use a dispatcher then.
[self.historyContainerViewController.dismissButton setTarget:self];
[self.historyContainerViewController.dismissButton setAction:@selector(stop)];
self.historyContainerViewController.navigationItem.rightBarButtonItem =
self.historyContainerViewController.dismissButton;
historyTableViewController.delegate = self.historyContainerViewController; historyTableViewController.delegate = self.historyContainerViewController;
// Present HistoryContainerViewController.
FormSheetNavigationController* navController =
[[FormSheetNavigationController alloc]
initWithRootViewController:self.historyContainerViewController];
self.historyTransitioningDelegate = self.historyTransitioningDelegate =
[[HistoryTransitioningDelegate alloc] init]; [[HistoryTransitioningDelegate alloc] init];
[navController.navigationBar setBackgroundImage:[UIImage new] self.historyContainerViewController.transitioningDelegate =
forBarMetrics:UIBarMetricsDefault]; self.historyTransitioningDelegate;
navController.navigationBar.translucent = NO; [self.historyContainerViewController
navController.transitioningDelegate = self.historyTransitioningDelegate; setModalPresentationStyle:UIModalPresentationCustom];
[navController setModalPresentationStyle:UIModalPresentationCustom]; [self.baseViewController
[self.baseViewController presentViewController:navController presentViewController:self.historyContainerViewController
animated:YES animated:YES
completion:nil]; completion:nil];
} }
- (void)stop { - (void)stop {
......
...@@ -4,89 +4,16 @@ ...@@ -4,89 +4,16 @@
#import "ios/chrome/browser/ui/history/history_table_container_view_controller.h" #import "ios/chrome/browser/ui/history/history_table_container_view_controller.h"
#include "base/mac/foundation_util.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#include "ios/chrome/browser/ui/history/history_table_view_controller.h"
#import "ios/chrome/browser/ui/table_view/table_container_bottom_toolbar.h"
#include "ui/base/l10n/l10n_util_mac.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
@interface HistoryTableContainerViewController ()
// This ViewController's searchController;
@property(nonatomic, strong) UISearchController* searchController;
@end
@implementation HistoryTableContainerViewController @implementation HistoryTableContainerViewController
@synthesize dispatcher = _dispatcher; @synthesize dispatcher = _dispatcher;
@synthesize searchController = _searchController;
- (instancetype)initWithTable: - (instancetype)initWithTable:
(ChromeTableViewController<HistoryTableUpdaterDelegate>*)table { (ChromeTableViewController<HistoryTableUpdaterDelegate>*)table {
self = [super initWithTable:table]; return [super initWithTable:table];
if (self) {
// Setup the bottom toolbar.
NSString* leadingButtonString = l10n_util::GetNSStringWithFixup(
IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG);
NSString* trailingButtonString =
l10n_util::GetNSString(IDS_HISTORY_START_EDITING_BUTTON);
TableContainerBottomToolbar* toolbar = [[TableContainerBottomToolbar alloc]
initWithLeadingButtonText:leadingButtonString
trailingButtonText:trailingButtonString];
[toolbar.leadingButton setTitleColor:[UIColor redColor]
forState:UIControlStateNormal];
self.bottomToolbar = toolbar;
// Setup toolbar buttons.
[self.bottomToolbar.leadingButton addTarget:self
action:@selector(openPrivacySettings)
forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self addSearchController];
}
// Creates and adds a UISearchController.
- (void)addSearchController {
// Init the searchController with nil so the results are displayed on the same
// TableView.
self.searchController =
[[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.dimsBackgroundDuringPresentation = NO;
// For iOS 11 and later, we place the search bar in the navigation bar, if not
// we place the search bar in the table view's header.
if (@available(iOS 11, *)) {
self.navigationItem.searchController = self.searchController;
// We want the search bar visible all the time.
self.navigationItem.hidesSearchBarWhenScrolling = NO;
} else {
self.tableViewController.tableView.tableHeaderView =
self.searchController.searchBar;
}
}
#pragma mark - Private Methods
- (void)openPrivacySettings {
// Ignore the button tap if |self| is presenting another ViewController.
// TODO(crbug.com/831865): Find a way to disable the button when a VC is
// presented.
if ([self presentedViewController]) {
return;
}
base::RecordAction(
base::UserMetricsAction("HistoryPage_InitClearBrowsingData"));
[self.dispatcher showClearBrowsingDataSettingsFromViewController:
self.navigationController];
} }
#pragma mark - HistoryTableViewControllerDelegate #pragma mark - HistoryTableViewControllerDelegate
......
...@@ -76,6 +76,8 @@ const int kMaxFetchCount = 100; ...@@ -76,6 +76,8 @@ const int kMaxFetchCount = 100;
@property(nonatomic, assign) BOOL filterQueryResult; @property(nonatomic, assign) BOOL filterQueryResult;
// YES if there is a search happening. // YES if there is a search happening.
@property(nonatomic, assign, getter=isSearching) BOOL searching; @property(nonatomic, assign, getter=isSearching) BOOL searching;
// This ViewController's searchController;
@property(nonatomic, strong) UISearchController* searchController;
@end @end
@implementation HistoryTableViewController @implementation HistoryTableViewController
...@@ -90,6 +92,7 @@ const int kMaxFetchCount = 100; ...@@ -90,6 +92,7 @@ const int kMaxFetchCount = 100;
@synthesize historyService = _historyService; @synthesize historyService = _historyService;
@synthesize loader = _loader; @synthesize loader = _loader;
@synthesize loading = _loading; @synthesize loading = _loading;
@synthesize searchController = _searchController;
@synthesize searching = _searching; @synthesize searching = _searching;
@synthesize shouldShowNoticeAboutOtherFormsOfBrowsingHistory = @synthesize shouldShowNoticeAboutOtherFormsOfBrowsingHistory =
_shouldShowNoticeAboutOtherFormsOfBrowsingHistory; _shouldShowNoticeAboutOtherFormsOfBrowsingHistory;
...@@ -114,6 +117,52 @@ const int kMaxFetchCount = 100; ...@@ -114,6 +117,52 @@ const int kMaxFetchCount = 100;
initWithTarget:self initWithTarget:self
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;
// Init the searchController with nil so the results are displayed on the same
// TableView.
self.searchController =
[[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.dimsBackgroundDuringPresentation = NO;
// Navigation controller configuration.
self.title = l10n_util::GetNSString(IDS_HISTORY_TITLE);
// For iOS 11 and later, place the search bar in the navigation bar. Otherwise
// place the search bar in the table view's header.
if (@available(iOS 11, *)) {
self.navigationItem.searchController = self.searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
} else {
self.tableView.tableHeaderView = self.searchController.searchBar;
}
// Set up the bottom toolbar buttons.
NSString* leadingButtonString = l10n_util::GetNSStringWithFixup(
IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG);
NSString* trailingButtonString =
l10n_util::GetNSString(IDS_HISTORY_START_EDITING_BUTTON);
UIBarButtonItem* leadingButton =
[[UIBarButtonItem alloc] initWithTitle:leadingButtonString
style:UIBarButtonItemStylePlain
target:nil
action:nil];
UIBarButtonItem* trailingButton =
[[UIBarButtonItem alloc] initWithTitle:trailingButtonString
style:UIBarButtonItemStylePlain
target:nil
action:nil];
UIBarButtonItem* spaceButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
leadingButton.tintColor = [UIColor redColor];
[self setToolbarItems:@[ leadingButton, spaceButton, trailingButton ]
animated:NO];
} }
// TODO(crbug.com/805190): These methods are supposed to be public, though we // TODO(crbug.com/805190): These methods are supposed to be public, though we
......
...@@ -10,10 +10,8 @@ ...@@ -10,10 +10,8 @@
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_mediator.h" #import "ios/chrome/browser/ui/recent_tabs/recent_tabs_mediator.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_table_view_controller.h" #import "ios/chrome/browser/ui/recent_tabs/recent_tabs_table_view_controller.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_transitioning_delegate.h" #import "ios/chrome/browser/ui/recent_tabs/recent_tabs_transitioning_delegate.h"
#import "ios/chrome/browser/ui/table_view/table_container_constants.h"
#import "ios/chrome/browser/ui/table_view/table_container_view_controller.h" #import "ios/chrome/browser/ui/table_view/table_container_view_controller.h"
#import "ios/chrome/browser/ui/util/form_sheet_navigation_controller.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_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."
...@@ -52,6 +50,15 @@ ...@@ -52,6 +50,15 @@
recentTabsTableViewController.dispatcher = self.dispatcher; recentTabsTableViewController.dispatcher = self.dispatcher;
recentTabsTableViewController.handsetCommandHandler = self; recentTabsTableViewController.handsetCommandHandler = self;
// Adds the "Done" button and hooks it up to |stop|.
UIBarButtonItem* dismissButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(stop)];
[dismissButton setAccessibilityIdentifier:kTableContainerDismissButtonId];
recentTabsTableViewController.navigationItem.rightBarButtonItem =
dismissButton;
// Initialize and configure RecentTabsMediator. // Initialize and configure RecentTabsMediator.
DCHECK(!self.mediator); DCHECK(!self.mediator);
self.mediator = [[RecentTabsMediator alloc] init]; self.mediator = [[RecentTabsMediator alloc] init];
...@@ -62,33 +69,21 @@ ...@@ -62,33 +69,21 @@
[self.mediator initObservers]; [self.mediator initObservers];
[self.mediator reloadSessions]; [self.mediator reloadSessions];
// Initialize and configure RecentTabsViewController. // Present RecentTabsViewController.
self.recentTabsContainerViewController = [[TableContainerViewController alloc] self.recentTabsContainerViewController = [[TableContainerViewController alloc]
initWithTable:recentTabsTableViewController]; initWithTable:recentTabsTableViewController];
self.recentTabsContainerViewController.title = self.recentTabsContainerViewController.toolbarHidden = YES;
l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_RECENT_TABS);
// TODO(crbug.com/805135): Move this configuration code to
// RecentTabsContainerVC once its created, we will use a dispatcher then.
[self.recentTabsContainerViewController.dismissButton setTarget:self];
[self.recentTabsContainerViewController.dismissButton
setAction:@selector(stop)];
self.recentTabsContainerViewController.navigationItem.rightBarButtonItem =
self.recentTabsContainerViewController.dismissButton;
// Present RecentTabsViewController.
FormSheetNavigationController* navController =
[[FormSheetNavigationController alloc]
initWithRootViewController:self.recentTabsContainerViewController];
self.recentTabsTransitioningDelegate = self.recentTabsTransitioningDelegate =
[[RecentTabsTransitioningDelegate alloc] init]; [[RecentTabsTransitioningDelegate alloc] init];
[navController.navigationBar setBackgroundImage:[UIImage new] self.recentTabsContainerViewController.transitioningDelegate =
forBarMetrics:UIBarMetricsDefault]; self.recentTabsTransitioningDelegate;
navController.navigationBar.translucent = NO; [self.recentTabsContainerViewController
navController.transitioningDelegate = self.recentTabsTransitioningDelegate; setModalPresentationStyle:UIModalPresentationCustom];
[navController setModalPresentationStyle:UIModalPresentationCustom]; [self.baseViewController
[self.baseViewController presentViewController:navController presentViewController:self.recentTabsContainerViewController
animated:YES animated:YES
completion:nil]; completion:nil];
} }
- (void)stop { - (void)stop {
......
...@@ -154,6 +154,12 @@ const int kRelativeTimeMaxHours = 4; ...@@ -154,6 +154,12 @@ const int kRelativeTimeMaxHours = 4;
action:@selector(handleTap:)]; action:@selector(handleTap:)];
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);
} }
#pragma mark - TableViewModel #pragma mark - TableViewModel
......
...@@ -7,8 +7,6 @@ source_set("table_view") { ...@@ -7,8 +7,6 @@ source_set("table_view") {
sources = [ sources = [
"chrome_table_view_controller.h", "chrome_table_view_controller.h",
"chrome_table_view_controller.mm", "chrome_table_view_controller.mm",
"table_container_bottom_toolbar.h",
"table_container_bottom_toolbar.mm",
"table_container_constants.h", "table_container_constants.h",
"table_container_constants.mm", "table_container_constants.mm",
"table_container_view_controller.h", "table_container_view_controller.h",
...@@ -19,9 +17,7 @@ source_set("table_view") { ...@@ -19,9 +17,7 @@ source_set("table_view") {
deps = [ deps = [
":styler", ":styler",
"//base", "//base",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/list_model", "//ios/chrome/browser/ui/list_model",
"//ui/base",
] ]
public_deps = [ public_deps = [
"//ios/chrome/browser/ui/table_view/cells", "//ios/chrome/browser/ui/table_view/cells",
...@@ -57,7 +53,6 @@ source_set("unit_tests") { ...@@ -57,7 +53,6 @@ source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"chrome_table_view_controller_unittest.mm", "chrome_table_view_controller_unittest.mm",
"table_container_bottom_toolbar_unittest.mm",
"table_view_model_unittest.mm", "table_view_model_unittest.mm",
] ]
deps = [ deps = [
......
// 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_TABLE_CONTAINER_BOTTOM_TOOLBAR_H_
#define IOS_CHROME_BROWSER_UI_TABLE_VIEW_TABLE_CONTAINER_BOTTOM_TOOLBAR_H_
#import <UIKit/UIKit.h>
// TableContainer Bottom Toolbar that contains action buttons.
@interface TableContainerBottomToolbar : UIView
// Returns a Toolbar with leading and/or trailing buttons. If any of the
// parameters are nil or an empty string, a button will not be created.
- (instancetype)initWithLeadingButtonText:(NSString*)leadingButtonText
trailingButtonText:(NSString*)trailingButtonText
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
// Leading Toolbar button, nil if there's no leading button.
@property(nonatomic, strong, readonly) UIButton* leadingButton;
// Trailing Toolbar button, nil if there's no trailing button.
@property(nonatomic, strong, readonly) UIButton* trailingButton;
@end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_TABLE_CONTAINER_BOTTOM_TOOLBAR_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/table_container_bottom_toolbar.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Horizontal margins.
const CGFloat kHorizontalMargin = 10.0;
}
@interface TableContainerBottomToolbar ()
// Re-declare as readwrite.
@property(nonatomic, strong, readwrite) UIButton* leadingButton;
// Re-declare as readwrite.
@property(nonatomic, strong, readwrite) UIButton* trailingButton;
// StackView that contains the buttons.
@property(nonatomic, strong) UIStackView* stackView;
@end
@implementation TableContainerBottomToolbar
@synthesize leadingButton = _leadingButton;
@synthesize trailingButton = _trailingButton;
@synthesize stackView = _stackView;
- (instancetype)initWithLeadingButtonText:(NSString*)leadingButtonText
trailingButtonText:(NSString*)trailingButtonText {
self = [super initWithFrame:CGRectZero];
if (self) {
_stackView = [[UIStackView alloc] initWithFrame:CGRectZero];
// Configure and add the buttons to _stackView.
if (leadingButtonText && ![leadingButtonText isEqualToString:@""]) {
_leadingButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_leadingButton setTitle:leadingButtonText forState:UIControlStateNormal];
[_leadingButton setTitleColor:self.tintColor
forState:UIControlStateNormal];
[_stackView addArrangedSubview:_leadingButton];
}
if (trailingButtonText && ![trailingButtonText isEqualToString:@""]) {
_trailingButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_trailingButton setTitle:trailingButtonText
forState:UIControlStateNormal];
[_trailingButton setTitleColor:self.tintColor
forState:UIControlStateNormal];
[_stackView addArrangedSubview:_trailingButton];
}
// Configure the stackView.
_stackView.translatesAutoresizingMaskIntoConstraints = NO;
_stackView.distribution = UIStackViewDistributionEqualSpacing;
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.alignment = UIStackViewAlignmentCenter;
[self addSubview:_stackView];
// Set and activate constraints.
[NSLayoutConstraint activateConstraints:@[
[_stackView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor
constant:kHorizontalMargin],
[_stackView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor
constant:-kHorizontalMargin],
[_stackView.topAnchor constraintEqualToAnchor:self.topAnchor],
[_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
]];
}
return self;
}
@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.
#import "ios/chrome/browser/ui/table_view/table_container_bottom_toolbar.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
using TableContainerBottomToolbarTest = PlatformTest;
TEST_F(TableContainerBottomToolbarTest, ButtonsText) {
TableContainerBottomToolbar* toolbar =
[[TableContainerBottomToolbar alloc] initWithLeadingButtonText:@"Left"
trailingButtonText:@"Right"];
EXPECT_EQ(@"Left", toolbar.leadingButton.titleLabel.text);
EXPECT_EQ(@"Right", toolbar.trailingButton.titleLabel.text);
}
TEST_F(TableContainerBottomToolbarTest, NoButtonsWithNil) {
TableContainerBottomToolbar* toolbar =
[[TableContainerBottomToolbar alloc] initWithLeadingButtonText:@"Left"
trailingButtonText:nil];
EXPECT_EQ(@"Left", toolbar.leadingButton.titleLabel.text);
EXPECT_EQ(nil, toolbar.trailingButton);
toolbar =
[[TableContainerBottomToolbar alloc] initWithLeadingButtonText:nil
trailingButtonText:@"Right"];
EXPECT_EQ(nil, toolbar.leadingButton);
EXPECT_EQ(@"Right", toolbar.trailingButton.titleLabel.text);
toolbar = [[TableContainerBottomToolbar alloc] initWithLeadingButtonText:nil
trailingButtonText:nil];
EXPECT_EQ(nil, toolbar.leadingButton);
EXPECT_EQ(nil, toolbar.trailingButton);
}
TEST_F(TableContainerBottomToolbarTest, NoButtonsWithEmptyString) {
TableContainerBottomToolbar* toolbar =
[[TableContainerBottomToolbar alloc] initWithLeadingButtonText:@"Left"
trailingButtonText:@""];
EXPECT_EQ(@"Left", toolbar.leadingButton.titleLabel.text);
EXPECT_EQ(nil, toolbar.trailingButton);
toolbar =
[[TableContainerBottomToolbar alloc] initWithLeadingButtonText:@""
trailingButtonText:@"Right"];
EXPECT_EQ(nil, toolbar.leadingButton);
EXPECT_EQ(@"Right", toolbar.trailingButton.titleLabel.text);
toolbar = [[TableContainerBottomToolbar alloc] initWithLeadingButtonText:@""
trailingButtonText:@""];
EXPECT_EQ(nil, toolbar.leadingButton);
EXPECT_EQ(nil, toolbar.trailingButton);
}
} // namespace
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
@class ChromeTableViewController; @class ChromeTableViewController;
@class TableContainerBottomToolbar; @class TableContainerBottomToolbar;
// TableContainerViewController contains a ChromeTableViewController and a // TableContainerViewController encapsulates a ChromeTableViewController inside
// Bottom Toolbar that interacts with the ChromeTableViewController. // a UINavigationController.
@interface TableContainerViewController : UIViewController @interface TableContainerViewController : UINavigationController
- (instancetype)initWithTable:(ChromeTableViewController*)table - (instancetype)initWithTable:(ChromeTableViewController*)table
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
...@@ -21,15 +21,9 @@ ...@@ -21,15 +21,9 @@
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE; - (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
// The bottom toolbar owned by this ViewController.
@property(nonatomic, strong) TableContainerBottomToolbar* bottomToolbar;
// UIBarButtonItem to be used on a Navigation Controller to dismiss this
// ViewController.
@property(nonatomic, strong, readonly) UIBarButtonItem* dismissButton;
// The ChromeTableViewController owned by this ViewController. // The ChromeTableViewController owned by this ViewController.
@property(nonatomic, strong) ChromeTableViewController* tableViewController; @property(nonatomic, readonly, strong)
ChromeTableViewController* tableViewController;
@end @end
......
...@@ -5,111 +5,39 @@ ...@@ -5,111 +5,39 @@
#import "ios/chrome/browser/ui/table_view/table_container_view_controller.h" #import "ios/chrome/browser/ui/table_view/table_container_view_controller.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
#import "ios/chrome/browser/ui/table_view/table_container_bottom_toolbar.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/browser/ui/table_view/table_container_constants.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_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
@interface TableContainerViewController ()
// Change dismissButton to readwrite.
@property(nonatomic, strong, readwrite) UIBarButtonItem* dismissButton;
@end
@implementation TableContainerViewController @implementation TableContainerViewController
@synthesize bottomToolbar = _bottomToolbar;
@synthesize dismissButton = _dismissButton;
@synthesize tableViewController = _tableViewController; @synthesize tableViewController = _tableViewController;
#pragma mark - Public Interface #pragma mark - Public Interface
- (instancetype)initWithTable:(ChromeTableViewController*)table { - (instancetype)initWithTable:(ChromeTableViewController*)table {
self = [super initWithNibName:nil bundle:nil]; self = [super initWithRootViewController:table];
if (self) { if (self) {
self.tableViewController = table; _tableViewController = table;
// Dismiss Button configuration.
_dismissButton = [[UIBarButtonItem alloc] init];
_dismissButton.style = UIBarButtonItemStylePlain;
_dismissButton.title =
l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON);
[_dismissButton setAccessibilityIdentifier:kTableContainerDismissButtonId];
} }
return self; return self;
} }
#pragma mark Setters and Getters
// TODO(crbug.com/805178): Temporary Toolbar code for prototyping purposes.
- (void)setBottomToolbar:(TableContainerBottomToolbar*)bottomToolbar {
_bottomToolbar = bottomToolbar;
_bottomToolbar.backgroundColor = [UIColor lightGrayColor];
_bottomToolbar.translatesAutoresizingMaskIntoConstraints = NO;
_bottomToolbar.alpha = 0.8;
}
#pragma mark - View Lifecycle #pragma mark - View Lifecycle
- (void)viewDidLoad { - (void)viewDidLoad {
// If the NavigationBar is not translucid we need to set [self.navigationBar setBackgroundImage:[UIImage new]
// |self.extendedLayoutIncludesOpaqueBars| to YES in order to avoid a top forBarMetrics:UIBarMetricsDefault];
// margin inset on the |_tableViewController| subview.
if (!self.navigationController.navigationBar.isTranslucent) {
self.extendedLayoutIncludesOpaqueBars = YES;
}
// NavigationController if (self.tableViewController.styler.tableViewBackgroundColor !=
if (@available(iOS 11, *)) { [UIColor clearColor]) {
self.navigationController.navigationBar.prefersLargeTitles = YES; self.navigationBar.translucent = NO;
} }
// TableView if (@available(iOS 11, *)) {
self.tableViewController.tableView.translatesAutoresizingMaskIntoConstraints = self.navigationBar.prefersLargeTitles = YES;
NO;
[self addChildViewController:self.tableViewController];
[self.view addSubview:self.tableViewController.view];
[self.tableViewController didMoveToParentViewController:self];
// Add Bottom Toolbar to view hierarchy if it exists.
if (self.bottomToolbar) {
// Add the Bottom Toolbar after the TableView since it needs to be on top of
// the view hierarchy.
[self.view addSubview:_bottomToolbar];
[self setUpBottomToolbarConstraints];
} }
[self setUpConstraints];
}
#pragma mark - UI Setup
- (void)setUpConstraints {
NSArray* constraints = @[
[self.tableViewController.view.topAnchor
constraintEqualToAnchor:self.view.topAnchor],
[self.tableViewController.view.bottomAnchor
constraintEqualToAnchor:self.view.bottomAnchor],
[self.tableViewController.view.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor],
[self.tableViewController.view.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor],
];
[NSLayoutConstraint activateConstraints:constraints];
}
- (void)setUpBottomToolbarConstraints {
NSArray* constraints = @[
[self.bottomToolbar.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor],
[self.bottomToolbar.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor],
[self.bottomToolbar.bottomAnchor
constraintEqualToAnchor:self.view.bottomAnchor],
[self.bottomToolbar.heightAnchor constraintEqualToConstant:40],
];
[NSLayoutConstraint activateConstraints:constraints];
} }
@end @end
...@@ -30,7 +30,6 @@ group("features") { ...@@ -30,7 +30,6 @@ group("features") {
"//ios/showcase/payments", "//ios/showcase/payments",
"//ios/showcase/settings", "//ios/showcase/settings",
"//ios/showcase/tab_grid", "//ios/showcase/tab_grid",
"//ios/showcase/table_view",
"//ios/showcase/text_badge_view", "//ios/showcase/text_badge_view",
"//ios/showcase/uikit_table_view_cell", "//ios/showcase/uikit_table_view_cell",
"//ios/showcase/widget", "//ios/showcase/widget",
......
# 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.
source_set("table_view") {
sources = [
"sc_table_container_coordinator.h",
"sc_table_container_coordinator.mm",
]
deps = [
"//base",
"//ios/chrome/browser/ui/table_view",
"//ios/showcase/common",
]
libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
// 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_SHOWCASE_TABLE_VIEW_SC_TABLE_CONTAINER_COORDINATOR_H_
#define IOS_SHOWCASE_TABLE_VIEW_SC_TABLE_CONTAINER_COORDINATOR_H_
#import "ios/showcase/common/navigation_coordinator.h"
@interface SCTableContainerCoordinator : NSObject<NavigationCoordinator>
@end
#endif // IOS_SHOWCASE_TABLE_VIEW_SC_TABLE_CONTAINER_COORDINATOR_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/showcase/table_view/sc_table_container_coordinator.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
#import "ios/chrome/browser/ui/table_view/table_container_bottom_toolbar.h"
#import "ios/chrome/browser/ui/table_view/table_container_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface SCTableContainerCoordinator ()
@property(nonatomic, strong) TableContainerViewController* viewController;
@end
@implementation SCTableContainerCoordinator
@synthesize viewController = _viewController;
@synthesize baseViewController = _baseViewController;
- (void)start {
self.viewController = [[TableContainerViewController alloc]
initWithTable:[[ChromeTableViewController alloc]
initWithStyle:UITableViewStylePlain]];
self.viewController.title = @"Table View";
TableContainerBottomToolbar* toolbar =
[[TableContainerBottomToolbar alloc] initWithLeadingButtonText:@"Left"
trailingButtonText:@"Right"];
[toolbar.trailingButton setTitleColor:[UIColor redColor]
forState:UIControlStateNormal];
self.viewController.bottomToolbar = toolbar;
[self.baseViewController pushViewController:self.viewController animated:YES];
}
@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