Commit 040c114d authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Don't show selection change when leaving tab grid.

Per the attached bug, this CL changes the tab grid to not show the changed selection state when leaving the tab grid via a tap on a cell.

Cell selection actually happened twice when a cell was tapped; once directly from the collection view, and a second time after the selection had round-tripped through the mediator. This CL cleans that up, and has the collection view decline all selection events, allowing them only to happen as a result of consumer calls.

This CL adds a |showSelectionState| property to the grid view controller; when set to NO, the grid view controller will not update the selection state of the cells when the -selectWithItemID: consumer call is received. The ID of the selected item is maintained, however.

This Cl also doesn't show the selection ring on the proxy cells animated for the transition.

Bug: 849642

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ibf8d2c91dc80c42dea55c7e457efe7232d234267
Reviewed-on: https://chromium-review.googlesource.com/1096763Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567192}
parent 416dec0b
......@@ -52,6 +52,9 @@
// YES if the selected cell is visible in the grid.
@property(nonatomic, readonly, getter=isSelectedCellVisible)
BOOL selectedCellVisible;
// YES if the gid should show cell selection updates. This would be set to NO,
// for example, if the grid was about to be transitioned out of.
@property(nonatomic, assign) BOOL showsSelectionUpdates;
// Returns the layout of the grid for use in an animated transition.
- (GridTransitionLayout*)transitionLayout;
......
......@@ -63,6 +63,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
@synthesize delegate = _delegate;
@synthesize imageDataSource = _imageDataSource;
@synthesize emptyStateView = _emptyStateView;
@synthesize showsSelectionUpdates = _showsSelectionUpdates;
// Private properties.
@synthesize viewAppeared = _viewAppeared;
@synthesize collectionView = _collectionView;
......@@ -75,6 +76,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (instancetype)init {
if (self = [super init]) {
_items = [[NSMutableArray<GridItem*> alloc] init];
_showsSelectionUpdates = YES;
}
return self;
}
......@@ -185,7 +187,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
[GridTransitionLayoutItem itemWithCell:[cell proxyForTransitions]
attributes:attributes];
[items addObject:item];
if (cell.selected) {
if ([cell.itemIdentifier isEqualToString:self.selectedItemID]) {
selectedItem = item;
}
}
......@@ -236,12 +238,16 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView*)collectionView
didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
// This method is used instead of -willSelectItemAtIndexPath, because any
// selection events will be signalled through the model layer and handled in
// the GridConsumer -selectItemWithID: method.
- (BOOL)collectionView:(UICollectionView*)collectionView
shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath {
NSUInteger index = base::checked_cast<NSUInteger>(indexPath.item);
DCHECK_LT(index, self.items.count);
NSString* itemID = self.items[index].identifier;
[self.delegate gridViewController:self didSelectItemWithID:itemID];
return NO;
}
#pragma mark - GridCellDelegate
......@@ -337,7 +343,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)selectItemWithID:(NSString*)selectedItemID {
self.selectedItemID = selectedItemID;
if (![self isViewAppeared])
if (!([self isViewAppeared] && self.showsSelectionUpdates))
return;
[self.collectionView
selectItemAtIndexPath:CreateIndexPath(self.selectedIndex)
......
......@@ -755,6 +755,10 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
- (void)gridViewController:(GridViewController*)gridViewController
didSelectItemWithID:(NSString*)itemID {
// Update the model with the tab selection, but don't have the grid view
// controller display the new selection, since there will be a transition
// away from it immediately afterwards.
gridViewController.showsSelectionUpdates = NO;
if (gridViewController == self.regularTabsViewController) {
[self.regularTabsDelegate selectItemWithID:itemID];
} else if (gridViewController == self.incognitoTabsViewController) {
......@@ -762,6 +766,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
}
self.activePage = self.currentPage;
[self.tabPresentationDelegate showActiveTabInPage:self.currentPage];
gridViewController.showsSelectionUpdates = YES;
}
- (void)gridViewController:(GridViewController*)gridViewController
......
......@@ -70,7 +70,6 @@
break;
case GridAnimationDirectionExpanding:
[self positionSelectedItemInRegularGrid];
self.layout.selectedItem.cell.selected = YES;
[self positionUnselectedItemsInRegularGrid];
break;
}
......
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