Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ @interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDe
*/
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.
Expand Down Expand Up @@ -1620,7 +1626,9 @@ - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(N
- (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) {
Expand All @@ -1630,6 +1638,11 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
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
Expand All @@ -1645,6 +1658,8 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
[self _beginBatchFetchingIfNeededWithContentOffset:*targetContentOffset velocity:velocity];
}

_hasCheckedForBatchFetchingOnScroll = NO; // reset once the scroll is done

if (_asyncDelegateFlags.scrollViewWillEndDragging) {
[_asyncDelegate scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:(targetContentOffset ? : &contentOffset)];
}
Expand Down
1 change: 1 addition & 0 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
3 changes: 2 additions & 1 deletion Source/ASExperimentalFeatures.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
@"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;
Expand Down