mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Adding visibility monitoring for ASTableVieww
This commit is contained in:
@@ -76,8 +76,6 @@ typedef NSUInteger ASCellNodeAnimation;
|
||||
*/
|
||||
@property (nonatomic, weak) id<ASCellNodeLayoutDelegate> 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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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:)]) {
|
||||
|
||||
@@ -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:) ||
|
||||
|
||||
Reference in New Issue
Block a user