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; ...@@ -296,6 +296,7 @@ const CGFloat kToolbarHeight = 56;
- (BOOL)loadPanel:(NewTabPageBarItem*)item { - (BOOL)loadPanel:(NewTabPageBarItem*)item {
DCHECK(self.parentViewController); DCHECK(self.parentViewController);
UIViewController* panelController = nil; UIViewController* panelController = nil;
UICollectionView* collectionView = nil;
// Only load the controllers once. // Only load the controllers once.
if (item.identifier == ntp_home::HOME_PANEL) { if (item.identifier == ntp_home::HOME_PANEL) {
if (!self.contentSuggestionsCoordinator) { if (!self.contentSuggestionsCoordinator) {
...@@ -311,6 +312,8 @@ const CGFloat kToolbarHeight = 56; ...@@ -311,6 +312,8 @@ const CGFloat kToolbarHeight = 56;
self.contentSuggestionsCoordinator.headerController; self.contentSuggestionsCoordinator.headerController;
} }
panelController = [self.contentSuggestionsCoordinator viewController]; panelController = [self.contentSuggestionsCoordinator viewController];
collectionView =
self.contentSuggestionsCoordinator.viewController.collectionView;
self.homePanel = self.contentSuggestionsCoordinator; self.homePanel = self.contentSuggestionsCoordinator;
[self.homePanel setDelegate:self]; [self.homePanel setDelegate:self];
} else if (item.identifier == ntp_home::INCOGNITO_PANEL) { } else if (item.identifier == ntp_home::INCOGNITO_PANEL) {
...@@ -346,6 +349,7 @@ const CGFloat kToolbarHeight = 56; ...@@ -346,6 +349,7 @@ const CGFloat kToolbarHeight = 56;
[self.parentViewController addChildViewController:panelController]; [self.parentViewController addChildViewController:panelController];
[self.view insertSubview:view belowSubview:self.view.tabBar]; [self.view insertSubview:view belowSubview:self.view.tabBar];
self.view.contentView = view; self.view.contentView = view;
self.view.contentCollectionView = collectionView;
[panelController didMoveToParentViewController:self.parentViewController]; [panelController didMoveToParentViewController:self.parentViewController];
} }
return created; return created;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
@interface NewTabPageView : UIView @interface NewTabPageView : UIView
@property(nonatomic, weak, readonly) NewTabPageBar* tabBar; @property(nonatomic, weak, readonly) NewTabPageBar* tabBar;
@property(nonatomic, weak) UIView* contentView; @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 // 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 // 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, // snapshot of the view is taken before it is inserted in the view hierarchy,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
@implementation NewTabPageView @implementation NewTabPageView
@synthesize contentView = _contentView; @synthesize contentView = _contentView;
@synthesize contentCollectionView = _contentCollectionView;
@synthesize tabBar = tabBar_; @synthesize tabBar = tabBar_;
@synthesize safeAreaInsetForToolbar = _safeAreaInsetForToolbar; @synthesize safeAreaInsetForToolbar = _safeAreaInsetForToolbar;
...@@ -76,9 +77,13 @@ ...@@ -76,9 +77,13 @@
self.tabBar.frame = CGRectMake(CGRectGetMinX(self.bounds), self.tabBar.frame = CGRectMake(CGRectGetMinX(self.bounds),
CGRectGetMaxY(self.bounds) - barSize.height, CGRectGetMaxY(self.bounds) - barSize.height,
barSize.width, barSize.height); barSize.width, barSize.height);
CGRect previousContentFrame = self.contentView.frame;
self.contentView.frame = CGRectMake( self.contentView.frame = CGRectMake(
CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds), CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds),
CGRectGetWidth(self.bounds), CGRectGetMinY(self.tabBar.frame)); 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, // 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