Fix fetching will continually trigger in a loop after reaching end of content

Don't schedule a new check for a batch fetch if no data changed previous batch fetch
This commit is contained in:
Michael Schneider
2016-04-12 17:10:22 -07:00
parent 364013a333
commit d0023a97f7
2 changed files with 22 additions and 11 deletions

View File

@@ -755,8 +755,13 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
}
}
- (void)_scheduleCheckForBatchFetching
- (void)_scheduleCheckForBatchFetchingForNumberOfChanges:(NSUInteger)changes
{
// Prevent fetching will continually trigger in a loop after reaching end of content and no new content was provided
if (changes == 0) {
return;
}
// Push this to the next runloop to be sure the scroll view has the right content size
dispatch_async(dispatch_get_main_queue(), ^{
[self _checkForBatchFetching];
@@ -973,6 +978,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
return; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
}
NSUInteger numberOfUpdateBlocks = _batchUpdateBlocks.count;
ASPerformBlockWithoutAnimation(!animated, ^{
[_layoutFacilitator collectionViewWillPerformBatchUpdates];
[super performBatchUpdates:^{
@@ -980,7 +986,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
block();
}
} completion:^(BOOL finished){
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:numberOfUpdateBlocks];
if (completion) { completion(finished); }
}];
});
@@ -1005,7 +1011,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
[_layoutFacilitator collectionViewWillEditCellsAtIndexPaths:indexPaths batched:NO];
[UIView performWithoutAnimation:^{
[super insertItemsAtIndexPaths:indexPaths];
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:indexPaths.count];
}];
}
}
@@ -1026,7 +1032,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
[_layoutFacilitator collectionViewWillEditCellsAtIndexPaths:indexPaths batched:NO];
[UIView performWithoutAnimation:^{
[super deleteItemsAtIndexPaths:indexPaths];
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:indexPaths.count];
}];
}
}
@@ -1047,7 +1053,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
[_layoutFacilitator collectionViewWillEditSectionsAtIndexSet:indexSet batched:NO];
[UIView performWithoutAnimation:^{
[super insertSections:indexSet];
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:indexSet.count];
}];
}
}
@@ -1068,7 +1074,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
[_layoutFacilitator collectionViewWillEditSectionsAtIndexSet:indexSet batched:NO];
[UIView performWithoutAnimation:^{
[super deleteSections:indexSet];
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:indexSet.count];
}];
}
}