mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[Batch Fetching] Add ASBatchFetchingDelegate (#281)
* Add ASBatchFetchingDelegate - In addition to checking remaining leading screens, ASBatchFetching now also calculates a remaining time and consults its delegate if needed. - The delegate can override the decision of ASBatchFetching, for example based on remaining time and average time of past batch requests. * Fix up tests * Update CHANGELOG
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#import <AsyncDisplayKit/ASCollectionElement.h>
|
||||
#import <AsyncDisplayKit/ASCollectionInternal.h>
|
||||
#import <AsyncDisplayKit/ASCollectionLayout.h>
|
||||
#import <AsyncDisplayKit/ASCollectionNode+Beta.h>
|
||||
#import <AsyncDisplayKit/ASCollectionViewLayoutController.h>
|
||||
#import <AsyncDisplayKit/ASCollectionViewLayoutFacilitatorProtocol.h>
|
||||
#import <AsyncDisplayKit/ASCollectionViewFlowLayoutInspector.h>
|
||||
@@ -1347,7 +1348,7 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
|
||||
|
||||
if (targetContentOffset != NULL) {
|
||||
ASDisplayNodeAssert(_batchContext != nil, @"Batch context should exist");
|
||||
[self _beginBatchFetchingIfNeededWithContentOffset:*targetContentOffset];
|
||||
[self _beginBatchFetchingIfNeededWithContentOffset:*targetContentOffset velocity:velocity];
|
||||
}
|
||||
|
||||
if (_asyncDelegateFlags.scrollViewWillEndDragging) {
|
||||
@@ -1521,6 +1522,10 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
|
||||
}
|
||||
}
|
||||
|
||||
- (id<ASBatchFetchingDelegate>)batchFetchingDelegate{
|
||||
return self.collectionNode.batchFetchingDelegate;
|
||||
}
|
||||
|
||||
- (void)_scheduleCheckForBatchFetchingForNumberOfChanges:(NSUInteger)changes
|
||||
{
|
||||
// Prevent fetching will continually trigger in a loop after reaching end of content and no new content was provided
|
||||
@@ -1542,12 +1547,12 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
|
||||
return;
|
||||
}
|
||||
|
||||
[self _beginBatchFetchingIfNeededWithContentOffset:self.contentOffset];
|
||||
[self _beginBatchFetchingIfNeededWithContentOffset:self.contentOffset velocity:CGPointZero];
|
||||
}
|
||||
|
||||
- (void)_beginBatchFetchingIfNeededWithContentOffset:(CGPoint)contentOffset
|
||||
- (void)_beginBatchFetchingIfNeededWithContentOffset:(CGPoint)contentOffset velocity:(CGPoint)velocity
|
||||
{
|
||||
if (ASDisplayShouldFetchBatchForScrollView(self, self.scrollDirection, self.scrollableDirections, contentOffset)) {
|
||||
if (ASDisplayShouldFetchBatchForScrollView(self, self.scrollDirection, self.scrollableDirections, contentOffset, velocity)) {
|
||||
[self _beginBatchFetching];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user