Commit 4779b989 authored by adamta's avatar adamta Committed by Chromium LUCI CQ

[iOS] Use new scroll delegate + Rename feed wrapper

Uses new feed initializer with custom scroll delegate. Reorders
component creation in NewTabPageCoordinator so that delegates can be
passed appropriately. Renamed DiscoverFeedViewController to
DiscoverFeedWrapperViewController for clarity on what it does.

Bug: 1114792
Change-Id: Iccdc7bf0efeda2252e0937d8665f1c33b09d9b87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593471
Commit-Queue: Adam Trudeau-Arcaro <adamta@google.com>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837432}
parent 3fb0816a
...@@ -54,8 +54,8 @@ source_set("util") { ...@@ -54,8 +54,8 @@ source_set("util") {
source_set("ntp_internal") { source_set("ntp_internal") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"discover_feed_view_controller.h", "discover_feed_wrapper_view_controller.h",
"discover_feed_view_controller.mm", "discover_feed_wrapper_view_controller.mm",
"incognito_view.h", "incognito_view.h",
"incognito_view.mm", "incognito_view.mm",
"incognito_view_controller.h", "incognito_view_controller.h",
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_NTP_DISCOVER_FEED_VIEW_CONTROLLER_H_ #ifndef IOS_CHROME_BROWSER_UI_NTP_DISCOVER_FEED_WRAPPER_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_NTP_DISCOVER_FEED_VIEW_CONTROLLER_H_ #define IOS_CHROME_BROWSER_UI_NTP_DISCOVER_FEED_WRAPPER_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
// View controller wrapping a Discover feed view controller // View controller wrapping a Discover feed view controller
// (|self.discoverFeed|) originating from the provider. // (|self.discoverFeed|) originating from the provider.
@interface DiscoverFeedViewController : UIViewController @interface DiscoverFeedWrapperViewController : UIViewController
// Feed view controller being contained by this view controller. This is the // Feed view controller being contained by this view controller. This is the
// view controller that is wrapped by this view controller. // view controller that is wrapped by this view controller.
...@@ -30,4 +30,4 @@ ...@@ -30,4 +30,4 @@
@end @end
#endif // IOS_CHROME_BROWSER_UI_NTP_DISCOVER_FEED_VIEW_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_NTP_DISCOVER_FEED_WRAPPER_VIEW_CONTROLLER_H_
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/ntp/discover_feed_view_controller.h" #import "ios/chrome/browser/ui/ntp/discover_feed_wrapper_view_controller.h"
#import "ios/chrome/common/ui/util/constraints_ui_util.h" #import "ios/chrome/common/ui/util/constraints_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 DiscoverFeedViewController @implementation DiscoverFeedWrapperViewController
- (instancetype)initWithDiscoverFeedViewController: - (instancetype)initWithDiscoverFeedViewController:
(UIViewController*)discoverFeed { (UIViewController*)discoverFeed {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#import "ios/chrome/browser/ui/main/scene_state.h" #import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/main/scene_state_browser_agent.h" #import "ios/chrome/browser/ui/main/scene_state_browser_agent.h"
#import "ios/chrome/browser/ui/main/scene_state_observer.h" #import "ios/chrome/browser/ui/main/scene_state_observer.h"
#import "ios/chrome/browser/ui/ntp/discover_feed_view_controller.h" #import "ios/chrome/browser/ui/ntp/discover_feed_wrapper_view_controller.h"
#import "ios/chrome/browser/ui/ntp/incognito_view_controller.h" #import "ios/chrome/browser/ui/ntp/incognito_view_controller.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_feature.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_feature.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_view_controller.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_view_controller.h"
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
// View controller wrapping the Discover feed. // View controller wrapping the Discover feed.
@property(nonatomic, strong) @property(nonatomic, strong)
DiscoverFeedViewController* discoverFeedViewController; DiscoverFeedWrapperViewController* discoverFeedWrapperViewController;
// View controller for the incognito NTP. // View controller for the incognito NTP.
@property(nonatomic, strong) IncognitoViewController* incognitoViewController; @property(nonatomic, strong) IncognitoViewController* incognitoViewController;
...@@ -97,19 +97,22 @@ ...@@ -97,19 +97,22 @@
[self.contentSuggestionsCoordinator start]; [self.contentSuggestionsCoordinator start];
if (IsRefactoredNTP()) { if (IsRefactoredNTP()) {
// TODO(crbug.com/1114792): Use function with scroll delegate. self.ntpViewController = [[NewTabPageViewController alloc]
UIViewController* discoverFeed = initWithContentSuggestionsViewController:
self.contentSuggestionsCoordinator.viewController];
UIViewController* discoverFeedViewController =
ios::GetChromeBrowserProvider() ios::GetChromeBrowserProvider()
->GetDiscoverFeedProvider() ->GetDiscoverFeedProvider()
->NewFeedViewController(self.browser); ->NewFeedViewControllerWithScrollDelegate(self.browser,
self.ntpViewController);
self.discoverFeedViewController = [[DiscoverFeedViewController alloc] self.discoverFeedWrapperViewController =
initWithDiscoverFeedViewController:discoverFeed]; [[DiscoverFeedWrapperViewController alloc]
initWithDiscoverFeedViewController:discoverFeedViewController];
self.ntpViewController = [[NewTabPageViewController alloc] self.ntpViewController.discoverFeedWrapperViewController =
initWithDiscoverFeedViewController:self.discoverFeedViewController self.discoverFeedWrapperViewController;
contentSuggestionsViewController:self.contentSuggestionsCoordinator
.viewController];
} }
base::RecordAction(base::UserMetricsAction("MobileNTPShowMostVisited")); base::RecordAction(base::UserMetricsAction("MobileNTPShowMostVisited"));
...@@ -134,6 +137,8 @@ ...@@ -134,6 +137,8 @@
[sceneState removeObserver:self]; [sceneState removeObserver:self];
self.contentSuggestionsCoordinator = nil; self.contentSuggestionsCoordinator = nil;
self.incognitoViewController = nil; self.incognitoViewController = nil;
self.ntpViewController = nil;
self.discoverFeedWrapperViewController = nil;
self.started = NO; self.started = NO;
} }
......
...@@ -8,21 +8,22 @@ ...@@ -8,21 +8,22 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@class ContentSuggestionsViewController; @class ContentSuggestionsViewController;
@class DiscoverFeedViewController; @class DiscoverFeedWrapperViewController;
// View controller containing all the content presented on a standard, // View controller containing all the content presented on a standard,
// non-incognito new tab page. // non-incognito new tab page.
@interface NewTabPageViewController : UIViewController <UIScrollViewDelegate> @interface NewTabPageViewController : UIViewController <UIScrollViewDelegate>
// View controller wrapping the Discover feed.
@property(nonatomic, strong)
DiscoverFeedWrapperViewController* discoverFeedWrapperViewController;
// Initializes view controller with NTP content view controllers. // Initializes view controller with NTP content view controllers.
// |discoverFeedViewController| represents the Discover feed for suggesting // |discoverFeedViewController| represents the Discover feed for suggesting
// articles. |contentSuggestionsViewController| represents other content // articles. |contentSuggestionsViewController| represents other content
// suggestions, such as the most visited site tiles. // suggestions, such as the most visited site tiles.
- (instancetype)initWithDiscoverFeedViewController: - (instancetype)initWithContentSuggestionsViewController:
(DiscoverFeedViewController*)discoverFeedViewController (UICollectionViewController*)contentSuggestionsViewController
contentSuggestionsViewController:
(UICollectionViewController*)
contentSuggestionsViewController
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithNibName:(NSString*)name - (instancetype)initWithNibName:(NSString*)name
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#import "ios/chrome/browser/ui/ntp/new_tab_page_view_controller.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_view_controller.h"
#import "ios/chrome/browser/ui/ntp/discover_feed_view_controller.h" #import "base/check.h"
#import "ios/chrome/browser/ui/ntp/discover_feed_wrapper_view_controller.h"
#import "ios/chrome/common/ui/util/constraints_ui_util.h" #import "ios/chrome/common/ui/util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -15,10 +16,6 @@ ...@@ -15,10 +16,6 @@
@interface NewTabPageViewController () @interface NewTabPageViewController ()
// View controller representing the Discover feed.
@property(nonatomic, strong)
DiscoverFeedViewController* discoverFeedViewController;
// View controller representing the NTP content suggestions. These suggestions // View controller representing the NTP content suggestions. These suggestions
// include the most visited site tiles, the shortcut tiles, the fake omnibox and // include the most visited site tiles, the shortcut tiles, the fake omnibox and
// the Google doodle. // the Google doodle.
...@@ -29,14 +26,10 @@ ...@@ -29,14 +26,10 @@
@implementation NewTabPageViewController @implementation NewTabPageViewController
- (instancetype)initWithDiscoverFeedViewController: - (instancetype)initWithContentSuggestionsViewController:
(DiscoverFeedViewController*)discoverFeedViewController (UICollectionViewController*)contentSuggestionsViewController {
contentSuggestionsViewController:
(UICollectionViewController*)
contentSuggestionsViewController {
self = [super initWithNibName:nil bundle:nil]; self = [super initWithNibName:nil bundle:nil];
if (self) { if (self) {
_discoverFeedViewController = discoverFeedViewController;
_contentSuggestionsViewController = contentSuggestionsViewController; _contentSuggestionsViewController = contentSuggestionsViewController;
} }
...@@ -46,25 +39,27 @@ ...@@ -46,25 +39,27 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
UIView* discoverFeedView = self.discoverFeedViewController.view; DCHECK(self.discoverFeedWrapperViewController);
UIView* discoverFeedView = self.discoverFeedWrapperViewController.view;
[self.discoverFeedViewController willMoveToParentViewController:self]; [self.discoverFeedWrapperViewController willMoveToParentViewController:self];
[self addChildViewController:self.discoverFeedViewController]; [self addChildViewController:self.discoverFeedWrapperViewController];
[self.view addSubview:discoverFeedView]; [self.view addSubview:discoverFeedView];
[self.discoverFeedViewController didMoveToParentViewController:self]; [self.discoverFeedWrapperViewController didMoveToParentViewController:self];
discoverFeedView.translatesAutoresizingMaskIntoConstraints = NO; discoverFeedView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(discoverFeedView, self.view); AddSameConstraints(discoverFeedView, self.view);
[self.contentSuggestionsViewController [self.contentSuggestionsViewController
willMoveToParentViewController:self.discoverFeedViewController willMoveToParentViewController:self.discoverFeedWrapperViewController
.discoverFeed]; .discoverFeed];
[self.discoverFeedViewController.discoverFeed [self.discoverFeedWrapperViewController.discoverFeed
addChildViewController:self.contentSuggestionsViewController]; addChildViewController:self.contentSuggestionsViewController];
[self.discoverFeedViewController.feedCollectionView [self.discoverFeedWrapperViewController.feedCollectionView
addSubview:self.contentSuggestionsViewController.view]; addSubview:self.contentSuggestionsViewController.view];
[self.contentSuggestionsViewController [self.contentSuggestionsViewController
didMoveToParentViewController:self.discoverFeedViewController didMoveToParentViewController:self.discoverFeedWrapperViewController
.discoverFeed]; .discoverFeed];
} }
...@@ -78,7 +73,7 @@ ...@@ -78,7 +73,7 @@
self.contentSuggestionsViewController.view.frame = self.contentSuggestionsViewController.view.frame =
CGRectMake(0, -collectionView.contentSize.height, CGRectMake(0, -collectionView.contentSize.height,
self.view.frame.size.width, collectionView.contentSize.height); self.view.frame.size.width, collectionView.contentSize.height);
self.discoverFeedViewController.feedCollectionView.contentInset = self.discoverFeedWrapperViewController.feedCollectionView.contentInset =
UIEdgeInsetsMake(collectionView.contentSize.height, 0, 0, 0); UIEdgeInsetsMake(collectionView.contentSize.height, 0, 0, 0);
} }
......
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