Commit 69e4263a authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Use NTP snapshot in new tab animation from grid.

New tabs opened from the grid were shown as white as they animated open,
because they were only showing the cell's snapshot, not the snapshot
taken from the BVC that will be displayed.

This was because the gird animation only shows the BVC snapshot if it
thinks there will be a difference between it and the cell snapshot --
specifically when there's been a device rotation.

This CL lets the grid view controller flag the active cell in the
animation as "appearing" so that the animation can always show the
BVC's snapshot in that case.

Bug: 865978
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Iede4af004e89e5fda1395c4257c3d74fd2a682c7
Reviewed-on: https://chromium-review.googlesource.com/1156685
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579470}
parent db5f4939
...@@ -50,6 +50,9 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -50,6 +50,9 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
@property(nonatomic, copy) NSString* selectedItemID; @property(nonatomic, copy) NSString* selectedItemID;
// Index of the selected item in |items|. // Index of the selected item in |items|.
@property(nonatomic, readonly) NSUInteger selectedIndex; @property(nonatomic, readonly) NSUInteger selectedIndex;
// ID of the last item to be inserted. This is used to track if the active tab
// was newly created when building the animation layout for transitions.
@property(nonatomic, copy) NSString* lastInsertedItemID;
// The gesture recognizer used for interactive item reordering. // The gesture recognizer used for interactive item reordering.
@property(nonatomic, strong) @property(nonatomic, strong)
UILongPressGestureRecognizer* itemReorderRecognizer; UILongPressGestureRecognizer* itemReorderRecognizer;
...@@ -79,6 +82,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -79,6 +82,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
@synthesize collectionView = _collectionView; @synthesize collectionView = _collectionView;
@synthesize items = _items; @synthesize items = _items;
@synthesize selectedItemID = _selectedItemID; @synthesize selectedItemID = _selectedItemID;
@synthesize lastInsertedItemID = _lastInsertedItemID;
@synthesize itemReorderRecognizer = _itemReorderRecognizer; @synthesize itemReorderRecognizer = _itemReorderRecognizer;
@synthesize itemReorderTouchPoint = _itemReorderTouchPoint; @synthesize itemReorderTouchPoint = _itemReorderTouchPoint;
@synthesize emptyStateAnimator = _emptyStateAnimator; @synthesize emptyStateAnimator = _emptyStateAnimator;
...@@ -150,6 +154,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -150,6 +154,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
// Update the delegate, in case it wasn't set when |items| was populated. // Update the delegate, in case it wasn't set when |items| was populated.
[self.delegate gridViewController:self didChangeItemCount:self.items.count]; [self.delegate gridViewController:self didChangeItemCount:self.items.count];
[self animateEmptyStateOut]; [self animateEmptyStateOut];
self.lastInsertedItemID = nil;
} }
- (void)viewWillDisappear:(BOOL)animated { - (void)viewWillDisappear:(BOOL)animated {
...@@ -218,6 +223,10 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -218,6 +223,10 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
activeItem = [GridTransitionActiveItem itemWithCell:activeCell activeItem = [GridTransitionActiveItem itemWithCell:activeCell
center:attributes.center center:attributes.center
size:attributes.size]; size:attributes.size];
// If the active item is the last inserted item, it needs to be animated
// differently.
if ([cell.itemIdentifier isEqualToString:self.lastInsertedItemID])
activeItem.isAppearing = YES;
selectionItem = [GridTransitionItem selectionItem = [GridTransitionItem
itemWithCell:[GridTransitionSelectionCell transitionCellFromCell:cell] itemWithCell:[GridTransitionSelectionCell transitionCellFromCell:cell]
center:attributes.center]; center:attributes.center];
...@@ -357,6 +366,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) { ...@@ -357,6 +366,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
auto modelUpdates = ^{ auto modelUpdates = ^{
[self.items insertObject:item atIndex:index]; [self.items insertObject:item atIndex:index];
self.selectedItemID = selectedItemID; self.selectedItemID = selectedItemID;
self.lastInsertedItemID = item.identifier;
[self.delegate gridViewController:self didChangeItemCount:self.items.count]; [self.delegate gridViewController:self didChangeItemCount:self.items.count];
}; };
auto collectionViewUpdates = ^{ auto collectionViewUpdates = ^{
......
...@@ -61,7 +61,6 @@ ...@@ -61,7 +61,6 @@
[containerView addSubview:presentedView]; [containerView addSubview:presentedView];
presentedView.frame = presentedView.frame =
[transitionContext finalFrameForViewController:presentedViewController]; [transitionContext finalFrameForViewController:presentedViewController];
presentedView.alpha = 0.0;
// Get the layout of the grid for the transition. // Get the layout of the grid for the transition.
GridTransitionLayout* layout = GridTransitionLayout* layout =
...@@ -103,6 +102,10 @@ ...@@ -103,6 +102,10 @@
[self.stateProvider proxyPositionForTransitionContext:transitionContext]; [self.stateProvider proxyPositionForTransitionContext:transitionContext];
[proxyContainer insertSubview:self.animation aboveSubview:viewBehindProxies]; [proxyContainer insertSubview:self.animation aboveSubview:viewBehindProxies];
// Make the presented view alpha-zero; this should happen after all snapshots
// are taken.
presentedView.alpha = 0.1;
[self.animation.animator addCompletion:^(UIViewAnimatingPosition position) { [self.animation.animator addCompletion:^(UIViewAnimatingPosition position) {
BOOL finished = (position == UIViewAnimatingPositionEnd); BOOL finished = (position == UIViewAnimatingPositionEnd);
[self gridTransitionAnimationDidFinish:finished]; [self gridTransitionAnimationDidFinish:finished];
......
...@@ -262,9 +262,13 @@ CGFloat DeviceCornerRadius() { ...@@ -262,9 +262,13 @@ CGFloat DeviceCornerRadius() {
// is shown. // is shown.
UIView<GridToTabTransitionView>* activeCell = self.layout.activeItem.cell; UIView<GridToTabTransitionView>* activeCell = self.layout.activeItem.cell;
// The top and main tab views start at zero alpha but are crossfaded in. // The top tab view starts at zero alpha but is crossfaded in.
activeCell.mainTabView.alpha = 0.0;
activeCell.topTabView.alpha = 0.0; activeCell.topTabView.alpha = 0.0;
// If the active item is appearing, the main tab view is shown. If not, it's
// hidden, and may be faded in if it's expected to be different in content
// from the existing cell snapshot.
if (!self.layout.activeItem.isAppearing)
activeCell.mainTabView.alpha = 0.0;
// A: Zoom the active cell into position. // A: Zoom the active cell into position.
UIViewPropertyAnimator* zoomActiveCell = UIViewPropertyAnimator* zoomActiveCell =
......
...@@ -75,6 +75,9 @@ ...@@ -75,6 +75,9 @@
// The size of |cell| in the grid. // The size of |cell| in the grid.
@property(nonatomic, readonly) CGSize size; @property(nonatomic, readonly) CGSize size;
// YES if the item is "appearing" in the grid as part of this animation.
@property(nonatomic, assign) BOOL isAppearing;
// Creates a new active item instance with |cell|, |center| and |size|. // Creates a new active item instance with |cell|, |center| and |size|.
+ (instancetype)itemWithCell:(UIView<GridToTabTransitionView>*)cell + (instancetype)itemWithCell:(UIView<GridToTabTransitionView>*)cell
center:(CGPoint)center center:(CGPoint)center
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
@implementation GridTransitionActiveItem @implementation GridTransitionActiveItem
@dynamic cell; @dynamic cell;
@synthesize size = _size; @synthesize size = _size;
@synthesize isAppearing = _isAppearing;
+ (instancetype)itemWithCell:(UIView<GridToTabTransitionView>*)cell + (instancetype)itemWithCell:(UIView<GridToTabTransitionView>*)cell
center:(CGPoint)center center:(CGPoint)center
......
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