mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-06 06:58:26 +00:00
Summary: Adding an API to do item-level (cell) moves on the collection view. This complicates things a little bit because of all the issues that moving sections have while in batch updates (e.g. simultaneous animation UICV bugs). Thankfully we use pretty strict types so the compiler does most of the work for us. Closes #145 - [x] Tests build and pass - [x] Add `IGListBatchUpdateData` tests to check moves during - [x] ~~Moving within a reloaded section (no op)~~ can't reload sections - [x] Moving within a deleted section (no op) - [x] Moving within a moved section (convert section ops to delete+insert) - [x] Moving an index path that is also reloaded (convert to delete+insert path) - [x] Add move unit tests to `IGListAdapterUpdater` - [x] Add move unit tests to `IGListReloadDataUpdater` (mostly for code coverage...) - [x] Add move unit tests to `IGListStackedSectionController` - [x] Add `CHANGELOG.md` entry for 3.0.0 - [x] Test moving without batch Closes https://github.com/Instagram/IGListKit/pull/418 Reviewed By: jessesquires Differential Revision: D4521732 Pulled By: rnystrom fbshipit-source-id: 99a46d1cbb0cc1f857a62ff6ca257aff6e8b7f25
77 lines
3 KiB
Objective-C
77 lines
3 KiB
Objective-C
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import <IGListKit/IGListReloadDataUpdater.h>
|
|
|
|
@implementation IGListReloadDataUpdater
|
|
|
|
#pragma mark - IGListUpdatingDelegate
|
|
|
|
- (NSPointerFunctions *)objectLookupPointerFunctions {
|
|
return [NSPointerFunctions pointerFunctionsWithOptions:NSPointerFunctionsObjectPersonality];
|
|
}
|
|
|
|
- (void)performUpdateWithCollectionView:(UICollectionView *)collectionView
|
|
fromObjects:(NSArray *)fromObjects
|
|
toObjects:(NSArray *)toObjects
|
|
animated:(BOOL)animated
|
|
objectTransitionBlock:(IGListObjectTransitionBlock)objectTransitionBlock
|
|
completion:(IGListUpdatingCompletion)completion {
|
|
objectTransitionBlock(toObjects);
|
|
[self synchronousReloadDataWithCollectionView:collectionView];
|
|
if (completion) {
|
|
completion(YES);
|
|
}
|
|
}
|
|
|
|
- (void)performUpdateWithCollectionView:(UICollectionView *)collectionView
|
|
animated:(BOOL)animated
|
|
itemUpdates:(IGListItemUpdateBlock)itemUpdates
|
|
completion:(IGListUpdatingCompletion)completion {
|
|
itemUpdates();
|
|
[self synchronousReloadDataWithCollectionView:collectionView];
|
|
if (completion) {
|
|
completion(YES);
|
|
}
|
|
}
|
|
|
|
- (void)insertItemsIntoCollectionView:(UICollectionView *)collectionView indexPaths:(NSArray<NSIndexPath *> *)indexPaths {
|
|
[self synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)deleteItemsFromCollectionView:(UICollectionView *)collectionView indexPaths:(NSArray<NSIndexPath *> *)indexPaths {
|
|
[self synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)moveItemInCollectionView:(UICollectionView *)collectionView fromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
[self synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)reloadItemsInCollectionView:(UICollectionView *)collectionView indexPaths:(NSArray<NSIndexPath *> *)indexPaths {
|
|
[self synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)reloadDataWithCollectionView:(UICollectionView *)collectionView reloadUpdateBlock:(IGListReloadUpdateBlock)reloadUpdateBlock completion:(IGListUpdatingCompletion)completion {
|
|
reloadUpdateBlock();
|
|
[self synchronousReloadDataWithCollectionView:collectionView];
|
|
if (completion) {
|
|
completion(YES);
|
|
}
|
|
}
|
|
|
|
- (void)reloadCollectionView:(UICollectionView *)collectionView sections:(NSIndexSet *)sections {
|
|
[self synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)synchronousReloadDataWithCollectionView:(UICollectionView *)collectionView {
|
|
[collectionView reloadData];
|
|
[collectionView layoutIfNeeded];
|
|
}
|
|
|
|
@end
|