Commit 2d89d852 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Don't animate grid item insertions before presenting NTP.

This CL adds GridLayout.animatesItemUpdates, which can be used to
disable animations from occurring when items are inserted or removed.
This is done to prevent the interleving of the new tab insertion
animation and the tab presentation animation.

Bug: 864982
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I7867fc475a6d399a8ecbe45df456fd6082f6d8eb
Reviewed-on: https://chromium-review.googlesource.com/1161560Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580631}
parent e8b14cdd
......@@ -11,6 +11,10 @@
// square-ish. Item sizes adapt to the size classes they are shown in. Item
// deletions are animated.
@interface GridLayout : UICollectionViewFlowLayout
// Whether to animate item insertions and deletions.
@property(nonatomic, assign) BOOL animatesItemUpdates;
@end
// A specialization of GridLayout that shows the UI in its "reordering" state,
......
......@@ -16,9 +16,17 @@
@end
@implementation GridLayout
@synthesize animatesItemUpdates = _animatesItemUpdates;
@synthesize indexPathsOfDeletingItems = _indexPathsOfDeletingItems;
@synthesize indexPathsOfInsertingItems = _indexPathsOfInsertingItems;
- (instancetype)init {
if (self = [super init]) {
_animatesItemUpdates = YES;
}
return self;
}
#pragma mark - UICollectionViewLayout
// This is called whenever the layout is invalidated, including during rotation.
......@@ -93,6 +101,10 @@
- (UICollectionViewLayoutAttributes*)
finalLayoutAttributesForDisappearingItemAtIndexPath:
(NSIndexPath*)itemIndexPath {
// Return initial layout if animations are disabled.
if (!self.animatesItemUpdates) {
return [self layoutAttributesForItemAtIndexPath:itemIndexPath];
}
// Note that this method is called for any item whose index path changing from
// |itemIndexPath|, which includes any items that were in the layout and whose
// index path is changing. For an item whose index path is changing, this
......@@ -120,6 +132,10 @@ finalLayoutAttributesForDisappearingItemAtIndexPath:
- (UICollectionViewLayoutAttributes*)
initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath*)itemIndexPath {
// Return final layout if animations are disabled.
if (!self.animatesItemUpdates) {
return [self layoutAttributesForItemAtIndexPath:itemIndexPath];
}
// Note that this method is called for any item whose index path is becoming
// |itemIndexPath|, which includes any items that were in the layout but whose
// index path is changing. For an item whose index path is changing, this
......
......@@ -59,6 +59,9 @@
// Returns the layout of the grid for use in an animated transition.
- (GridTransitionLayout*)transitionLayout;
// Notifies the grid that it is about to be dismissed.
- (void)prepareForDismissal;
@end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_GRID_VIEW_CONTROLLER_H_
......@@ -64,7 +64,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
// Animator to show or hide the empty state.
@property(nonatomic, strong) UIViewPropertyAnimator* emptyStateAnimator;
// The default layout for the tab grid.
@property(nonatomic, strong) UICollectionViewLayout* defaultLayout;
@property(nonatomic, strong) GridLayout* defaultLayout;
// The layout used while the grid is being reordered.
@property(nonatomic, strong) UICollectionViewLayout* reorderingLayout;
......@@ -142,6 +142,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.updatesCollectionView = YES;
self.defaultLayout.animatesItemUpdates = YES;
[self.collectionView reloadData];
// Selection is invalid if there are no items.
if (self.items.count == 0) {
......@@ -243,6 +244,12 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
selectionItem:selectionItem];
}
- (void)prepareForDismissal {
// Stop animating the collection view to prevent the insertion animation from
// interfering with the tab presentation animation.
self.defaultLayout.animatesItemUpdates = NO;
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView*)collectionView
......
......@@ -987,6 +987,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
- (void)openNewTabInPage:(TabGridPage)page focusOmnibox:(BOOL)focusOmnibox {
switch (page) {
case TabGridPageIncognitoTabs:
[self.incognitoTabsViewController prepareForDismissal];
[self.incognitoTabsDelegate addNewItem];
// Record when new incognito tab is created.
// TODO(crbug.com/856965) : Rename metrics.
......@@ -994,6 +995,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
base::UserMetricsAction("MobileTabSwitcherCreateIncognitoTab"));
break;
case TabGridPageRegularTabs:
[self.regularTabsViewController prepareForDismissal];
[self.regularTabsDelegate addNewItem];
// Record when new regular tab is created.
// TODO(crbug.com/856965) : Rename metrics.
......
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