Commit ecb8fb27 authored by sczs's avatar sczs Committed by Chromium LUCI CQ

[ios] Adds Discover Feed on/off support for refactored NTP.

- If the Discover Feed is OFF then the non refactored version (which
uses ContentSuggestionsVC as the main NTP VC) will be used, for this
container VC is created on NTPCoordinator which is returned to BVC.
The contained VC will change (between NTPVC and ContentSuggestionsVC)
depending on the Feed being ON or OFF.
- Adds an extra check on most IsRefactoredNTP calls, so the refactored
NTP is only used when the Discover Feed is on.
- Moves the NTPHomeMediator creation to NTPCoordinator.

Bug: 1114792
Change-Id: I64b82462825da7bd66f1004e89f55c64313f1dbb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625508
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarAdam Trudeau-Arcaro <adamta@google.com>
Cr-Commit-Position: refs/heads/master@{#843197}
parent 1ff4677b
...@@ -12,7 +12,9 @@ class WebState; ...@@ -12,7 +12,9 @@ class WebState;
} }
@class ContentSuggestionsHeaderViewController; @class ContentSuggestionsHeaderViewController;
@protocol NewTabPageCommands;
@protocol NewTabPageControllerDelegate; @protocol NewTabPageControllerDelegate;
@class NTPHomeMediator;
@class ViewRevealingVerticalPanHandler; @class ViewRevealingVerticalPanHandler;
// Coordinator to manage the Suggestions UI via a // Coordinator to manage the Suggestions UI via a
...@@ -36,6 +38,15 @@ class WebState; ...@@ -36,6 +38,15 @@ class WebState;
// The pan gesture handler for the view controller. // The pan gesture handler for the view controller.
@property(nonatomic, weak) ViewRevealingVerticalPanHandler* panGestureHandler; @property(nonatomic, weak) ViewRevealingVerticalPanHandler* panGestureHandler;
// NTP Mediator used by this Coordinator.
// TODO(crbug.com/1114792): Move all usage of this mediator to NTPCoordinator.
// It might also be necessary to split it and create a ContentSuggestions
// mediator for non NTP logic.
@property(nonatomic, strong) NTPHomeMediator* ntpMediator;
// Command handler for NTP related commands.
@property(nonatomic, weak) id<NewTabPageCommands> ntpCommandHandler;
// Dismisses all modals owned by the NTP mediator. // Dismisses all modals owned by the NTP mediator.
- (void)dismissModals; - (void)dismissModals;
...@@ -61,6 +72,9 @@ class WebState; ...@@ -61,6 +72,9 @@ class WebState;
// Constrains the named layout guide for the Discover header menu button. // Constrains the named layout guide for the Discover header menu button.
- (void)constrainDiscoverHeaderMenuButtonNamedGuide; - (void)constrainDiscoverHeaderMenuButtonNamedGuide;
// YES if the Discover feed is currently visible.
- (BOOL)isDiscoverFeedVisible;
@end @end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_COORDINATOR_H_ #endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_COORDINATOR_H_
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#import "ios/chrome/browser/search_engines/template_url_service_factory.h" #import "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service.h" #import "ios/chrome/browser/signin/authentication_service.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h" #import "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/browser/ui/activity_services/activity_params.h" #import "ios/chrome/browser/ui/activity_services/activity_params.h"
#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
...@@ -65,6 +64,7 @@ ...@@ -65,6 +64,7 @@
#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/menu/action_factory.h" #import "ios/chrome/browser/ui/menu/action_factory.h"
#import "ios/chrome/browser/ui/menu/menu_histograms.h" #import "ios/chrome/browser/ui/menu/menu_histograms.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_commands.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_header_constants.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h"
#import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h" #import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h"
...@@ -76,7 +76,6 @@ ...@@ -76,7 +76,6 @@
#import "ios/chrome/browser/ui/util/uikit_ui_util.h" #import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/browser/url_loading/url_loading_browser_agent.h" #import "ios/chrome/browser/url_loading/url_loading_browser_agent.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h" #import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/voice/voice_search_availability.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h" #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/discover_feed/discover_feed_provider.h" #import "ios/public/provider/chrome/browser/discover_feed/discover_feed_provider.h"
...@@ -98,8 +97,6 @@ ...@@ -98,8 +97,6 @@
OverscrollActionsControllerDelegate, OverscrollActionsControllerDelegate,
ThemeChangeDelegate, ThemeChangeDelegate,
URLDropDelegate> { URLDropDelegate> {
// Helper object managing the availability of the voice search feature.
VoiceSearchAvailability _voiceSearchAvailability;
} }
@property(nonatomic, strong) @property(nonatomic, strong)
...@@ -111,7 +108,6 @@ ...@@ -111,7 +108,6 @@
@property(nonatomic, strong) ContentSuggestionsMetricsRecorder* metricsRecorder; @property(nonatomic, strong) ContentSuggestionsMetricsRecorder* metricsRecorder;
@property(nonatomic, strong) @property(nonatomic, strong)
DiscoverFeedMetricsRecorder* discoverFeedMetricsRecorder; DiscoverFeedMetricsRecorder* discoverFeedMetricsRecorder;
@property(nonatomic, strong) NTPHomeMediator* NTPMediator;
@property(nonatomic, strong) UIViewController* discoverFeedViewController; @property(nonatomic, strong) UIViewController* discoverFeedViewController;
@property(nonatomic, strong) UIView* discoverFeedHeaderMenuButton; @property(nonatomic, strong) UIView* discoverFeedHeaderMenuButton;
@property(nonatomic, strong) URLDragDropHandler* dragDropHandler; @property(nonatomic, strong) URLDragDropHandler* dragDropHandler;
...@@ -119,7 +115,8 @@ ...@@ -119,7 +115,8 @@
// Redefined as readwrite. // Redefined as readwrite.
@property(nonatomic, strong, readwrite) @property(nonatomic, strong, readwrite)
ContentSuggestionsHeaderViewController* headerController; ContentSuggestionsHeaderViewController* headerController;
@property(nonatomic, strong) PrefBackedBoolean* contentSuggestionsVisible; @property(nonatomic, strong) PrefBackedBoolean* contentSuggestionsExpanded;
@property(nonatomic, assign) BOOL contentSuggestionsEnabled;
// Delegate for handling Discover feed header UI changes. // Delegate for handling Discover feed header UI changes.
@property(nonatomic, weak) id<DiscoverFeedHeaderChanging> @property(nonatomic, weak) id<DiscoverFeedHeaderChanging>
discoverFeedHeaderDelegate; discoverFeedHeaderDelegate;
...@@ -139,6 +136,7 @@ ...@@ -139,6 +136,7 @@
- (void)start { - (void)start {
DCHECK(self.browser); DCHECK(self.browser);
DCHECK(self.ntpMediator);
if (self.visible) { if (self.visible) {
// Prevent this coordinator from being started twice in a row // Prevent this coordinator from being started twice in a row
return; return;
...@@ -167,13 +165,14 @@ ...@@ -167,13 +165,14 @@
PrefService* prefs = PrefService* prefs =
ChromeBrowserState::FromBrowserState(self.browser->GetBrowserState()) ChromeBrowserState::FromBrowserState(self.browser->GetBrowserState())
->GetPrefs(); ->GetPrefs();
bool contentSuggestionsEnabled =
self.contentSuggestionsEnabled =
prefs->GetBoolean(prefs::kArticlesForYouEnabled); prefs->GetBoolean(prefs::kArticlesForYouEnabled);
self.contentSuggestionsVisible = [[PrefBackedBoolean alloc] self.contentSuggestionsExpanded = [[PrefBackedBoolean alloc]
initWithPrefService:prefs initWithPrefService:prefs
prefName:feed::prefs::kArticlesListVisible]; prefName:feed::prefs::kArticlesListVisible];
if (contentSuggestionsEnabled) { if (self.contentSuggestionsEnabled) {
if ([self.contentSuggestionsVisible value]) { if ([self.contentSuggestionsExpanded value]) {
ntp_home::RecordNTPImpression(ntp_home::REMOTE_SUGGESTIONS); ntp_home::RecordNTPImpression(ntp_home::REMOTE_SUGGESTIONS);
} else { } else {
ntp_home::RecordNTPImpression(ntp_home::REMOTE_COLLAPSED); ntp_home::RecordNTPImpression(ntp_home::REMOTE_COLLAPSED);
...@@ -182,30 +181,14 @@ ...@@ -182,30 +181,14 @@
ntp_home::RecordNTPImpression(ntp_home::LOCAL_SUGGESTIONS); ntp_home::RecordNTPImpression(ntp_home::LOCAL_SUGGESTIONS);
} }
TemplateURLService* templateURLService =
ios::TemplateURLServiceFactory::GetForBrowserState(
self.browser->GetBrowserState());
self.NTPMediator = [[NTPHomeMediator alloc]
initWithWebState:self.webState
templateURLService:templateURLService
URLLoader:UrlLoadingBrowserAgent::FromBrowser(self.browser)
authService:self.authService
identityManager:IdentityManagerFactory::GetForBrowserState(
self.browser->GetBrowserState())
logoVendor:ios::GetChromeBrowserProvider()->CreateLogoVendor(
self.browser, self.webState)
voiceSearchAvailability:&_voiceSearchAvailability];
self.NTPMediator.browser = self.browser;
self.headerController = [[ContentSuggestionsHeaderViewController alloc] init]; self.headerController = [[ContentSuggestionsHeaderViewController alloc] init];
// TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol // TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
// clean up. // clean up.
self.headerController.dispatcher = self.headerController.dispatcher =
static_cast<id<ApplicationCommands, BrowserCommands, OmniboxCommands, static_cast<id<ApplicationCommands, BrowserCommands, OmniboxCommands,
FakeboxFocuser>>(self.browser->GetCommandDispatcher()); FakeboxFocuser>>(self.browser->GetCommandDispatcher());
self.headerController.commandHandler = self.NTPMediator; self.headerController.commandHandler = self.ntpMediator;
self.headerController.delegate = self.NTPMediator; self.headerController.delegate = self.ntpMediator;
self.headerController.readingListModel = self.headerController.readingListModel =
ReadingListModelFactory::GetForBrowserState( ReadingListModelFactory::GetForBrowserState(
...@@ -234,6 +217,9 @@ ...@@ -234,6 +217,9 @@
} }
self.discoverFeedViewController = [self discoverFeed]; self.discoverFeedViewController = [self discoverFeed];
TemplateURLService* templateURLService =
ios::TemplateURLServiceFactory::GetForBrowserState(
self.browser->GetBrowserState());
const TemplateURL* defaultURL = const TemplateURL* defaultURL =
templateURLService->GetDefaultSearchProvider(); templateURLService->GetDefaultSearchProvider();
BOOL isGoogleDefaultSearchProvider = BOOL isGoogleDefaultSearchProvider =
...@@ -250,10 +236,10 @@ ...@@ -250,10 +236,10 @@
prefService:prefs prefService:prefs
discoverFeed:self.discoverFeedViewController discoverFeed:self.discoverFeedViewController
isGoogleDefaultSearchProvider:isGoogleDefaultSearchProvider]; isGoogleDefaultSearchProvider:isGoogleDefaultSearchProvider];
self.contentSuggestionsMediator.commandHandler = self.NTPMediator; self.contentSuggestionsMediator.commandHandler = self.ntpMediator;
self.contentSuggestionsMediator.headerProvider = self.headerController; self.contentSuggestionsMediator.headerProvider = self.headerController;
self.contentSuggestionsMediator.contentArticlesExpanded = self.contentSuggestionsMediator.contentArticlesExpanded =
self.contentSuggestionsVisible; self.contentSuggestionsExpanded;
self.contentSuggestionsMediator.discoverFeedDelegate = self; self.contentSuggestionsMediator.discoverFeedDelegate = self;
self.headerController.promoCanShow = self.headerController.promoCanShow =
...@@ -265,7 +251,7 @@ ...@@ -265,7 +251,7 @@
// Offset to maintain Discover feed scroll position. // Offset to maintain Discover feed scroll position.
CGFloat offset = 0; CGFloat offset = 0;
if (IsDiscoverFeedEnabled() && contentSuggestionsEnabled) { if (IsDiscoverFeedEnabled() && self.contentSuggestionsEnabled) {
web::NavigationManager* navigationManager = web::NavigationManager* navigationManager =
self.webState->GetNavigationManager(); self.webState->GetNavigationManager();
web::NavigationItem* item = navigationManager->GetVisibleItem(); web::NavigationItem* item = navigationManager->GetVisibleItem();
...@@ -276,10 +262,11 @@ ...@@ -276,10 +262,11 @@
self.suggestionsViewController = [[ContentSuggestionsViewController alloc] self.suggestionsViewController = [[ContentSuggestionsViewController alloc]
initWithStyle:CollectionViewControllerStyleDefault initWithStyle:CollectionViewControllerStyleDefault
offset:offset]; offset:offset
feedVisible:[self isDiscoverFeedVisible]];
[self.suggestionsViewController [self.suggestionsViewController
setDataSource:self.contentSuggestionsMediator]; setDataSource:self.contentSuggestionsMediator];
self.suggestionsViewController.suggestionCommandHandler = self.NTPMediator; self.suggestionsViewController.suggestionCommandHandler = self.ntpMediator;
self.suggestionsViewController.audience = self; self.suggestionsViewController.audience = self;
self.suggestionsViewController.overscrollDelegate = self; self.suggestionsViewController.overscrollDelegate = self;
self.suggestionsViewController.themeChangeDelegate = self; self.suggestionsViewController.themeChangeDelegate = self;
...@@ -295,10 +282,10 @@ ...@@ -295,10 +282,10 @@
self.discoverFeedHeaderDelegate = self.discoverFeedHeaderDelegate =
self.suggestionsViewController.discoverFeedHeaderDelegate; self.suggestionsViewController.discoverFeedHeaderDelegate;
[self.discoverFeedHeaderDelegate [self.discoverFeedHeaderDelegate
changeDiscoverFeedHeaderVisibility:[self.contentSuggestionsVisible changeDiscoverFeedHeaderVisibility:[self.contentSuggestionsExpanded
value]]; value]];
self.suggestionsViewController.contentSuggestionsEnabled = self.suggestionsViewController.contentSuggestionsEnabled =
contentSuggestionsEnabled; self.contentSuggestionsEnabled;
self.suggestionsViewController.handler = self; self.suggestionsViewController.handler = self;
self.contentSuggestionsMediator.consumer = self.suggestionsViewController; self.contentSuggestionsMediator.consumer = self.suggestionsViewController;
...@@ -306,21 +293,21 @@ ...@@ -306,21 +293,21 @@
self.suggestionsViewController.menuProvider = self; self.suggestionsViewController.menuProvider = self;
} }
self.NTPMediator.consumer = self.headerController; self.ntpMediator.consumer = self.headerController;
// TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol // TODO(crbug.com/1045047): Use HandlerForProtocol after commands protocol
// clean up. // clean up.
self.NTPMediator.dispatcher = self.ntpMediator.dispatcher =
static_cast<id<ApplicationCommands, BrowserCommands, OmniboxCommands, static_cast<id<ApplicationCommands, BrowserCommands, OmniboxCommands,
SnackbarCommands>>(self.browser->GetCommandDispatcher()); SnackbarCommands>>(self.browser->GetCommandDispatcher());
self.NTPMediator.NTPMetrics = [[NTPHomeMetrics alloc] self.ntpMediator.NTPMetrics = [[NTPHomeMetrics alloc]
initWithBrowserState:self.browser->GetBrowserState() initWithBrowserState:self.browser->GetBrowserState()
webState:self.webState]; webState:self.webState];
self.NTPMediator.metricsRecorder = self.metricsRecorder; self.ntpMediator.metricsRecorder = self.metricsRecorder;
self.NTPMediator.suggestionsViewController = self.suggestionsViewController; self.ntpMediator.suggestionsViewController = self.suggestionsViewController;
self.NTPMediator.suggestionsMediator = self.contentSuggestionsMediator; self.ntpMediator.suggestionsMediator = self.contentSuggestionsMediator;
self.NTPMediator.suggestionsService = contentSuggestionsService; self.ntpMediator.suggestionsService = contentSuggestionsService;
[self.NTPMediator setUp]; [self.ntpMediator setUp];
self.NTPMediator.discoverFeedMetrics = self.discoverFeedMetricsRecorder; self.ntpMediator.discoverFeedMetrics = self.discoverFeedMetricsRecorder;
[self.suggestionsViewController addChildViewController:self.headerController]; [self.suggestionsViewController addChildViewController:self.headerController];
[self.headerController [self.headerController
...@@ -330,12 +317,12 @@ ...@@ -330,12 +317,12 @@
// synchronizer instead. // synchronizer instead.
self.suggestionsViewController.headerProvider = self.headerController; self.suggestionsViewController.headerProvider = self.headerController;
if (!IsRefactoredNTP()) { if (!IsRefactoredNTP() || ![self isDiscoverFeedVisible]) {
self.headerCollectionInteractionHandler = self.headerCollectionInteractionHandler =
[[ContentSuggestionsHeaderSynchronizer alloc] [[ContentSuggestionsHeaderSynchronizer alloc]
initWithCollectionController:self.suggestionsViewController initWithCollectionController:self.suggestionsViewController
headerController:self.headerController]; headerController:self.headerController];
self.NTPMediator.headerCollectionInteractionHandler = self.ntpMediator.headerCollectionInteractionHandler =
self.headerCollectionInteractionHandler; self.headerCollectionInteractionHandler;
} }
...@@ -347,8 +334,8 @@ ...@@ -347,8 +334,8 @@
} }
- (void)stop { - (void)stop {
[self.NTPMediator shutdown]; [self.ntpMediator shutdown];
self.NTPMediator = nil; self.ntpMediator = nil;
[self.contentSuggestionsMediator disconnect]; [self.contentSuggestionsMediator disconnect];
self.contentSuggestionsMediator = nil; self.contentSuggestionsMediator = nil;
[self.sharingCoordinator stop]; [self.sharingCoordinator stop];
...@@ -359,7 +346,7 @@ ...@@ -359,7 +346,7 @@
->GetDiscoverFeedProvider() ->GetDiscoverFeedProvider()
->RemoveFeedViewController(self.discoverFeedViewController); ->RemoveFeedViewController(self.discoverFeedViewController);
} }
self.contentSuggestionsVisible = nil; self.contentSuggestionsExpanded = nil;
_visible = NO; _visible = NO;
} }
...@@ -490,12 +477,15 @@ ...@@ -490,12 +477,15 @@
view:self.discoverFeedHeaderMenuButton.superview]; view:self.discoverFeedHeaderMenuButton.superview];
__weak ContentSuggestionsCoordinator* weakSelf = self; __weak ContentSuggestionsCoordinator* weakSelf = self;
if ([self.contentSuggestionsVisible value]) { if ([self.contentSuggestionsExpanded value]) {
[self.alertCoordinator [self.alertCoordinator
addItemWithTitle:l10n_util::GetNSString( addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_DISCOVER_FEED_MENU_TURN_OFF_ITEM) IDS_IOS_DISCOVER_FEED_MENU_TURN_OFF_ITEM)
action:^{ action:^{
[weakSelf setDiscoverFeedVisible:NO]; [weakSelf setDiscoverFeedVisible:NO];
if (IsRefactoredNTP()) {
[weakSelf.ntpCommandHandler setDiscoverFeedVisible:NO];
}
} }
style:UIAlertActionStyleDestructive]; style:UIAlertActionStyleDestructive];
} else { } else {
...@@ -504,6 +494,9 @@ ...@@ -504,6 +494,9 @@
IDS_IOS_DISCOVER_FEED_MENU_TURN_ON_ITEM) IDS_IOS_DISCOVER_FEED_MENU_TURN_ON_ITEM)
action:^{ action:^{
[weakSelf setDiscoverFeedVisible:YES]; [weakSelf setDiscoverFeedVisible:YES];
if (IsRefactoredNTP()) {
[weakSelf.ntpCommandHandler setDiscoverFeedVisible:YES];
}
} }
style:UIAlertActionStyleDefault]; style:UIAlertActionStyleDefault];
} }
...@@ -513,7 +506,7 @@ ...@@ -513,7 +506,7 @@
addItemWithTitle:l10n_util::GetNSString( addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_DISCOVER_FEED_MENU_MANAGE_ACTIVITY_ITEM) IDS_IOS_DISCOVER_FEED_MENU_MANAGE_ACTIVITY_ITEM)
action:^{ action:^{
[weakSelf.NTPMediator handleFeedManageActivityTapped]; [weakSelf.ntpMediator handleFeedManageActivityTapped];
} }
style:UIAlertActionStyleDefault]; style:UIAlertActionStyleDefault];
...@@ -521,7 +514,7 @@ ...@@ -521,7 +514,7 @@
addItemWithTitle:l10n_util::GetNSString( addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_DISCOVER_FEED_MENU_MANAGE_INTERESTS_ITEM) IDS_IOS_DISCOVER_FEED_MENU_MANAGE_INTERESTS_ITEM)
action:^{ action:^{
[weakSelf.NTPMediator handleFeedManageInterestsTapped]; [weakSelf.ntpMediator handleFeedManageInterestsTapped];
} }
style:UIAlertActionStyleDefault]; style:UIAlertActionStyleDefault];
} }
...@@ -530,7 +523,7 @@ ...@@ -530,7 +523,7 @@
addItemWithTitle:l10n_util::GetNSString( addItemWithTitle:l10n_util::GetNSString(
IDS_IOS_DISCOVER_FEED_MENU_LEARN_MORE_ITEM) IDS_IOS_DISCOVER_FEED_MENU_LEARN_MORE_ITEM)
action:^{ action:^{
[weakSelf.NTPMediator handleFeedLearnMoreTapped]; [weakSelf.ntpMediator handleFeedLearnMoreTapped];
} }
style:UIAlertActionStyleDefault]; style:UIAlertActionStyleDefault];
[self.alertCoordinator start]; [self.alertCoordinator start];
...@@ -576,7 +569,7 @@ ...@@ -576,7 +569,7 @@
} }
- (void)dismissModals { - (void)dismissModals {
[self.NTPMediator dismissModals]; [self.ntpMediator dismissModals];
} }
- (UIEdgeInsets)contentInset { - (UIEdgeInsets)contentInset {
...@@ -592,23 +585,28 @@ ...@@ -592,23 +585,28 @@
} }
- (void)willUpdateSnapshot { - (void)willUpdateSnapshot {
DCHECK(!IsRefactoredNTP());
[self.suggestionsViewController clearOverscroll]; [self.suggestionsViewController clearOverscroll];
} }
- (void)reload { - (void)reload {
if (IsDiscoverFeedEnabled() && !IsRefactoredNTP()) { if (IsDiscoverFeedEnabled() && !IsRefactoredNTP() &&
DCHECK(!IsRefactoredNTP()); [self isDiscoverFeedVisible]) {
ios::GetChromeBrowserProvider()->GetDiscoverFeedProvider()->RefreshFeed(); ios::GetChromeBrowserProvider()->GetDiscoverFeedProvider()->RefreshFeed();
} }
[self.contentSuggestionsMediator.dataSink reloadAllData]; [self.contentSuggestionsMediator.dataSink reloadAllData];
} }
- (void)locationBarDidBecomeFirstResponder { - (void)locationBarDidBecomeFirstResponder {
[self.NTPMediator locationBarDidBecomeFirstResponder]; [self.ntpMediator locationBarDidBecomeFirstResponder];
} }
- (void)locationBarDidResignFirstResponder { - (void)locationBarDidResignFirstResponder {
[self.NTPMediator locationBarDidResignFirstResponder]; [self.ntpMediator locationBarDidResignFirstResponder];
}
- (BOOL)isDiscoverFeedVisible {
return self.contentSuggestionsEnabled &&
[self.contentSuggestionsExpanded value];
} }
#pragma mark - ContentSuggestionsMenuProvider #pragma mark - ContentSuggestionsMenuProvider
...@@ -643,7 +641,7 @@ ...@@ -643,7 +641,7 @@
indexPathForItem:item]; indexPathForItem:item];
[menuElements addObject:[actionFactory actionToOpenInNewTabWithBlock:^{ [menuElements addObject:[actionFactory actionToOpenInNewTabWithBlock:^{
[weakSelf.NTPMediator [weakSelf.ntpMediator
openNewTabWithMostVisitedItem:item openNewTabWithMostVisitedItem:item
incognito:NO incognito:NO
atIndex:indexPath.item]; atIndex:indexPath.item];
...@@ -651,7 +649,7 @@ ...@@ -651,7 +649,7 @@
[menuElements [menuElements
addObject:[actionFactory actionToOpenInNewIncognitoTabWithBlock:^{ addObject:[actionFactory actionToOpenInNewIncognitoTabWithBlock:^{
[weakSelf.NTPMediator [weakSelf.ntpMediator
openNewTabWithMostVisitedItem:item openNewTabWithMostVisitedItem:item
incognito:YES incognito:YES
atIndex:indexPath.item]; atIndex:indexPath.item];
...@@ -674,7 +672,7 @@ ...@@ -674,7 +672,7 @@
}]]; }]];
[menuElements addObject:[actionFactory actionToRemoveWithBlock:^{ [menuElements addObject:[actionFactory actionToRemoveWithBlock:^{
[weakSelf.NTPMediator removeMostVisited:item]; [weakSelf.ntpMediator removeMostVisited:item];
}]]; }]];
return [UIMenu menuWithTitle:@"" children:menuElements]; return [UIMenu menuWithTitle:@"" children:menuElements];
...@@ -727,7 +725,7 @@ ...@@ -727,7 +725,7 @@
// Toggles Discover feed visibility between hidden or expanded. // Toggles Discover feed visibility between hidden or expanded.
- (void)setDiscoverFeedVisible:(BOOL)visible { - (void)setDiscoverFeedVisible:(BOOL)visible {
[self.contentSuggestionsVisible setValue:visible]; [self.contentSuggestionsExpanded setValue:visible];
[self.discoverFeedHeaderDelegate changeDiscoverFeedHeaderVisibility:visible]; [self.discoverFeedHeaderDelegate changeDiscoverFeedHeaderVisibility:visible];
[self.contentSuggestionsMediator reloadAllData]; [self.contentSuggestionsMediator reloadAllData];
[self.discoverFeedMetricsRecorder [self.discoverFeedMetricsRecorder
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
// Creates layout with |offset| as additional height. Allows the view's height // Creates layout with |offset| as additional height. Allows the view's height
// to be increased enough to maintain the scroll position. Only needed if // to be increased enough to maintain the scroll position. Only needed if
// Discover feed is enabled. // Discover feed is visible.
- (instancetype)initWithOffset:(CGFloat)offset; - (instancetype)initWithOffset:(CGFloat)offset feedVisible:(BOOL)visible;
@end @end
......
...@@ -15,22 +15,29 @@ ...@@ -15,22 +15,29 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface ContentSuggestionsLayout ()
// YES if the Discover Feed is currently visible.
@property(nonatomic, assign, getter=isFeedVisible) BOOL feedVisible;
@end
@implementation ContentSuggestionsLayout @implementation ContentSuggestionsLayout
- (instancetype)initWithOffset:(CGFloat)offset { - (instancetype)initWithOffset:(CGFloat)offset feedVisible:(BOOL)visible {
if (self = [super init]) { if (self = [super init]) {
_feedVisible = visible;
_offset = offset; _offset = offset;
} }
return self; return self;
} }
- (CGSize)collectionViewContentSize { - (CGSize)collectionViewContentSize {
if (IsRefactoredNTP()) { if (IsRefactoredNTP() && [self isFeedVisible]) {
// In the refactored NTP, we don't want to extend the view height beyond its // In the refactored NTP and when the Feed is visible, we don't want to
// content. // extend the view height beyond its content.
return [super collectionViewContentSize]; return [super collectionViewContentSize];
} }
DCHECK(!IsRefactoredNTP());
CGFloat collectionViewHeight = self.collectionView.bounds.size.height; CGFloat collectionViewHeight = self.collectionView.bounds.size.height;
CGFloat headerHeight = [self firstHeaderHeight]; CGFloat headerHeight = [self firstHeaderHeight];
...@@ -116,7 +123,7 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind ...@@ -116,7 +123,7 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
if ([kind isEqualToString:UICollectionElementKindSectionHeader] && if ([kind isEqualToString:UICollectionElementKindSectionHeader] &&
indexPath.section == 0) { indexPath.section == 0) {
CGFloat contentOffset; CGFloat contentOffset;
if (IsRefactoredNTP()) { if (IsRefactoredNTP() && [self isFeedVisible]) {
contentOffset = self.parentCollectionView.contentOffset.y + contentOffset = self.parentCollectionView.contentOffset.y +
self.collectionView.contentSize.height; self.collectionView.contentSize.height;
} else { } else {
...@@ -136,8 +143,11 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind ...@@ -136,8 +143,11 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
ToolbarExpandedHeight( ToolbarExpandedHeight(
[UIApplication sharedApplication].preferredContentSizeCategory) - [UIApplication sharedApplication].preferredContentSizeCategory) -
topSafeArea; topSafeArea;
if (contentOffset > minY && // TODO(crbug.com/1114792): Remove mentioned of "refactored" from the
(!IsRefactoredNTP() || !self.isScrolledIntoFeed)) { // variable name once this launches.
BOOL hasScrolledIntoRefactoredDiscoverFeed =
[self isFeedVisible] && self.isScrolledIntoFeed && IsRefactoredNTP();
if (contentOffset > minY && !hasScrolledIntoRefactoredDiscoverFeed) {
origin.y = contentOffset - minY; origin.y = contentOffset - minY;
} }
attributes.frame = {origin, attributes.frame.size}; attributes.frame = {origin, attributes.frame.size};
......
...@@ -38,9 +38,10 @@ extern NSString* const ...@@ -38,9 +38,10 @@ extern NSString* const
ContentSuggestionsConsumer> ContentSuggestionsConsumer>
// Inits view controller with |offset| to maintain scroll position if needed. // Inits view controller with |offset| to maintain scroll position if needed.
// Offset is only required if Discover feed is enabled. // Offset is only required if Discover feed is visible.
- (instancetype)initWithStyle:(CollectionViewControllerStyle)style - (instancetype)initWithStyle:(CollectionViewControllerStyle)style
offset:(CGFloat)offset NS_DESIGNATED_INITIALIZER; offset:(CGFloat)offset
feedVisible:(BOOL)visible NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithLayout:(UICollectionViewLayout*)layout - (instancetype)initWithLayout:(UICollectionViewLayout*)layout
style:(CollectionViewControllerStyle)style style:(CollectionViewControllerStyle)style
......
...@@ -116,9 +116,11 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix = ...@@ -116,9 +116,11 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
#pragma mark - Lifecycle #pragma mark - Lifecycle
- (instancetype)initWithStyle:(CollectionViewControllerStyle)style - (instancetype)initWithStyle:(CollectionViewControllerStyle)style
offset:(CGFloat)offset { offset:(CGFloat)offset
feedVisible:(BOOL)visible {
_offset = offset; _offset = offset;
_layout = [[ContentSuggestionsLayout alloc] initWithOffset:offset]; _layout = [[ContentSuggestionsLayout alloc] initWithOffset:offset
feedVisible:visible];
self = [super initWithLayout:_layout style:style]; self = [super initWithLayout:_layout style:style];
if (self) { if (self) {
_collectionUpdater = [[ContentSuggestionsCollectionUpdater alloc] init]; _collectionUpdater = [[ContentSuggestionsCollectionUpdater alloc] init];
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
source_set("ntp") { source_set("ntp") {
sources = [ sources = [
"new_tab_page_commands.h",
"new_tab_page_content_delegate.h", "new_tab_page_content_delegate.h",
"new_tab_page_controller_delegate.h", "new_tab_page_controller_delegate.h",
"new_tab_page_header_constants.h", "new_tab_page_header_constants.h",
...@@ -26,6 +27,8 @@ source_set("coordinator") { ...@@ -26,6 +27,8 @@ source_set("coordinator") {
":ntp_internal", ":ntp_internal",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main:public", "//ios/chrome/browser/main:public",
"//ios/chrome/browser/search_engines",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/content_suggestions", "//ios/chrome/browser/ui/content_suggestions",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui", "//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui",
...@@ -34,7 +37,9 @@ source_set("coordinator") { ...@@ -34,7 +37,9 @@ source_set("coordinator") {
"//ios/chrome/browser/ui/main:scene_state_observer", "//ios/chrome/browser/ui/main:scene_state_observer",
"//ios/chrome/browser/ui/overscroll_actions", "//ios/chrome/browser/ui/overscroll_actions",
"//ios/chrome/browser/url_loading", "//ios/chrome/browser/url_loading",
"//ios/chrome/browser/voice",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
"//ios/chrome/common/ui/util",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/discover_feed", "//ios/public/provider/chrome/browser/discover_feed",
"//ios/public/provider/chrome/browser/voice", "//ios/public/provider/chrome/browser/voice",
......
// Copyright 2021 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_NTP_NEW_TAB_PAGE_COMMANDS_H_
#define IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_COMMANDS_H_
// Commands to communicate back to the NewTabPageCoordinator
@protocol NewTabPageCommands
// Called when the Discover Feed changes it visibility.
- (void)setDiscoverFeedVisible:(BOOL)visible;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_COMMANDS_H_
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/main/browser.h" #import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h" #import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
...@@ -17,16 +20,20 @@ ...@@ -17,16 +20,20 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_coordinator.h" #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_coordinator.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_header_synchronizer.h" #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_header_synchronizer.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_header_view_controller.h" #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_header_view_controller.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_mediator.h"
#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_wrapper_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_commands.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_content_delegate.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_content_delegate.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"
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h" #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
#import "ios/chrome/browser/url_loading/url_loading_browser_agent.h" #import "ios/chrome/browser/url_loading/url_loading_browser_agent.h"
#import "ios/chrome/browser/voice/voice_search_availability.h"
#import "ios/chrome/common/ui/util/constraints_ui_util.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h" #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/discover_feed/discover_feed_provider.h" #import "ios/public/provider/chrome/browser/discover_feed/discover_feed_provider.h"
#import "ios/web/public/navigation/navigation_context.h" #import "ios/web/public/navigation/navigation_context.h"
...@@ -38,9 +45,13 @@ ...@@ -38,9 +45,13 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface NewTabPageCoordinator () <NewTabPageContentDelegate, @interface NewTabPageCoordinator () <NewTabPageCommands,
NewTabPageContentDelegate,
OverscrollActionsControllerDelegate, OverscrollActionsControllerDelegate,
SceneStateObserver> SceneStateObserver> {
// Helper object managing the availability of the voice search feature.
VoiceSearchAvailability _voiceSearchAvailability;
}
// Coordinator for the ContentSuggestions. // Coordinator for the ContentSuggestions.
@property(nonatomic, strong) @property(nonatomic, strong)
...@@ -49,6 +60,12 @@ ...@@ -49,6 +60,12 @@
// View controller for the regular NTP. // View controller for the regular NTP.
@property(nonatomic, strong) NewTabPageViewController* ntpViewController; @property(nonatomic, strong) NewTabPageViewController* ntpViewController;
// Mediator owned by this Coordinator.
@property(nonatomic, strong) NTPHomeMediator* NTPMediator;
// Authentication Service for the user's signed-in state.
@property(nonatomic, assign) AuthenticationService* authService;
// View controller wrapping the Discover feed. // View controller wrapping the Discover feed.
@property(nonatomic, strong) @property(nonatomic, strong)
DiscoverFeedWrapperViewController* discoverFeedWrapperViewController; DiscoverFeedWrapperViewController* discoverFeedWrapperViewController;
...@@ -75,6 +92,18 @@ ...@@ -75,6 +92,18 @@
@property(nonatomic, strong) @property(nonatomic, strong)
ContentSuggestionsHeaderSynchronizer* headerSynchronizer; ContentSuggestionsHeaderSynchronizer* headerSynchronizer;
// The ViewController displayed by this Coordinator. This is the returned
// ViewController and will contain the |containedViewController| (Which can
// change depending on Feed visibility).
@property(nonatomic, strong) UIViewController* containerViewController;
// The coordinator contained ViewController. It can be either a
// NewTabPageViewController (When the Discover Feed is being shown) or a
// ContentSuggestionsViewController (When the Discover Feed is hidden or when
// the non refactored NTP is being used.)
// TODO(crbug.com/1114792): Update this comment when the NTP refactors launches.
@property(nonatomic, strong) UIViewController* containedViewController;
@end @end
@implementation NewTabPageCoordinator @implementation NewTabPageCoordinator
...@@ -82,7 +111,11 @@ ...@@ -82,7 +111,11 @@
#pragma mark - ChromeCoordinator #pragma mark - ChromeCoordinator
- (instancetype)initWithBrowser:(Browser*)browser { - (instancetype)initWithBrowser:(Browser*)browser {
return [super initWithBaseViewController:nil browser:browser]; self = [super initWithBaseViewController:nil browser:browser];
if (self) {
self.containerViewController = [[UIViewController alloc] init];
}
return self;
} }
- (void)start { - (void)start {
...@@ -99,19 +132,43 @@ ...@@ -99,19 +132,43 @@
UrlLoadingBrowserAgent::FromBrowser(self.browser); UrlLoadingBrowserAgent::FromBrowser(self.browser);
self.incognitoViewController = self.incognitoViewController =
[[IncognitoViewController alloc] initWithUrlLoader:URLLoader]; [[IncognitoViewController alloc] initWithUrlLoader:URLLoader];
} else { self.started = YES;
return;
}
DCHECK(!self.contentSuggestionsCoordinator); DCHECK(!self.contentSuggestionsCoordinator);
self.authService = AuthenticationServiceFactory::GetForBrowserState(
self.browser->GetBrowserState());
TemplateURLService* templateURLService =
ios::TemplateURLServiceFactory::GetForBrowserState(
self.browser->GetBrowserState());
self.NTPMediator = [[NTPHomeMediator alloc]
initWithWebState:self.webState
templateURLService:templateURLService
URLLoader:UrlLoadingBrowserAgent::FromBrowser(self.browser)
authService:self.authService
identityManager:IdentityManagerFactory::GetForBrowserState(
self.browser->GetBrowserState())
logoVendor:ios::GetChromeBrowserProvider()->CreateLogoVendor(
self.browser, self.webState)
voiceSearchAvailability:&_voiceSearchAvailability];
self.NTPMediator.browser = self.browser;
self.contentSuggestionsCoordinator = [[ContentSuggestionsCoordinator alloc] self.contentSuggestionsCoordinator = [[ContentSuggestionsCoordinator alloc]
initWithBaseViewController:nil initWithBaseViewController:nil
browser:self.browser]; browser:self.browser];
self.contentSuggestionsCoordinator.webState = self.webState; self.contentSuggestionsCoordinator.webState = self.webState;
self.contentSuggestionsCoordinator.toolbarDelegate = self.toolbarDelegate; self.contentSuggestionsCoordinator.toolbarDelegate = self.toolbarDelegate;
self.contentSuggestionsCoordinator.panGestureHandler = self.contentSuggestionsCoordinator.panGestureHandler = self.panGestureHandler;
self.panGestureHandler; self.contentSuggestionsCoordinator.ntpMediator = self.NTPMediator;
self.contentSuggestionsCoordinator.ntpCommandHandler = self;
[self.contentSuggestionsCoordinator start]; [self.contentSuggestionsCoordinator start];
if (IsRefactoredNTP()) { if ([self isNTPRefactoredAndFeedVisible]) {
self.ntpViewController = [[NewTabPageViewController alloc] self.ntpViewController = [[NewTabPageViewController alloc]
initWithContentSuggestionsViewController: initWithContentSuggestionsViewController:
self.contentSuggestionsCoordinator.viewController]; self.contentSuggestionsCoordinator.viewController];
...@@ -146,7 +203,24 @@ ...@@ -146,7 +203,24 @@
[sceneState addObserver:self]; [sceneState addObserver:self];
self.sceneInForeground = self.sceneInForeground =
sceneState.activationLevel >= SceneActivationLevelForegroundInactive; sceneState.activationLevel >= SceneActivationLevelForegroundInactive;
}
UIViewController* containedViewController =
[self isNTPRefactoredAndFeedVisible]
? self.ntpViewController
: self.contentSuggestionsCoordinator.viewController;
[containedViewController
willMoveToParentViewController:self.containerViewController];
[self.containerViewController addChildViewController:containedViewController];
[self.containerViewController.view addSubview:containedViewController.view];
[containedViewController
didMoveToParentViewController:self.containerViewController];
containedViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(containedViewController.view,
self.containerViewController.view);
self.containedViewController = containedViewController;
self.started = YES; self.started = YES;
} }
...@@ -164,6 +238,11 @@ ...@@ -164,6 +238,11 @@
self.incognitoViewController = nil; self.incognitoViewController = nil;
self.ntpViewController = nil; self.ntpViewController = nil;
self.discoverFeedWrapperViewController = nil; self.discoverFeedWrapperViewController = nil;
[self.containedViewController willMoveToParentViewController:nil];
[self.containedViewController.view removeFromSuperview];
[self.containedViewController removeFromParentViewController];
self.started = NO; self.started = NO;
} }
...@@ -198,9 +277,7 @@ ...@@ -198,9 +277,7 @@
if (self.browser->GetBrowserState()->IsOffTheRecord()) { if (self.browser->GetBrowserState()->IsOffTheRecord()) {
return self.incognitoViewController; return self.incognitoViewController;
} else { } else {
return IsRefactoredNTP() return self.containerViewController;
? self.ntpViewController
: self.contentSuggestionsCoordinator.viewController;
} }
} }
...@@ -219,7 +296,7 @@ ...@@ -219,7 +296,7 @@
} }
- (void)willUpdateSnapshot { - (void)willUpdateSnapshot {
if (IsRefactoredNTP()) { if ([self isNTPRefactoredAndFeedVisible]) {
[self.ntpViewController willUpdateSnapshot]; [self.ntpViewController willUpdateSnapshot];
} else { } else {
[self.contentSuggestionsCoordinator willUpdateSnapshot]; [self.contentSuggestionsCoordinator willUpdateSnapshot];
...@@ -231,7 +308,7 @@ ...@@ -231,7 +308,7 @@
} }
- (void)reload { - (void)reload {
if (IsRefactoredNTP()) { if ([self isNTPRefactoredAndFeedVisible]) {
ios::GetChromeBrowserProvider()->GetDiscoverFeedProvider()->RefreshFeed(); ios::GetChromeBrowserProvider()->GetDiscoverFeedProvider()->RefreshFeed();
} }
[self reloadContentSuggestions]; [self reloadContentSuggestions];
...@@ -255,6 +332,14 @@ ...@@ -255,6 +332,14 @@
[self updateVisible]; [self updateVisible];
} }
#pragma mark - NewTabPageCommands
- (void)setDiscoverFeedVisible:(BOOL)visible {
[self stop];
[self start];
[self.containerViewController.view layoutIfNeeded];
}
#pragma mark - LogoAnimationControllerOwnerOwner #pragma mark - LogoAnimationControllerOwnerOwner
- (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
...@@ -346,4 +431,12 @@ ...@@ -346,4 +431,12 @@
.headerController heightAboveFakeOmnibox]; .headerController heightAboveFakeOmnibox];
} }
#pragma mark - Private
// YES if we're using the refactored NTP and the Discover Feed is visible.
- (BOOL)isNTPRefactoredAndFeedVisible {
return IsRefactoredNTP() &&
[self.contentSuggestionsCoordinator isDiscoverFeedVisible];
}
@end @end
...@@ -90,7 +90,8 @@ class NewTabPageCoordinatorTest : public PlatformTest { ...@@ -90,7 +90,8 @@ class NewTabPageCoordinatorTest : public PlatformTest {
NewTabPageCoordinator* coordinator_; NewTabPageCoordinator* coordinator_;
}; };
// Tests that the coordinator vends a content suggestions VC on the record. // Tests that the coordinator doesn't vend an IncognitoViewController VC on the
// record.
TEST_F(NewTabPageCoordinatorTest, StartOnTheRecord) { TEST_F(NewTabPageCoordinatorTest, StartOnTheRecord) {
CreateCoordinator(/*off_the_record=*/false); CreateCoordinator(/*off_the_record=*/false);
id omniboxCommandsHandlerMock = OCMProtocolMock(@protocol(OmniboxCommands)); id omniboxCommandsHandlerMock = OCMProtocolMock(@protocol(OmniboxCommands));
...@@ -103,13 +104,7 @@ TEST_F(NewTabPageCoordinatorTest, StartOnTheRecord) { ...@@ -103,13 +104,7 @@ TEST_F(NewTabPageCoordinatorTest, StartOnTheRecord) {
forProtocol:@protocol(SnackbarCommands)]; forProtocol:@protocol(SnackbarCommands)];
[coordinator_ start]; [coordinator_ start];
UIViewController* viewController = [coordinator_ viewController]; UIViewController* viewController = [coordinator_ viewController];
if (IsRefactoredNTP()) { EXPECT_FALSE([viewController isKindOfClass:[IncognitoViewController class]]);
EXPECT_TRUE(
[viewController isKindOfClass:[NewTabPageViewController class]]);
} else {
EXPECT_TRUE([viewController
isKindOfClass:[ContentSuggestionsViewController class]]);
}
[coordinator_ stop]; [coordinator_ stop];
} }
......
...@@ -40,7 +40,8 @@ ...@@ -40,7 +40,8 @@
_suggestionViewController = [[ContentSuggestionsViewController alloc] _suggestionViewController = [[ContentSuggestionsViewController alloc]
initWithStyle:CollectionViewControllerStyleDefault initWithStyle:CollectionViewControllerStyleDefault
offset:0]; offset:0
feedVisible:NO];
[_suggestionViewController setDataSource:_dataSource]; [_suggestionViewController setDataSource:_dataSource];
_suggestionViewController.suggestionCommandHandler = _suggestionViewController.suggestionCommandHandler =
......
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