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;
}
@class ContentSuggestionsHeaderViewController;
@protocol NewTabPageCommands;
@protocol NewTabPageControllerDelegate;
@class NTPHomeMediator;
@class ViewRevealingVerticalPanHandler;
// Coordinator to manage the Suggestions UI via a
......@@ -36,6 +38,15 @@ class WebState;
// The pan gesture handler for the view controller.
@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.
- (void)dismissModals;
......@@ -61,6 +72,9 @@ class WebState;
// Constrains the named layout guide for the Discover header menu button.
- (void)constrainDiscoverHeaderMenuButtonNamedGuide;
// YES if the Discover feed is currently visible.
- (BOOL)isDiscoverFeedVisible;
@end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_COORDINATOR_H_
......@@ -29,8 +29,8 @@
// Creates layout with |offset| as additional height. Allows the view's height
// to be increased enough to maintain the scroll position. Only needed if
// Discover feed is enabled.
- (instancetype)initWithOffset:(CGFloat)offset;
// Discover feed is visible.
- (instancetype)initWithOffset:(CGFloat)offset feedVisible:(BOOL)visible;
@end
......
......@@ -15,22 +15,29 @@
#error "This file requires ARC support."
#endif
@interface ContentSuggestionsLayout ()
// YES if the Discover Feed is currently visible.
@property(nonatomic, assign, getter=isFeedVisible) BOOL feedVisible;
@end
@implementation ContentSuggestionsLayout
- (instancetype)initWithOffset:(CGFloat)offset {
- (instancetype)initWithOffset:(CGFloat)offset feedVisible:(BOOL)visible {
if (self = [super init]) {
_feedVisible = visible;
_offset = offset;
}
return self;
}
- (CGSize)collectionViewContentSize {
if (IsRefactoredNTP()) {
// In the refactored NTP, we don't want to extend the view height beyond its
// content.
if (IsRefactoredNTP() && [self isFeedVisible]) {
// In the refactored NTP and when the Feed is visible, we don't want to
// extend the view height beyond its content.
return [super collectionViewContentSize];
}
DCHECK(!IsRefactoredNTP());
CGFloat collectionViewHeight = self.collectionView.bounds.size.height;
CGFloat headerHeight = [self firstHeaderHeight];
......@@ -116,7 +123,7 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
if ([kind isEqualToString:UICollectionElementKindSectionHeader] &&
indexPath.section == 0) {
CGFloat contentOffset;
if (IsRefactoredNTP()) {
if (IsRefactoredNTP() && [self isFeedVisible]) {
contentOffset = self.parentCollectionView.contentOffset.y +
self.collectionView.contentSize.height;
} else {
......@@ -136,8 +143,11 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
ToolbarExpandedHeight(
[UIApplication sharedApplication].preferredContentSizeCategory) -
topSafeArea;
if (contentOffset > minY &&
(!IsRefactoredNTP() || !self.isScrolledIntoFeed)) {
// TODO(crbug.com/1114792): Remove mentioned of "refactored" from the
// variable name once this launches.
BOOL hasScrolledIntoRefactoredDiscoverFeed =
[self isFeedVisible] && self.isScrolledIntoFeed && IsRefactoredNTP();
if (contentOffset > minY && !hasScrolledIntoRefactoredDiscoverFeed) {
origin.y = contentOffset - minY;
}
attributes.frame = {origin, attributes.frame.size};
......
......@@ -38,9 +38,10 @@ extern NSString* const
ContentSuggestionsConsumer>
// 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
offset:(CGFloat)offset NS_DESIGNATED_INITIALIZER;
offset:(CGFloat)offset
feedVisible:(BOOL)visible NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithLayout:(UICollectionViewLayout*)layout
style:(CollectionViewControllerStyle)style
......
......@@ -116,9 +116,11 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
#pragma mark - Lifecycle
- (instancetype)initWithStyle:(CollectionViewControllerStyle)style
offset:(CGFloat)offset {
offset:(CGFloat)offset
feedVisible:(BOOL)visible {
_offset = offset;
_layout = [[ContentSuggestionsLayout alloc] initWithOffset:offset];
_layout = [[ContentSuggestionsLayout alloc] initWithOffset:offset
feedVisible:visible];
self = [super initWithLayout:_layout style:style];
if (self) {
_collectionUpdater = [[ContentSuggestionsCollectionUpdater alloc] init];
......
......@@ -4,6 +4,7 @@
source_set("ntp") {
sources = [
"new_tab_page_commands.h",
"new_tab_page_content_delegate.h",
"new_tab_page_controller_delegate.h",
"new_tab_page_header_constants.h",
......@@ -26,6 +27,8 @@ source_set("coordinator") {
":ntp_internal",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/search_engines",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/content_suggestions",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui",
......@@ -34,7 +37,9 @@ source_set("coordinator") {
"//ios/chrome/browser/ui/main:scene_state_observer",
"//ios/chrome/browser/ui/overscroll_actions",
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/voice",
"//ios/chrome/browser/web_state_list",
"//ios/chrome/common/ui/util",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/discover_feed",
"//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_
......@@ -90,7 +90,8 @@ class NewTabPageCoordinatorTest : public PlatformTest {
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) {
CreateCoordinator(/*off_the_record=*/false);
id omniboxCommandsHandlerMock = OCMProtocolMock(@protocol(OmniboxCommands));
......@@ -103,13 +104,7 @@ TEST_F(NewTabPageCoordinatorTest, StartOnTheRecord) {
forProtocol:@protocol(SnackbarCommands)];
[coordinator_ start];
UIViewController* viewController = [coordinator_ viewController];
if (IsRefactoredNTP()) {
EXPECT_TRUE(
[viewController isKindOfClass:[NewTabPageViewController class]]);
} else {
EXPECT_TRUE([viewController
isKindOfClass:[ContentSuggestionsViewController class]]);
}
EXPECT_FALSE([viewController isKindOfClass:[IncognitoViewController class]]);
[coordinator_ stop];
}
......
......@@ -40,7 +40,8 @@
_suggestionViewController = [[ContentSuggestionsViewController alloc]
initWithStyle:CollectionViewControllerStyleDefault
offset:0];
offset:0
feedVisible:NO];
[_suggestionViewController setDataSource:_dataSource];
_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