mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-14 12:07:05 +08:00
Adding scrollViewWillBeginDragging and scrollViewDidEndDragging callbac to ASCellNode instances
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:) ||
|
||||
|
||||
Reference in New Issue
Block a user