From ab8928c140946c86eca4119b9fbb26c67866164f Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Fri, 8 Apr 2016 14:56:09 -0700 Subject: [PATCH] Consolidate methods for batch fetching in ASTableView --- AsyncDisplayKit/ASTableView.mm | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 9a6e7b771a..3fa5607371 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -700,20 +700,16 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; } -#pragma mark - -#pragma mark Batch Fetching +#pragma mark - Batch Fetching - (void)_checkForBatchFetching { // Dragging will be handled in scrollViewWillEndDragging:withVelocity:targetContentOffset: - if ([self isDragging] || [self isTracking] || ![self _shouldBatchFetch]) { + if ([self isDragging] || [self isTracking]) { return; } - // Check if we should batch fetch - if (ASDisplayShouldFetchBatchForContext(_batchContext, [self scrollableDirections], self.bounds, self.contentSize, self.contentOffset, _leadingScreensForBatching)) { - [self _beginBatchFetching]; - } + [self _beginBatchFetchingIfNeededForScrollDirection:[self scrollableDirections] contentOffset:self.contentOffset]; } - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset @@ -724,7 +720,8 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; ); if (targetContentOffset != NULL) { - [self _handleBatchFetchScrollingToOffset:*targetContentOffset]; + ASDisplayNodeAssert(_batchContext != nil, @"Batch context should exist"); + [self _beginBatchFetchingIfNeededForScrollDirection:[self scrollDirection] contentOffset:*targetContentOffset]; } if ([_asyncDelegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)]) { @@ -732,15 +729,14 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; } } -- (void)_handleBatchFetchScrollingToOffset:(CGPoint)targetOffset +- (void)_beginBatchFetchingIfNeededForScrollDirection:(ASScrollDirection)scrollDirection contentOffset:(CGPoint)contentOffset { - ASDisplayNodeAssert(_batchContext != nil, @"Batch context should exist"); - if (![self _shouldBatchFetch]) { return; } - - if (ASDisplayShouldFetchBatchForContext(_batchContext, [self scrollDirection], self.bounds, self.contentSize, targetOffset, _leadingScreensForBatching)) { + + // Check if we should batch fetch + if (ASDisplayShouldFetchBatchForContext(_batchContext, [self scrollableDirections], self.bounds, self.contentSize, self.contentOffset, _leadingScreensForBatching)) { [self _beginBatchFetching]; } }