mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Move most of the batch fetching logic to a central place for ASTableView and ASCollectionView usage
This commit is contained in:
@@ -8,23 +8,31 @@
|
||||
|
||||
#import "ASBatchFetching.h"
|
||||
|
||||
BOOL ASDisplayShouldFetchBatchForContext(ASBatchContext *context,
|
||||
ASScrollDirection scrollDirection,
|
||||
CGRect bounds,
|
||||
CGSize contentSize,
|
||||
CGPoint targetOffset,
|
||||
CGFloat leadingScreens) {
|
||||
// do not allow fetching if a batch is already in-flight and hasn't been completed or cancelled
|
||||
BOOL ASDisplayShouldFetchBatchForScrollView(UIScrollView<ASBatchFetchingScrollView> *scrollView, ASScrollDirection scrollDirection, CGPoint contentOffset)
|
||||
{
|
||||
|
||||
// Don't fetch if the scroll view does not allow
|
||||
if (![scrollView canBatchFetch]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Check if we should batch fetch
|
||||
ASBatchContext *context = scrollView.batchContext;
|
||||
CGRect bounds = scrollView.bounds;
|
||||
CGSize contentSize = scrollView.contentSize;
|
||||
CGFloat leadingScreens = scrollView.leadingScreensForBatching;
|
||||
|
||||
// Do not allow fetching if a batch is already in-flight and hasn't been completed or cancelled
|
||||
if ([context isFetching]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
// only Down and Right scrolls are currently supported (tail loading)
|
||||
// Only Down and Right scrolls are currently supported (tail loading)
|
||||
if (!ASScrollDirectionContainsDown(scrollDirection) && !ASScrollDirectionContainsRight(scrollDirection)) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
// no fetching for null states
|
||||
// No fetching for null states
|
||||
if (leadingScreens <= 0.0 || CGRectEqualToRect(bounds, CGRectZero)) {
|
||||
return NO;
|
||||
}
|
||||
@@ -33,11 +41,11 @@ BOOL ASDisplayShouldFetchBatchForContext(ASBatchContext *context,
|
||||
|
||||
if (ASScrollDirectionContainsDown(scrollDirection)) {
|
||||
viewLength = bounds.size.height;
|
||||
offset = targetOffset.y;
|
||||
offset = contentOffset.y;
|
||||
contentLength = contentSize.height;
|
||||
} else { // horizontal / right
|
||||
viewLength = bounds.size.width;
|
||||
offset = targetOffset.x;
|
||||
offset = contentOffset.x;
|
||||
contentLength = contentSize.width;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user