Commit 9bc6853d authored by gambard's avatar gambard Committed by Commit bot

Creates the Suggestions UI

This CL creates the Suggestions UI with a Collection View.

BUG=679369

Review-Url: https://codereview.chromium.org/2619353004
Cr-Commit-Position: refs/heads/master@{#442850}
parent 8ef5dcc3
# Copyright 2016 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("suggestions") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"suggestions_commands.h",
"suggestions_item_actions.h",
"suggestions_view_controller.h",
"suggestions_view_controller.mm",
]
deps = [
"//base",
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/collection_view",
"//ios/third_party/material_roboto_font_loader_ios",
]
public_deps = [
"//ios/third_party/material_components_ios",
]
}
// Copyright 2016 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_SUGGESTIONS_SUGGESTIONS_COMMANDS_H_
#define IOS_CHROME_BROWSER_UI_SUGGESTIONS_SUGGESTIONS_COMMANDS_H_
// Commands protocol for the SuggestionsViewController.
@protocol SuggestionsCommands
// Adds a new empty SuggestionItem.
- (void)addEmptyItem;
@end
#endif // IOS_CHROME_BROWSER_UI_SUGGESTIONS_SUGGESTIONS_COMMANDS_H_
// Copyright 2016 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_SUGGESTIONS_SUGGESTIONS_ITEM_ACTIONS_H_
#define IOS_CHROME_BROWSER_UI_SUGGESTIONS_SUGGESTIONS_ITEM_ACTIONS_H_
// Protocol handling the actions sent in the responder chain by the suggestions
// items.
@protocol SuggestionsItemActions
// Sent through the responder chain when the button of a suggestion item is
// pressed.
- (void)addNewItem:(id)sender;
@end
#endif // IOS_CHROME_BROWSER_UI_SUGGESTIONS_SUGGESTIONS_ITEM_ACTIONS_H_
// Copyright 2016 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_SUGGESTIONS_SUGGESTIONS_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SUGGESTIONS_SUGGESTIONS_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
@protocol SuggestionsCommands;
// CollectionViewController to display the suggestions items.
@interface SuggestionsViewController : CollectionViewController
// Handler for the commands sent by the SuggestionsViewController.
@property(nonatomic, weak) id<SuggestionsCommands> suggestionCommandHandler;
@end
#endif // IOS_CHROME_BROWSER_UI_SUGGESTIONS_SUGGESTIONS_VIEW_CONTROLLER_H_
// Copyright 2016 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/suggestions/suggestions_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/suggestions/suggestions_commands.h"
#import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface SuggestionsViewController ()<SuggestionsItemActions>
@end
@implementation SuggestionsViewController
@synthesize suggestionCommandHandler = _suggestionCommandHandler;
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.collectionView.delegate = self;
self.styler.cellStyle = MDCCollectionViewCellStyleCard;
}
#pragma mark - MDCCollectionViewStylingDelegate
- (CGFloat)collectionView:(UICollectionView*)collectionView
cellHeightAtIndexPath:(NSIndexPath*)indexPath {
CollectionViewItem* item =
[self.collectionViewModel itemAtIndexPath:indexPath];
UIEdgeInsets inset = [self collectionView:collectionView
layout:collectionView.collectionViewLayout
insetForSectionAtIndex:indexPath.section];
return [MDCCollectionViewCell
cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) -
inset.left - inset.right
forItem:item];
}
#pragma mark - SuggestionsItemActions
- (void)addNewItem:(id)sender {
[self.suggestionCommandHandler addEmptyItem];
}
@end
...@@ -28,6 +28,7 @@ group("features") { ...@@ -28,6 +28,7 @@ group("features") {
"//ios/chrome/browser/ui/tools:tools_ui", "//ios/chrome/browser/ui/tools:tools_ui",
"//ios/showcase/settings", "//ios/showcase/settings",
"//ios/showcase/strip", "//ios/showcase/strip",
"//ios/showcase/suggestions",
"//ios/showcase/tab_grid", "//ios/showcase/tab_grid",
"//ios/showcase/uikit_table_view_cell", "//ios/showcase/uikit_table_view_cell",
] ]
......
...@@ -25,6 +25,13 @@ source_set("main") { ...@@ -25,6 +25,13 @@ source_set("main") {
] ]
deps = [ deps = [
":core", ":core",
# Needed to disable the tests hooks.
"//ios/chrome/app:tests_fake_hook",
# Needed for including ios/chrome/browser/ui.
"//ios/chrome/browser/tabs:tabs_internal",
"//ios/chrome/browser/ui:ui_internal",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
......
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
showcase::kClassForInstantiationKey : @"SettingsCoordinator", showcase::kClassForInstantiationKey : @"SettingsCoordinator",
showcase::kUseCaseKey : @"Main settings screen", showcase::kUseCaseKey : @"Main settings screen",
}, },
@{
showcase::kClassForDisplayKey : @"SuggestionsViewController",
showcase::kClassForInstantiationKey : @"SCSuggestionsCoordinator",
showcase::kUseCaseKey : @"New Suggestions UI",
},
@{ @{
showcase::kClassForDisplayKey : @"MenuViewController", showcase::kClassForDisplayKey : @"MenuViewController",
showcase::kClassForInstantiationKey : @"MenuViewController", showcase::kClassForInstantiationKey : @"MenuViewController",
......
# Copyright 2016 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("suggestions") {
sources = [
"sc_suggestions_coordinator.h",
"sc_suggestions_coordinator.mm",
]
deps = [
"//base",
"//ios/chrome/browser/ui/suggestions",
"//ios/showcase/common",
]
libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("eg_tests") {
testonly = true
sources = [
"sc_suggestions_egtest.mm",
]
deps = [
"//ios/showcase/test",
"//ios/third_party/earl_grey",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
include_rules = [
"+ios/third_party/material_components_ios",
]
// Copyright 2016 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_SUGGESTIONS_SC_SUGGESTIONS_COORDINATOR_H_
#define IOS_SHOWCASE_SUGGESTIONS_SC_SUGGESTIONS_COORDINATOR_H_
#import <UIKit/UIKit.h>
#import "ios/showcase/common/coordinator.h"
@interface SCSuggestionsCoordinator : NSObject<Coordinator>
// Redefined to be a UINavigationController.
@property(nonatomic, weak) UINavigationController* baseViewController;
@end
#endif // IOS_SHOWCASE_SUGGESTIONS_SC_SUGGESTIONS_COORDINATOR_H_
// Copyright 2016 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/suggestions/sc_suggestions_coordinator.h"
#import "ios/chrome/browser/ui/suggestions/suggestions_commands.h"
#import "ios/chrome/browser/ui/suggestions/suggestions_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface SCSuggestionsCoordinator ()<SuggestionsCommands>
@end
@implementation SCSuggestionsCoordinator
@synthesize baseViewController;
#pragma mark - Coordinator
- (void)start {
SuggestionsViewController* suggestion = [[SuggestionsViewController alloc]
initWithStyle:CollectionViewControllerStyleDefault];
suggestion.suggestionCommandHandler = self;
[self.baseViewController pushViewController:suggestion animated:YES];
}
#pragma mark - SuggestionsCommands
- (void)addEmptyItem {
}
@end
// Copyright 2016 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 <EarlGrey/EarlGrey.h>
#import "ios/showcase/test/showcase_test_case.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Tests for the suggestions view controller.
@interface SCSuggestionsTestCase : ShowcaseTestCase
@end
@implementation SCSuggestionsTestCase
// Tests launching TabGridViewController and tapping a cell.
- (void)testLaunchAndTappingCell {
[[EarlGrey selectElementWithMatcher:grey_text(@"SuggestionsViewController")]
performAction:grey_tap()];
}
@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