Commit d36901d9 authored by gambard's avatar gambard Committed by Commit Bot

Fix animation on ContentSuggestions rotations

When there is an animation on the NTP screen with ContentSuggestions,
the appearing and disappearing icons are shown with an alpha of 1
during the whole animation.
This CL fixes this by reloading the data during the rotation.

Before: https://drive.google.com/open?id=0B21N-0pPGAuJMHVhWDRvdU55ODg
After: https://drive.google.com/open?id=0B21N-0pPGAuJYm13cW5IVDRiUjQ

BUG=700375

Change-Id: Ie2c928ff1d012439cf329948713f2ff46887b7d2
Reviewed-on: https://chromium-review.googlesource.com/561776
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarLouis Romero <lpromero@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485199}
parent ca98682a
......@@ -76,7 +76,8 @@ addSuggestionsToModel:
// header containing the fake omnibox and the logo.
- (BOOL)isHeaderSection:(NSInteger)section;
// Updates the number of Most Visited tiles shown for the |size|.
// Updates the number of Most Visited tiles shown for the |size| on the model
// only. The collection needs to be updated separately.
- (void)updateMostVisitedForSize:(CGSize)size;
// Dismisses the |item| from the model. Does not change the UI.
......
......@@ -446,24 +446,22 @@ addSuggestionsToModel:(NSArray<CSCollectionViewItem*>*)suggestions
if (currentCount == newCount)
return;
// If the animations are enabled, the items are added then the rotation
// animation is triggered, creating a weird sequenced animation.
[UIView setAnimationsEnabled:NO];
if (currentCount > newCount) {
for (NSInteger i = newCount; i < currentCount; i++) {
NSIndexPath* itemToRemove =
[NSIndexPath indexPathForItem:newCount inSection:mostVisitedSection];
[self.collectionViewController dismissEntryAtIndexPath:itemToRemove];
[self.collectionViewController.collectionViewModel
removeItemWithType:ItemTypeMostVisited
fromSectionWithIdentifier:SectionIdentifierMostVisited
atIndex:newCount];
}
} else {
NSMutableArray* itemsToBeAdded = [NSMutableArray array];
for (NSInteger i = currentCount; i < newCount; i++) {
[itemsToBeAdded addObject:mostVisited[i]];
CSCollectionViewItem* item = mostVisited[i];
item.type = ItemTypeMostVisited;
[self.collectionViewController.collectionViewModel
addItem:item
toSectionWithIdentifier:SectionIdentifierMostVisited];
}
[self.collectionViewController addSuggestions:itemsToBeAdded
toSectionInfo:mostVisitedSectionInfo];
}
[UIView setAnimationsEnabled:YES];
}
- (void)dismissItem:(CSCollectionViewItem*)item {
......
......@@ -204,7 +204,7 @@ BOOL ShouldCellsBeFullWidth(UITraitCollection* collection) {
UIEdgeInsetsMake(0, self.cardStyleMargin, 0, self.cardStyleMargin);
}
[self.collectionUpdater updateMostVisitedForSize:size];
[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];
}
- (void)willTransitionToTraitCollection:(UITraitCollection*)newCollection
......@@ -212,6 +212,10 @@ BOOL ShouldCellsBeFullWidth(UITraitCollection* collection) {
(id<UIViewControllerTransitionCoordinator>)coordinator {
[super willTransitionToTraitCollection:newCollection
withTransitionCoordinator:coordinator];
// Invalidating the layout after changing the cellStyle/contentInset results
// in the layout not being updated. Do it before to have it taken into
// account.
[self.collectionView.collectionViewLayout invalidateLayout];
if (ShouldCellsBeFullWidth(newCollection)) {
self.collectionView.contentInset = UIEdgeInsetsZero;
self.styler.cellStyle = MDCCollectionViewCellStyleGrouped;
......@@ -220,7 +224,6 @@ BOOL ShouldCellsBeFullWidth(UITraitCollection* collection) {
UIEdgeInsetsMake(0, self.cardStyleMargin, 0, self.cardStyleMargin);
self.styler.cellStyle = MDCCollectionViewCellStyleCard;
}
[self.collectionView.collectionViewLayout invalidateLayout];
}
#pragma mark - UICollectionViewDelegate
......
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