Commit 9d8520be authored by edchin's avatar edchin Committed by Commit Bot

[ios] Animate tab grid empty state when closing last tab

This CL animates the appearance of the empty state prompt as the last
tab closes. The animation scales and fades in.

Bug: 804558
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I1449560d6be676030048e11cf32db21123c37e5f
Reviewed-on: https://chromium-review.googlesource.com/974576
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545070}
parent b31b3a75
......@@ -76,7 +76,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.collectionView reloadData];
self.collectionView.backgroundView.hidden = (self.items.count > 0);
self.emptyStateView.hidden = (self.items.count > 0);
// Selection is invalid if there are no items.
if (self.items.count == 0)
return;
......@@ -221,7 +221,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
}
auto performAllUpdates = ^{
performDataSourceUpdates();
self.collectionView.backgroundView.hidden = YES;
self.emptyStateView.hidden = YES;
[self.collectionView insertItemsAtIndexPaths:@[ CreateIndexPath(index) ]];
};
auto completion = ^(BOOL finished) {
......@@ -249,6 +249,9 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
auto performAllUpdates = ^{
performDataSourceUpdates();
[self.collectionView deleteItemsAtIndexPaths:@[ CreateIndexPath(index) ]];
if (self.items.count == 0) {
[self animateEmptyStateIntoView];
}
};
auto completion = ^(BOOL finished) {
if (self.items.count > 0) {
......@@ -256,8 +259,6 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionNone];
} else {
self.collectionView.backgroundView.hidden = NO;
}
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
};
......@@ -319,4 +320,26 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
return (self.isViewLoaded && self.view.window);
}
// Animates the empty state into view.
- (void)animateEmptyStateIntoView {
// TODO(crbug.com/820410) : Polish the animation, and put constants where they
// belong.
CGFloat scale = 0.8f;
CGAffineTransform originalTransform = self.emptyStateView.transform;
self.emptyStateView.transform =
CGAffineTransformScale(self.emptyStateView.transform, scale, scale);
self.emptyStateView.alpha = 0.0f;
self.emptyStateView.hidden = NO;
[UIView animateWithDuration:1.0f
delay:0.0f
usingSpringWithDamping:1.0f
initialSpringVelocity:0.7f
options:UIViewAnimationCurveEaseOut
animations:^{
self.emptyStateView.alpha = 1.0f;
self.emptyStateView.transform = originalTransform;
}
completion:nil];
}
@end
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