mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
[ASDataController] Call All Completion Handlers after Nested Batch Updates (#2274)
* Add tests for batch update completion handler calling * Ensure we call all completion handlers after collection view updates * Tweak it * Fix the doc * Minor improvements * Document addCompletionHandler better
This commit is contained in:
@@ -20,6 +20,11 @@
|
||||
_ASHierarchyChangeSet *_changeSet;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
ASDisplayNodeCAssert(_changeSetBatchUpdateCounter == 0, @"ASChangeSetDataController deallocated in the middle of a batch update.");
|
||||
}
|
||||
|
||||
#pragma mark - Batching (External API)
|
||||
|
||||
- (void)beginUpdates
|
||||
@@ -40,18 +45,20 @@
|
||||
// Prevent calling endUpdatesAnimated:completion: in an unbalanced way
|
||||
NSAssert(_changeSetBatchUpdateCounter >= 0, @"endUpdatesAnimated:completion: called without having a balanced beginUpdates call");
|
||||
|
||||
[_changeSet addCompletionHandler:completion];
|
||||
if (_changeSetBatchUpdateCounter == 0) {
|
||||
[self invalidateDataSourceItemCounts];
|
||||
[_changeSet markCompletedWithNewItemCounts:[self itemCountsFromDataSource]];
|
||||
void (^batchCompletion)(BOOL finished) = _changeSet.completionHandler;
|
||||
|
||||
if (!self.initialReloadDataHasBeenCalled) {
|
||||
if (completion) {
|
||||
completion(YES);
|
||||
if (batchCompletion != nil) {
|
||||
batchCompletion(YES);
|
||||
}
|
||||
_changeSet = nil;
|
||||
return;
|
||||
}
|
||||
|
||||
[self invalidateDataSourceItemCounts];
|
||||
[_changeSet markCompletedWithNewItemCounts:[self itemCountsFromDataSource]];
|
||||
|
||||
[super beginUpdates];
|
||||
|
||||
for (_ASHierarchyItemChange *change in [_changeSet itemChangesOfType:_ASHierarchyChangeTypeDelete]) {
|
||||
@@ -70,7 +77,7 @@
|
||||
[super insertRowsAtIndexPaths:change.indexPaths withAnimationOptions:change.animationOptions];
|
||||
}
|
||||
|
||||
[super endUpdatesAnimated:animated completion:completion];
|
||||
[super endUpdatesAnimated:animated completion:batchCompletion];
|
||||
|
||||
_changeSet = nil;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user