Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Fix failing batch fetch in some cases. (#3242)
Browse files Browse the repository at this point in the history
* Fixed failed batch fetch caused by _deceleratingVelocity

* Fixed indentation
  • Loading branch information
hebertialmeida authored and Adlai Holler committed Apr 10, 2017
1 parent b41816d commit 582bca9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Source/ASCollectionView.mm
Expand Up @@ -145,6 +145,7 @@ @interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDe
unsigned int scrollViewWillBeginDragging:1;
unsigned int scrollViewDidEndDragging:1;
unsigned int scrollViewWillEndDragging:1;
unsigned int scrollViewDidEndDecelerating:1;
unsigned int collectionViewWillDisplayNodeForItem:1;
unsigned int collectionViewWillDisplayNodeForItemDeprecated:1;
unsigned int collectionViewDidEndDisplayingNodeForItem:1;
Expand Down Expand Up @@ -481,6 +482,7 @@ - (void)setAsyncDelegate:(id<ASCollectionDelegate>)asyncDelegate

_asyncDelegateFlags.scrollViewDidScroll = [_asyncDelegate respondsToSelector:@selector(scrollViewDidScroll:)];
_asyncDelegateFlags.scrollViewWillEndDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)];
_asyncDelegateFlags.scrollViewDidEndDecelerating = [_asyncDelegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)];
_asyncDelegateFlags.scrollViewWillBeginDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewWillBeginDragging:)];
_asyncDelegateFlags.scrollViewDidEndDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)];
_asyncDelegateFlags.collectionViewWillDisplayNodeForItem = [_asyncDelegate respondsToSelector:@selector(collectionView:willDisplayNode:forItemAtIndexPath:)];
Expand Down Expand Up @@ -1318,6 +1320,15 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
}
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_deceleratingVelocity = CGPointZero;

if (_asyncDelegateFlags.scrollViewDidEndDecelerating) {
[_asyncDelegate scrollViewDidEndDecelerating:scrollView];
}
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
Expand Down
11 changes: 11 additions & 0 deletions Source/ASTableView.mm
Expand Up @@ -181,6 +181,7 @@ @interface ASTableView () <ASRangeControllerDataSource, ASRangeControllerDelegat
unsigned int scrollViewWillBeginDragging:1;
unsigned int scrollViewDidEndDragging:1;
unsigned int scrollViewWillEndDragging:1;
unsigned int scrollViewDidEndDecelerating:1;
unsigned int tableNodeWillDisplayNodeForRow:1;
unsigned int tableViewWillDisplayNodeForRow:1;
unsigned int tableViewWillDisplayNodeForRowDeprecated:1;
Expand Down Expand Up @@ -431,6 +432,7 @@ - (void)setAsyncDelegate:(id<ASTableDelegate>)asyncDelegate
_asyncDelegateFlags.tableViewDidEndDisplayingNodeForRow = [_asyncDelegate respondsToSelector:@selector(tableView:didEndDisplayingNode:forRowAtIndexPath:)];
_asyncDelegateFlags.tableNodeDidEndDisplayingNodeForRow = [_asyncDelegate respondsToSelector:@selector(tableNode:didEndDisplayingRowWithNode:)];
_asyncDelegateFlags.scrollViewWillEndDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)];
_asyncDelegateFlags.scrollViewDidEndDecelerating = [_asyncDelegate respondsToSelector:@selector(scrollViewDidEndDecelerating:)];
_asyncDelegateFlags.tableViewWillBeginBatchFetch = [_asyncDelegate respondsToSelector:@selector(tableView:willBeginBatchFetchWithContext:)];
_asyncDelegateFlags.tableNodeWillBeginBatchFetch = [_asyncDelegate respondsToSelector:@selector(tableNode:willBeginBatchFetchWithContext:)];
_asyncDelegateFlags.shouldBatchFetchForTableView = [_asyncDelegate respondsToSelector:@selector(shouldBatchFetchForTableView:)];
Expand Down Expand Up @@ -1199,6 +1201,15 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
}
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_deceleratingVelocity = CGPointZero;

if (_asyncDelegateFlags.scrollViewDidEndDecelerating) {
[_asyncDelegate scrollViewDidEndDecelerating:scrollView];
}
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
for (_ASTableViewCell *tableViewCell in _cellsForVisibilityUpdates) {
Expand Down
4 changes: 3 additions & 1 deletion Source/Details/ASDelegateProxy.m
Expand Up @@ -54,7 +54,8 @@ - (BOOL)interceptsSelector:(SEL)selector
selector == @selector(tableView:didEndDisplayingCell:forRowAtIndexPath:) ||

// used for batch fetching API
selector == @selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)
selector == @selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:) ||
selector == @selector(scrollViewDidEndDecelerating:)
);
}

Expand Down Expand Up @@ -96,6 +97,7 @@ - (BOOL)interceptsSelector:(SEL)selector

// used for batch fetching API
selector == @selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:) ||
selector == @selector(scrollViewDidEndDecelerating:) ||

// used for ASCellNode visibility
selector == @selector(scrollViewDidScroll:) ||
Expand Down

0 comments on commit 582bca9

Please sign in to comment.