Commit f49290e8 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Animate tab grid cell deletion.

This CL customizes the deletion animation for tab grid cells via the
standard UICollectionViewLayout APIs.

Animation is done by adjusting the final layout attributes of the cell
in -finalLayoutAttributesForDisappearingItemAtIndexPath:. Because cells
may disappear for non-deleting reasons, the layout also needs to track
which cells are being deleted during each update cycle.

Bug: 804553
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I8566a5aff832ac8844d2d89639599b1b2372a27d
Reviewed-on: https://chromium-review.googlesource.com/964223Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543389}
parent f53bc613
......@@ -15,11 +15,13 @@ const CGFloat kInterTabSpacing = 20.0f;
@interface GridLayout ()
@property(nonatomic, assign) CGFloat startingTabWidth;
@property(nonatomic, assign) CGFloat maxTabWidth;
@property(nonatomic, strong) NSArray<NSIndexPath*>* indexPathsOfDeletingItems;
@end
@implementation GridLayout
@synthesize startingTabWidth = _startingTabWidth;
@synthesize maxTabWidth = _maxTabWidth;
@synthesize indexPathsOfDeletingItems = _indexPathsOfDeletingItems;
- (instancetype)init {
if (self = [super init]) {
......@@ -42,6 +44,44 @@ const CGFloat kInterTabSpacing = 20.0f;
}
}
- (void)prepareForCollectionViewUpdates:
(NSArray<UICollectionViewUpdateItem*>*)updateItems {
NSMutableArray<NSIndexPath*>* deletingItems =
[NSMutableArray arrayWithCapacity:updateItems.count];
for (UICollectionViewUpdateItem* item in updateItems) {
if (item.updateAction == UICollectionUpdateActionDelete) {
[deletingItems addObject:item.indexPathBeforeUpdate];
}
}
self.indexPathsOfDeletingItems = [deletingItems copy];
}
- (UICollectionViewLayoutAttributes*)
finalLayoutAttributesForDisappearingItemAtIndexPath:
(NSIndexPath*)itemIndexPath {
UICollectionViewLayoutAttributes* attributes =
[super finalLayoutAttributesForDisappearingItemAtIndexPath:itemIndexPath];
// Disappearing items that aren't being deleted just use the default
// attributes.
if (![self.indexPathsOfDeletingItems containsObject:itemIndexPath]) {
return attributes;
}
// Cells being deleted fade out, are scaled down, and drop downwards slightly.
attributes.alpha = 0.0;
// Scaled down to 60%.
CGAffineTransform transform =
CGAffineTransformScale(attributes.transform, 0.6, 0.6);
// Translated down (positive-y direction) by 50% of the cell cell size.
transform =
CGAffineTransformTranslate(transform, 0, attributes.size.height * 0.5);
attributes.transform = transform;
return attributes;
}
- (void)finalizeCollectionViewUpdates {
self.indexPathsOfDeletingItems = @[];
}
#pragma mark - Private
// This sets the appropriate itemSize given the width of the collection view.
......
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