Move most of the batch fetching logic to a central place for ASTableView and ASCollectionView usage

This commit is contained in:
Michael Schneider
2016-04-08 19:42:14 -07:00
parent 40fe1f3ac7
commit 24ca09ee6c
4 changed files with 219 additions and 199 deletions

View File

@@ -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;
}