mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-20 21:29:00 +00:00
Update ASCellNode visibility API
This commit is contained in:
parent
07ad27c7f6
commit
c64f23725f
@ -14,6 +14,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
typedef NSUInteger ASCellNodeAnimation;
|
typedef NSUInteger ASCellNodeAnimation;
|
||||||
|
|
||||||
|
typedef enum : NSUInteger {
|
||||||
|
// Indicates a cell has just became visible
|
||||||
|
ASCellNodeVisibilityEventVisible,
|
||||||
|
// Indicates a visible cell has a different visible rect. Its position, percent visible or both have changed.
|
||||||
|
ASCellNodeVisibilityEventVisibleRectChanged,
|
||||||
|
// Indicates a cell is no longer visible
|
||||||
|
ASCellNodeVisibilityEventInvisible,
|
||||||
|
} ASCellNodeVisibilityEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic cell node. Subclass this instead of `ASDisplayNode` to use with `ASTableView` and `ASCollectionView`.
|
* Generic cell node. Subclass this instead of `ASDisplayNode` to use with `ASTableView` and `ASCollectionView`.
|
||||||
*/
|
*/
|
||||||
@ -90,7 +99,7 @@ typedef NSUInteger ASCellNodeAnimation;
|
|||||||
*/
|
*/
|
||||||
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock;
|
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock;
|
||||||
|
|
||||||
- (void)visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame;
|
- (void)cellNodeVisibilityEvent:(ASCellNodeVisibilityEvent)event inScrollView:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@ -179,7 +179,9 @@
|
|||||||
[(_ASDisplayView *)self.view __forwardTouchesCancelled:touches withEvent:event];
|
[(_ASDisplayView *)self.view __forwardTouchesCancelled:touches withEvent:event];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame
|
- (void)cellNodeVisibilityEvent:(ASCellNodeVisibilityEvent)event
|
||||||
|
inScrollView:(UIScrollView *)scrollView
|
||||||
|
withCellFrame:(CGRect)cellFrame
|
||||||
{
|
{
|
||||||
// To be overriden by subclasses
|
// To be overriden by subclasses
|
||||||
}
|
}
|
||||||
|
|||||||
@ -542,8 +542,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
if (cellNode.neverShowPlaceholders) {
|
if (cellNode.neverShowPlaceholders) {
|
||||||
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
||||||
}
|
}
|
||||||
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(visibleNodeDidScroll:withCellFrame:))) {
|
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(cellNodeVisibilityEvent:inScrollView:withCellFrame:))) {
|
||||||
[_cellsForVisibilityUpdates addObject:cell];
|
[_cellsForVisibilityUpdates addObject:cell];
|
||||||
|
[cellNode cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisible
|
||||||
|
inScrollView:collectionView
|
||||||
|
withCellFrame:cell.frame];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,8 +559,14 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
ASDisplayNodeAssertNotNil(node, @"Expected node associated with removed cell not to be nil.");
|
ASDisplayNodeAssertNotNil(node, @"Expected node associated with removed cell not to be nil.");
|
||||||
[_asyncDelegate collectionView:self didEndDisplayingNode:node forItemAtIndexPath:indexPath];
|
[_asyncDelegate collectionView:self didEndDisplayingNode:node forItemAtIndexPath:indexPath];
|
||||||
}
|
}
|
||||||
[_cellsForVisibilityUpdates removeObject:cell];
|
|
||||||
|
|
||||||
|
if ([_cellsForVisibilityUpdates containsObject:cell]) {
|
||||||
|
ASCellNode *node = ((_ASCollectionViewCell *)cell).node;
|
||||||
|
[node cellNodeVisibilityEvent:ASCellNodeVisibilityEventInvisible
|
||||||
|
inScrollView:collectionView
|
||||||
|
withCellFrame:cell.frame];
|
||||||
|
[_cellsForVisibilityUpdates removeObject:cell];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||||
@ -681,9 +690,10 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||||||
{
|
{
|
||||||
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
|
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
|
||||||
ASCellNode *node = [collectionCell node];
|
|
||||||
// Only nodes that respond to the selector are added to _cellsForVisibilityUpdates
|
// Only nodes that respond to the selector are added to _cellsForVisibilityUpdates
|
||||||
[node visibleNodeDidScroll:scrollView withCellFrame:collectionCell.frame];
|
[[collectionCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisibleRectChanged
|
||||||
|
inScrollView:scrollView
|
||||||
|
withCellFrame:collectionCell.frame];
|
||||||
}
|
}
|
||||||
if (_asyncDelegateImplementsScrollviewDidScroll) {
|
if (_asyncDelegateImplementsScrollviewDidScroll) {
|
||||||
[_asyncDelegate scrollViewDidScroll:scrollView];
|
[_asyncDelegate scrollViewDidScroll:scrollView];
|
||||||
|
|||||||
@ -597,8 +597,9 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||||||
{
|
{
|
||||||
for (_ASTableViewCell *tableCell in _cellsForVisibilityUpdates) {
|
for (_ASTableViewCell *tableCell in _cellsForVisibilityUpdates) {
|
||||||
ASCellNode *node = [tableCell node];
|
[[tableCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisibleRectChanged
|
||||||
[node visibleNodeDidScroll:scrollView withCellFrame:tableCell.frame];
|
inScrollView:scrollView
|
||||||
|
withCellFrame:tableCell.frame];
|
||||||
}
|
}
|
||||||
if (_asyncDelegateImplementsScrollviewDidScroll) {
|
if (_asyncDelegateImplementsScrollviewDidScroll) {
|
||||||
[_asyncDelegate scrollViewDidScroll:scrollView];
|
[_asyncDelegate scrollViewDidScroll:scrollView];
|
||||||
@ -617,8 +618,11 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
|
|
||||||
ASCellNode *cellNode = [cell node];
|
ASCellNode *cellNode = [cell node];
|
||||||
|
|
||||||
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(visibleNodeDidScroll:withCellFrame:))) {
|
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(cellNodeVisibilityEvent:inScrollView:withCellFrame:))) {
|
||||||
[_cellsForVisibilityUpdates addObject:cell];
|
[_cellsForVisibilityUpdates addObject:cell];
|
||||||
|
[cellNode cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisible
|
||||||
|
inScrollView:tableView
|
||||||
|
withCellFrame:cell.frame];
|
||||||
}
|
}
|
||||||
if (cellNode.neverShowPlaceholders) {
|
if (cellNode.neverShowPlaceholders) {
|
||||||
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
||||||
@ -639,7 +643,13 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
[_asyncDelegate tableView:self didEndDisplayingNode:node forRowAtIndexPath:indexPath];
|
[_asyncDelegate tableView:self didEndDisplayingNode:node forRowAtIndexPath:indexPath];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ([_cellsForVisibilityUpdates containsObject:cell]) {
|
||||||
[_cellsForVisibilityUpdates removeObject:cell];
|
[_cellsForVisibilityUpdates removeObject:cell];
|
||||||
|
ASCellNode *node = ((_ASTableViewCell *)cell).node;
|
||||||
|
[node cellNodeVisibilityEvent:ASCellNodeVisibilityEventInvisible
|
||||||
|
inScrollView:tableView
|
||||||
|
withCellFrame:cell.frame];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user