Commit e01e660f authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Invalidate NTP collection layout on frame changes

This CL invalidates the layout of the collection view displayed by the
NTP (the content suggestions' one) when the frame changes. It allows
to have a snapshot with the correct layout when opening a tab from the
stack view.

Bug: 806069
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I2e79a0f9ec72e753d552006f1f31013f51173523
Reviewed-on: https://chromium-review.googlesource.com/888580Reviewed-by: default avatarLouis Romero <lpromero@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532356}
parent d49c3fe0
......@@ -296,6 +296,7 @@ const CGFloat kToolbarHeight = 56;
- (BOOL)loadPanel:(NewTabPageBarItem*)item {
DCHECK(self.parentViewController);
UIViewController* panelController = nil;
UICollectionView* collectionView = nil;
// Only load the controllers once.
if (item.identifier == ntp_home::HOME_PANEL) {
if (!self.contentSuggestionsCoordinator) {
......@@ -311,6 +312,8 @@ const CGFloat kToolbarHeight = 56;
self.contentSuggestionsCoordinator.headerController;
}
panelController = [self.contentSuggestionsCoordinator viewController];
collectionView =
self.contentSuggestionsCoordinator.viewController.collectionView;
self.homePanel = self.contentSuggestionsCoordinator;
[self.homePanel setDelegate:self];
} else if (item.identifier == ntp_home::INCOGNITO_PANEL) {
......@@ -346,6 +349,7 @@ const CGFloat kToolbarHeight = 56;
[self.parentViewController addChildViewController:panelController];
[self.view insertSubview:view belowSubview:self.view.tabBar];
self.view.contentView = view;
self.view.contentCollectionView = collectionView;
[panelController didMoveToParentViewController:self.parentViewController];
}
return created;
......
......@@ -14,6 +14,7 @@
@interface NewTabPageView : UIView
@property(nonatomic, weak, readonly) NewTabPageBar* tabBar;
@property(nonatomic, weak) UIView* contentView;
@property(nonatomic, weak) UICollectionView* contentCollectionView;
// Safe area to be used for toolbar. Once the view is part of the view hierarchy
// and has its own safe area set, this is equal to safeAreaInsets. But as a
// snapshot of the view is taken before it is inserted in the view hierarchy,
......
......@@ -16,6 +16,7 @@
@implementation NewTabPageView
@synthesize contentView = _contentView;
@synthesize contentCollectionView = _contentCollectionView;
@synthesize tabBar = tabBar_;
@synthesize safeAreaInsetForToolbar = _safeAreaInsetForToolbar;
......@@ -76,9 +77,13 @@
self.tabBar.frame = CGRectMake(CGRectGetMinX(self.bounds),
CGRectGetMaxY(self.bounds) - barSize.height,
barSize.width, barSize.height);
CGRect previousContentFrame = self.contentView.frame;
self.contentView.frame = CGRectMake(
CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds),
CGRectGetWidth(self.bounds), CGRectGetMinY(self.tabBar.frame));
if (!CGRectEqualToRect(previousContentFrame, self.contentView.frame)) {
[self.contentCollectionView.collectionViewLayout invalidateLayout];
}
}
// When using a new_tab_page_view in autolayout -setFrame is never called,
......
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