diff --git a/AsyncDisplayKit/ASCellNode.h b/AsyncDisplayKit/ASCellNode.h index 830ed49e8f..8788d30015 100644 --- a/AsyncDisplayKit/ASCellNode.h +++ b/AsyncDisplayKit/ASCellNode.h @@ -76,8 +76,6 @@ typedef NSUInteger ASCellNodeAnimation; */ @property (nonatomic, weak) id layoutDelegate; -@property (nonatomic, assign, readonly) BOOL shouldMonitorScrollViewDidScroll; - /* * ASCellNode must forward touch events in order for UITableView and UICollectionView tap handling to work. Overriding * these methods (e.g. for highlighting) requires the super method be called. @@ -110,7 +108,8 @@ typedef NSUInteger ASCellNodeAnimation; */ - (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock; -- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame; +- (void)visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame; + @end diff --git a/AsyncDisplayKit/ASCellNode.m b/AsyncDisplayKit/ASCellNode.m index c007110680..3e1fccdbc8 100644 --- a/AsyncDisplayKit/ASCellNode.m +++ b/AsyncDisplayKit/ASCellNode.m @@ -133,7 +133,7 @@ [(_ASDisplayView *)self.view __forwardTouchesCancelled:touches withEvent:event]; } -- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame +- (void)visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame { // To be overriden by subclasses } diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index eb456bba15..bd60b03d82 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -530,7 +530,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; return cell; } -- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath +- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(_ASCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:[self scrollDirection]]; @@ -538,7 +538,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; [_asyncDelegate collectionView:self willDisplayNodeForItemAtIndexPath:indexPath]; } - ASCellNode *cellNode = [self nodeForItemAtIndexPath:indexPath]; + ASCellNode *cellNode = [cell node]; if (cellNode.neverShowPlaceholders) { [cellNode recursivelyEnsureDisplaySynchronously:YES]; } @@ -681,7 +681,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) { ASCellNode *node = [collectionCell node]; // Only nodes that respond to the selector are added to _cellsForVisibilityUpdates - [node _visibleNodeDidScroll:scrollView withCellFrame:collectionCell.frame]; + [node visibleNodeDidScroll:scrollView withCellFrame:collectionCell.frame]; } if (_asyncDelegateImplementsScrollviewDidScroll) { [_asyncDelegate scrollViewDidScroll:scrollView]; diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index bbcfb42bba..272e6c4f46 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -112,6 +112,8 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; BOOL _queuedNodeHeightUpdate; BOOL _isDeallocating; BOOL _dataSourceImplementsNodeBlockForRowAtIndexPath; + BOOL _asyncDelegateImplementsScrollviewDidScroll; + NSMutableSet *_cellsForVisibilityUpdates; } @property (atomic, assign) BOOL asyncDataSourceLocked; @@ -197,7 +199,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; if (!(self = [super initWithFrame:frame style:style])) { return nil; } - + _cellsForVisibilityUpdates = [NSMutableSet set]; if (!dataControllerClass) { dataControllerClass = [[self class] dataControllerClass]; } @@ -585,7 +587,18 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; return direction; } -- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ + for (_ASTableViewCell *tableCell in _cellsForVisibilityUpdates) { + ASCellNode *node = [tableCell node]; + [node visibleNodeDidScroll:scrollView withCellFrame:tableCell.frame]; + } + if (_asyncDelegateImplementsScrollviewDidScroll) { + [_asyncDelegate scrollViewDidScroll:scrollView]; + } +} + +- (void)tableView:(UITableView *)tableView willDisplayCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { _pendingVisibleIndexPath = indexPath; @@ -595,13 +608,17 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; [_asyncDelegate tableView:self willDisplayNodeForRowAtIndexPath:indexPath]; } - ASCellNode *cellNode = [self nodeForRowAtIndexPath:indexPath]; + ASCellNode *cellNode = [cell node]; + + if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(visibleNodeDidScroll:withCellFrame:))) { + [_cellsForVisibilityUpdates addObject:cell]; + } if (cellNode.neverShowPlaceholders) { [cellNode recursivelyEnsureDisplaySynchronously:YES]; } } -- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath +- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath { if ([_pendingVisibleIndexPath isEqual:indexPath]) { _pendingVisibleIndexPath = nil; @@ -615,6 +632,10 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; [_asyncDelegate tableView:self didEndDisplayingNode:node forRowAtIndexPath:indexPath]; } + if ([_cellsForVisibilityUpdates containsObject:cell]) { + [_cellsForVisibilityUpdates removeObject:cell]; + } + #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" if ([_asyncDelegate respondsToSelector:@selector(tableView:didEndDisplayingNodeForRowAtIndexPath:)]) { diff --git a/AsyncDisplayKit/Details/ASDelegateProxy.m b/AsyncDisplayKit/Details/ASDelegateProxy.m index baa65a65c7..3034a83d86 100644 --- a/AsyncDisplayKit/Details/ASDelegateProxy.m +++ b/AsyncDisplayKit/Details/ASDelegateProxy.m @@ -24,6 +24,9 @@ selector == @selector(numberOfSectionsInTableView:) || selector == @selector(tableView:numberOfRowsInSection:) || + // used for ASCellNode visibility + selector == @selector(scrollViewDidScroll:) || + // used for ASRangeController visibility updates selector == @selector(tableView:willDisplayCell:forRowAtIndexPath:) || selector == @selector(tableView:didEndDisplayingCell:forRowAtIndexPath:) ||