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

Commit 87575b7

Browse files
committed
[ASCellNode] Adding support for scroll view begin / end drag to VisibilityEvent changes.
1 parent 783011b commit 87575b7

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ @interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDe
133133

134134
struct {
135135
unsigned int asyncDelegateScrollViewDidScroll:1;
136+
unsigned int asyncDelegateScrollViewWillBeginDragging:1;
137+
unsigned int asyncDelegateScrollViewDidEndDragging:1;
136138
unsigned int asyncDelegateScrollViewWillEndDraggingWithVelocityTargetContentOffset:1;
137139
unsigned int asyncDelegateCollectionViewWillDisplayNodeForItemAtIndexPath:1;
138140
unsigned int asyncDelegateCollectionViewDidEndDisplayingNodeForItemAtIndexPath:1;
@@ -396,6 +398,8 @@ - (void)setAsyncDelegate:(id<ASCollectionViewDelegate>)asyncDelegate
396398
_asyncDelegateFlags.asyncDelegateCollectionViewDidEndDisplayingNodeForItemAtIndexPath = [_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNode:forItemAtIndexPath:)];
397399
_asyncDelegateFlags.asyncDelegateCollectionViewWillBeginBatchFetchWithContext = [_asyncDelegate respondsToSelector:@selector(collectionView:willBeginBatchFetchWithContext:)];
398400
_asyncDelegateFlags.asyncDelegateShouldBatchFetchForCollectionView = [_asyncDelegate respondsToSelector:@selector(shouldBatchFetchForCollectionView:)];
401+
_asyncDelegateFlags.asyncDelegateScrollViewWillBeginDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewWillBeginDragging:)];
402+
_asyncDelegateFlags.asyncDelegateScrollViewDidEndDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)];
399403
}
400404

401405
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
@@ -672,6 +676,29 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
672676
}
673677
}
674678

679+
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
680+
{
681+
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
682+
[[collectionCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventWillBeginDragging
683+
inScrollView:scrollView
684+
withCellFrame:collectionCell.frame];
685+
}
686+
if (_asyncDelegateFlags.asyncDelegateScrollViewWillBeginDragging) {
687+
[_asyncDelegate scrollViewWillBeginDragging:scrollView];
688+
}
689+
}
690+
691+
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
692+
{
693+
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
694+
[[collectionCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventDidEndDragging
695+
inScrollView:scrollView
696+
withCellFrame:collectionCell.frame];
697+
}
698+
if (_asyncDelegateFlags.asyncDelegateScrollViewDidEndDragging) {
699+
[_asyncDelegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
700+
}
701+
}
675702

676703
#pragma mark - Scroll Direction.
677704

AsyncDisplayKit/ASTableView.mm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ @interface ASTableView () <ASRangeControllerDataSource, ASRangeControllerDelegat
117117

118118
struct {
119119
unsigned int asyncDelegateScrollViewDidScroll:1;
120+
unsigned int asyncDelegateScrollViewWillBeginDragging:1;
121+
unsigned int asyncDelegateScrollViewDidEndDragging:1;
120122
unsigned int asyncDelegateTableViewWillDisplayNodeForRowAtIndexPath:1;
121123
unsigned int asyncDelegateTableViewDidEndDisplayingNodeForRowAtIndexPath:1;
122124
unsigned int asyncDelegateTableViewDidEndDisplayingNodeForRowAtIndexPathDeprecated:1;
@@ -320,6 +322,8 @@ - (void)setAsyncDelegate:(id<ASTableViewDelegate>)asyncDelegate
320322
_asyncDelegateFlags.asyncDelegateScrollViewWillEndDraggingWithVelocityTargetContentOffset = [_asyncDelegate respondsToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)];
321323
_asyncDelegateFlags.asyncDelegateTableViewWillBeginBatchFetchWithContext = [_asyncDelegate respondsToSelector:@selector(tableView:willBeginBatchFetchWithContext:)];
322324
_asyncDelegateFlags.asyncDelegateShouldBatchFetchForTableView = [_asyncDelegate respondsToSelector:@selector(shouldBatchFetchForTableView:)];
325+
_asyncDelegateFlags.asyncDelegateScrollViewWillBeginDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewWillBeginDragging:)];
326+
_asyncDelegateFlags.asyncDelegateScrollViewDidEndDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)];
323327
}
324328

325329
super.delegate = (id<UITableViewDelegate>)_proxyDelegate;
@@ -697,6 +701,29 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
697701
}
698702
}
699703

704+
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
705+
{
706+
for (_ASTableViewCell *tableViewCell in _cellsForVisibilityUpdates) {
707+
[[tableViewCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventWillBeginDragging
708+
inScrollView:scrollView
709+
withCellFrame:tableViewCell.frame];
710+
}
711+
if (_asyncDelegateFlags.asyncDelegateScrollViewWillBeginDragging) {
712+
[_asyncDelegate scrollViewWillBeginDragging:scrollView];
713+
}
714+
}
715+
716+
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
717+
{
718+
for (_ASTableViewCell *tableViewCell in _cellsForVisibilityUpdates) {
719+
[[tableViewCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventDidEndDragging
720+
inScrollView:scrollView
721+
withCellFrame:tableViewCell.frame];
722+
}
723+
if (_asyncDelegateFlags.asyncDelegateScrollViewDidEndDragging) {
724+
[_asyncDelegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
725+
}
726+
}
700727

701728
#pragma mark - Scroll Direction
702729

AsyncDisplayKit/Details/ASDelegateProxy.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ - (BOOL)interceptsSelector:(SEL)selector
2626

2727
// used for ASCellNode visibility
2828
selector == @selector(scrollViewDidScroll:) ||
29+
30+
// used for ASCellNode user interaction
31+
selector == @selector(scrollViewWillBeginDragging:) ||
32+
selector == @selector(scrollViewDidEndDragging:willDecelerate:) ||
2933

3034
// used for ASRangeController visibility updates
3135
selector == @selector(tableView:willDisplayCell:forRowAtIndexPath:) ||
@@ -61,6 +65,10 @@ - (BOOL)interceptsSelector:(SEL)selector
6165

6266
// used for ASCellNode visibility
6367
selector == @selector(scrollViewDidScroll:) ||
68+
69+
// used for ASCellNode user interaction
70+
selector == @selector(scrollViewWillBeginDragging:) ||
71+
selector == @selector(scrollViewDidEndDragging:willDecelerate:) ||
6472

6573
// intercepted due to not being supported by ASCollectionView (prevent bugs caused by usage)
6674
selector == @selector(collectionView:canMoveItemAtIndexPath:) ||

0 commit comments

Comments
 (0)