diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 1ff6062a..a190abe0 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -142,6 +142,12 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; */ BOOL _hasEverCheckedForBatchFetchingDueToUpdate; + /** + * We want to check for batch fetching on scroll, but every tick would be too much. So check once at the + * beginning + */ + BOOL _hasCheckedForBatchFetchingOnScroll; + /** * Set during beginInteractiveMovementForItemAtIndexPath and UIGestureRecognizerStateEnded * (or UIGestureRecognizerStateFailed, UIGestureRecognizerStateCancelled. @@ -1620,7 +1626,9 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { ASInterfaceState interfaceState = [self interfaceStateForRangeController:_rangeController]; - if (ASInterfaceStateIncludesVisible(interfaceState)) { + if (ASInterfaceStateIncludesVisible(interfaceState) && !ASActivateExperimentalFeature(ASExperimentalCheckBatchFetchingOnScroll)) { + // The following call to _checkForBatchFetching is effectively a no-op, because during scrolling + // isDragging and isTracking are YES. [self _checkForBatchFetching]; } for (_ASCollectionViewCell *cell in _cellsForVisibilityUpdates) { @@ -1630,6 +1638,11 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; if (_asyncDelegateFlags.scrollViewDidScroll) { [_asyncDelegate scrollViewDidScroll:scrollView]; } + if (ASInterfaceStateIncludesVisible(interfaceState) && !_hasCheckedForBatchFetchingOnScroll && ASActivateExperimentalFeature(ASExperimentalCheckBatchFetchingOnScroll)) { + // Check after the delegate it give it a chance to turn on/off batch fetching + [self _beginBatchFetchingIfNeededWithContentOffset:self.contentOffset velocity:CGPointZero]; + _hasCheckedForBatchFetchingOnScroll = YES; + } } - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset @@ -1645,6 +1658,8 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; [self _beginBatchFetchingIfNeededWithContentOffset:*targetContentOffset velocity:velocity]; } + _hasCheckedForBatchFetchingOnScroll = NO; // reset once the scroll is done + if (_asyncDelegateFlags.scrollViewWillEndDragging) { [_asyncDelegate scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:(targetContentOffset ? : &contentOffset)]; } diff --git a/Source/ASExperimentalFeatures.h b/Source/ASExperimentalFeatures.h index 5a66c9a5..62e7cda2 100644 --- a/Source/ASExperimentalFeatures.h +++ b/Source/ASExperimentalFeatures.h @@ -34,6 +34,7 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) { ASExperimentalNoTextRendererCache = 1 << 13, // exp_no_text_renderer_cache ASExperimentalLockTextRendererCache = 1 << 14, // exp_lock_text_renderer_cache ASExperimentalHierarchyDisplayDidFinishIsRecursive = 1 << 15, // exp_hierarchy_display_did_finish_is_recursive + ASExperimentalCheckBatchFetchingOnScroll = 1 << 16, // exp_check_batch_fetching_on_scroll ASExperimentalFeatureAll = 0xFFFFFFFF }; diff --git a/Source/ASExperimentalFeatures.mm b/Source/ASExperimentalFeatures.mm index 729b1bc1..dd41e098 100644 --- a/Source/ASExperimentalFeatures.mm +++ b/Source/ASExperimentalFeatures.mm @@ -27,7 +27,8 @@ NSArray *ASExperimentalFeaturesGetNames(ASExperimentalFeatures flags @"exp_range_update_on_changeset_update", @"exp_no_text_renderer_cache", @"exp_lock_text_renderer_cache", - @"exp_hierarchy_display_did_finish_is_recursive"])); + @"exp_hierarchy_display_did_finish_is_recursive", + @"exp_check_batch_fetching_on_scroll"])); if (flags == ASExperimentalFeatureAll) { return allNames;