Commit a228fb37 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Update tab grid selection behavior

The selection was previously done simulataneously with
insertions/deletions, which resulted in one-off selection error.
Selection should be done after any insert/delete operation.

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Iea75f1233a587fe0970fd01219a96de10255968f
Reviewed-on: https://chromium-review.googlesource.com/959723Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542804}
parent 2e2541e8
......@@ -4,10 +4,8 @@
#import "ios/chrome/browser/ui/tab_grid/grid_view_controller.h"
#import "base/ios/block_types.h"
#import "base/mac/foundation_util.h"
#import "base/numerics/safe_conversions.h"
#include "ios/chrome/browser/procedural_block_types.h"
#import "ios/chrome/browser/ui/tab_grid/grid_cell.h"
#import "ios/chrome/browser/ui/tab_grid/grid_constants.h"
#import "ios/chrome/browser/ui/tab_grid/grid_image_data_source.h"
......@@ -208,7 +206,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)insertItem:(GridItem*)item
atIndex:(NSUInteger)index
selectedIndex:(NSUInteger)selectedIndex {
ProceduralBlock performDataSourceUpdates = ^{
auto performDataSourceUpdates = ^{
[self.items insertObject:item atIndex:index];
self.selectedIndex = selectedIndex;
};
......@@ -216,16 +214,16 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
performDataSourceUpdates();
return;
}
ProceduralBlock performAllUpdates = ^{
auto performAllUpdates = ^{
performDataSourceUpdates();
self.collectionView.backgroundView.hidden = YES;
[self.collectionView insertItemsAtIndexPaths:@[ CreateIndexPath(index) ]];
};
auto completion = ^(BOOL finished) {
[self.collectionView
selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionNone];
};
ProceduralBlockWithBool completion = ^(BOOL finished) {
if (self.items.count == 1) {
[self.delegate firstItemWasAddedInGridViewController:self];
}
......@@ -236,7 +234,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)removeItemAtIndex:(NSUInteger)index
selectedIndex:(NSUInteger)selectedIndex {
ProceduralBlock performDataSourceUpdates = ^{
auto performDataSourceUpdates = ^{
[self.items removeObjectAtIndex:index];
self.selectedIndex = selectedIndex;
};
......@@ -244,18 +242,17 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
performDataSourceUpdates();
return;
}
ProceduralBlock performAllUpdates = ^{
auto performAllUpdates = ^{
performDataSourceUpdates();
[self.collectionView deleteItemsAtIndexPaths:@[ CreateIndexPath(index) ]];
};
auto completion = ^(BOOL finished) {
if (self.items.count > 0) {
[self.collectionView
selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionNone];
}
};
ProceduralBlockWithBool completion = ^(BOOL finished) {
if (self.items.count == 0) {
} else {
self.collectionView.backgroundView.hidden = NO;
[self.delegate lastItemWasClosedInGridViewController:self];
}
......@@ -284,7 +281,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (void)moveItemFromIndex:(NSUInteger)fromIndex
toIndex:(NSUInteger)toIndex
selectedIndex:(NSUInteger)selectedIndex {
ProceduralBlock performDataSourceUpdates = ^{
auto performDataSourceUpdates = ^{
GridItem* item = self.items[fromIndex];
[self.items removeObjectAtIndex:fromIndex];
[self.items insertObject:item atIndex:toIndex];
......@@ -294,16 +291,19 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
performDataSourceUpdates();
return;
}
ProceduralBlock performAllUpdates = ^{
auto performAllUpdates = ^{
performDataSourceUpdates();
[self.collectionView moveItemAtIndexPath:CreateIndexPath(fromIndex)
toIndexPath:CreateIndexPath(toIndex)];
};
auto completion = ^(BOOL finished) {
[self.collectionView
selectItemAtIndexPath:CreateIndexPath(selectedIndex)
animated:YES
scrollPosition:UICollectionViewScrollPositionNone];
};
[self.collectionView performBatchUpdates:performAllUpdates completion:nil];
[self.collectionView performBatchUpdates:performAllUpdates
completion:completion];
}
#pragma mark - Private
......
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