Adding scrollViewWillBeginDragging and scrollViewDidEndDragging callbac to ASCellNode instances

This commit is contained in:
Max Gu
2016-03-24 14:50:08 -07:00
parent eed812dcdf
commit 1fba62da0e
3 changed files with 46 additions and 0 deletions

View File

@@ -30,6 +30,14 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
* Indicates a cell is no longer visible
*/
ASCellNodeVisibilityEventInvisible,
/**
* Indicates user has started dragging the visible cell
*/
ASCellNodeVisibilityEventWillBeginDragging,
/**
* Indicates user has ended dragging the visible cell
*/
ASCellNodeVisibilityEventDidEndDragging,
};
/**

View File

@@ -107,6 +107,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
BOOL _asyncDataFetchingEnabled;
BOOL _asyncDelegateImplementsScrollviewDidScroll;
BOOL _asyncDelegateImplementsWillBeginDragging;
BOOL _asyncDelegateImplementsDidEndDragging;
BOOL _asyncDataSourceImplementsConstrainedSizeForNode;
BOOL _asyncDataSourceImplementsNodeBlockForItemAtIndexPath;
_ASCollectionViewNodeSizeInvalidationContext *_queuedNodeSizeInvalidationContext; // Main thread only
@@ -364,10 +366,14 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
_asyncDelegate = nil;
_proxyDelegate = _isDeallocating ? nil : [[ASCollectionViewProxy alloc] initWithTarget:nil interceptor:self];
_asyncDelegateImplementsScrollviewDidScroll = NO;
_asyncDelegateImplementsWillBeginDragging = NO;
_asyncDelegateImplementsDidEndDragging = NO;
} else {
_asyncDelegate = asyncDelegate;
_proxyDelegate = [[ASCollectionViewProxy alloc] initWithTarget:_asyncDelegate interceptor:self];
_asyncDelegateImplementsScrollviewDidScroll = ([_asyncDelegate respondsToSelector:@selector(scrollViewDidScroll:)] ? 1 : 0);
_asyncDelegateImplementsWillBeginDragging = ([_asyncDelegate respondsToSelector:@selector(scrollViewWillBeginDragging:)] ? 1 : 0);
_asyncDelegateImplementsDidEndDragging = ([_asyncDelegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)] ? 1 : 0);
}
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
@@ -738,6 +744,30 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
[[collectionCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventWillBeginDragging
inScrollView:scrollView
withCellFrame:collectionCell.frame];
}
if (_asyncDelegateImplementsWillBeginDragging) {
[_asyncDelegate scrollViewWillBeginDragging:scrollView];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
[[collectionCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventDidEndDragging
inScrollView:scrollView
withCellFrame:collectionCell.frame];
}
if (_asyncDelegateImplementsDidEndDragging) {
[_asyncDelegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
}
}
- (BOOL)shouldBatchFetch
{
// if the delegate does not respond to this method, there is no point in starting to fetch

View File

@@ -27,6 +27,10 @@
// used for ASCellNode visibility
selector == @selector(scrollViewDidScroll:) ||
// used for ASCellNode user interaction
selector == @selector(scrollViewWillBeginDragging:) ||
selector == @selector(scrollViewDidEndDragging:willDecelerate:) ||
// used for ASRangeController visibility updates
selector == @selector(tableView:willDisplayCell:forRowAtIndexPath:) ||
selector == @selector(tableView:didEndDisplayingCell:forRowAtIndexPath:) ||
@@ -62,6 +66,10 @@
// used for ASCellNode visibility
selector == @selector(scrollViewDidScroll:) ||
// used for ASCellNode user interaction
selector == @selector(scrollViewWillBeginDragging:) ||
selector == @selector(scrollViewDidEndDragging:willDecelerate:) ||
// intercepted due to not being supported by ASCollectionView (prevent bugs caused by usage)
selector == @selector(collectionView:canMoveItemAtIndexPath:) ||
selector == @selector(collectionView:moveItemAtIndexPath:toIndexPath:) ||