mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-06 15:08:50 +00:00
Summary: Adding a fix to the `IGListAdapterUpdater` that requests the `UICollectionView` to perform updates on until just-before we update. This way if the `UICollectionView` is changed between update-queue and execution (b/c updates are async), we guarantee the update is performed on the correct view. See the accompanying unit test that fails w/out the fix enabled. Differential Revision: D7889908 fbshipit-source-id: 7178677f34951a1e42986b0289fc4abc708d6946
86 lines
3.5 KiB
Objective-C
86 lines
3.5 KiB
Objective-C
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <IGListKit/IGListReloadDataUpdater.h>
|
|
|
|
@implementation IGListReloadDataUpdater
|
|
|
|
#pragma mark - IGListUpdatingDelegate
|
|
|
|
- (NSPointerFunctions *)objectLookupPointerFunctions {
|
|
return [NSPointerFunctions pointerFunctionsWithOptions:NSPointerFunctionsObjectPersonality];
|
|
}
|
|
|
|
- (void)performUpdateWithCollectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
|
|
fromObjects:(NSArray *)fromObjects
|
|
toObjectsBlock:(IGListToObjectBlock)toObjectsBlock
|
|
animated:(BOOL)animated
|
|
objectTransitionBlock:(IGListObjectTransitionBlock)objectTransitionBlock
|
|
completion:(IGListUpdatingCompletion)completion {
|
|
if (toObjectsBlock != nil) {
|
|
NSArray *toObjects = toObjectsBlock() ?: @[];
|
|
objectTransitionBlock(toObjects);
|
|
}
|
|
[self _synchronousReloadDataWithCollectionView:collectionViewBlock()];
|
|
if (completion) {
|
|
completion(YES);
|
|
}
|
|
}
|
|
|
|
- (void)performUpdateWithCollectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock
|
|
animated:(BOOL)animated
|
|
itemUpdates:(IGListItemUpdateBlock)itemUpdates
|
|
completion:(IGListUpdatingCompletion)completion {
|
|
itemUpdates();
|
|
[self _synchronousReloadDataWithCollectionView:collectionViewBlock()];
|
|
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)reloadItemInCollectionView:(UICollectionView *)collectionView fromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
[self _synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)_reloadItemsInCollectionView:(UICollectionView *)collectionView indexPaths:(NSArray<NSIndexPath *> *)indexPaths {
|
|
[self _synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)moveSectionInCollectionView:(UICollectionView *)collectionView fromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
|
|
[self _synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)reloadDataWithCollectionViewBlock:(IGListCollectionViewBlock)collectionViewBlock reloadUpdateBlock:(IGListReloadUpdateBlock)reloadUpdateBlock completion:(IGListUpdatingCompletion)completion {
|
|
reloadUpdateBlock();
|
|
[self _synchronousReloadDataWithCollectionView:collectionViewBlock()];
|
|
if (completion) {
|
|
completion(YES);
|
|
}
|
|
}
|
|
|
|
- (void)reloadCollectionView:(UICollectionView *)collectionView sections:(NSIndexSet *)sections {
|
|
[self _synchronousReloadDataWithCollectionView:collectionView];
|
|
}
|
|
|
|
- (void)_synchronousReloadDataWithCollectionView:(UICollectionView *)collectionView {
|
|
[collectionView reloadData];
|
|
[collectionView layoutIfNeeded];
|
|
}
|
|
|
|
@end
|