Commit 7fb547a7 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Add tab grid to view controller and showcase

Bug: 804496, 804497
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I05b6627c4eb9ab6ae33e337631b7f1e70466730c
Reviewed-on: https://chromium-review.googlesource.com/924650
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@{#537485}
parent 39d52aa5
......@@ -11,6 +11,8 @@
// A view controller that contains a grid of items.
@interface GridViewController : UIViewController<GridConsumer>
// The gridView is accessible to manage the content inset behavior.
@property(nonatomic, readonly) UIScrollView* gridView;
@end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_VIEW_CONTROLLER_H_
......@@ -55,6 +55,12 @@ NSString* const kCellIdentifier = @"GridCellIdentifier";
self.view = collectionView;
}
#pragma mark - Public
- (UIScrollView*)gridView {
return self.collectionView;
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView*)collectionView
......@@ -78,9 +84,7 @@ NSString* const kCellIdentifier = @"GridCellIdentifier";
self.items = [items mutableCopy];
self.selectedIndex = selectedIndex;
if ([self isViewLoaded]) {
[self.collectionView
reloadItemsAtIndexPaths:[self.collectionView
indexPathsForVisibleItems]];
[self.collectionView reloadData];
}
}
......
......@@ -7,9 +7,13 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/tab_grid/grid_consumer.h"
// View controller representing a tab switcher. The tab switcher has an
// incognito tab grid, regular tab grid, and remote tabs.
@interface TabGridViewController : UIViewController
@property(nonatomic, readonly) id<GridConsumer> regularTabsConsumer;
@property(nonatomic, readonly) id<GridConsumer> incognitoTabsConsumer;
@end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_TAB_GRID_VIEW_CONTROLLER_H_
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/tab_grid/tab_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_top_toolbar.h"
......@@ -11,13 +12,63 @@
#error "This file requires ARC support."
#endif
@interface TabGridViewController ()
@property(nonatomic, weak) GridViewController* regularTabsViewController;
@property(nonatomic, weak) GridViewController* incognitoTabsViewController;
@end
@implementation TabGridViewController
@synthesize regularTabsViewController = _regularTabsViewController;
@synthesize incognitoTabsViewController = _incognitoTabsViewController;
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupRegularTabsViewController];
[self setupToolbars];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
#pragma mark - Public
- (id<GridConsumer>)regularTabsConsumer {
return self.regularTabsViewController;
}
- (id<GridConsumer>)incognitoTabsConsumer {
return self.incognitoTabsViewController;
}
#pragma mark - Private
// Adds the regular tabs GridViewController as a contained view controller, and
// sets constraints.
- (void)setupRegularTabsViewController {
GridViewController* viewController = [[GridViewController alloc] init];
viewController.view.translatesAutoresizingMaskIntoConstraints = NO;
[self addChildViewController:viewController];
[self.view addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
self.regularTabsViewController = viewController;
NSArray* constraints = @[
[viewController.view.topAnchor constraintEqualToAnchor:self.view.topAnchor],
[viewController.view.bottomAnchor
constraintEqualToAnchor:self.view.bottomAnchor],
[viewController.view.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor],
[viewController.view.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor],
];
[NSLayoutConstraint activateConstraints:constraints];
}
// Adds the top and bottom toolbars and sets constraints.
- (void)setupToolbars {
UIView* topToolbar = [[TabGridTopToolbar alloc] init];
topToolbar.translatesAutoresizingMaskIntoConstraints = NO;
......@@ -63,10 +114,12 @@
]];
}
[NSLayoutConstraint activateConstraints:constraints];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
// The content inset of the tab grids must be modified so that the toolbars do
// not obscure the tabs.
self.regularTabsViewController.gridView.contentInset =
UIEdgeInsetsMake(topToolbar.intrinsicContentSize.height, 0,
bottomToolbar.intrinsicContentSize.height, 0);
}
@end
......@@ -4,13 +4,14 @@
#import "ios/showcase/tab_grid/sc_tab_grid_coordinator.h"
#import "ios/chrome/browser/ui/tab_grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface SCTabGridCoordinator ()
@interface SCTabGridCoordinator ()<UINavigationControllerDelegate>
@property(nonatomic, strong) TabGridViewController* viewController;
@end
......@@ -20,9 +21,29 @@
- (void)start {
self.viewController = [[TabGridViewController alloc] init];
self.viewController.title = @"Tab Grid";
[self.baseViewController setHidesBarsOnSwipe:YES];
self.viewController.title = @"Full TabGrid UI";
self.baseViewController.delegate = self;
self.baseViewController.hidesBarsOnSwipe = YES;
[self.baseViewController pushViewController:self.viewController animated:YES];
}
#pragma mark - UINavigationControllerDelegate
// This delegate method is used as a way to have a completion handler after
// pushing onto a navigation controller.
- (void)navigationController:(UINavigationController*)navigationController
didShowViewController:(UIViewController*)viewController
animated:(BOOL)animated {
if (viewController != self.viewController)
return;
NSMutableArray* items = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++) {
GridItem* item = [[GridItem alloc] init];
item.title = @"The New York Times - Breaking News";
[items addObject:item];
}
[self.viewController.regularTabsConsumer populateItems:items selectedIndex:0];
}
@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