mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Letting ASCellNode and its subclasses handle didScroll
This commit is contained in:
15
AsyncDisplayKit/ASCellNode+Internal.h
Normal file
15
AsyncDisplayKit/ASCellNode+Internal.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// ASCellNode+Internal.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Max Gu on 2/19/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "ASCellNode.h"
|
||||
|
||||
@interface ASCellNode (Internal)
|
||||
|
||||
- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame;
|
||||
|
||||
@end
|
||||
@@ -25,15 +25,6 @@ typedef NSUInteger ASCellNodeAnimation;
|
||||
*/
|
||||
- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged;
|
||||
|
||||
@optional
|
||||
/**
|
||||
* Notifies the delegate that the specified cell node has scrolled
|
||||
*
|
||||
* @param node: A node informing the delegate about the scroll
|
||||
* @param cellFrame: The frame of the cell that has just scrolled
|
||||
*/
|
||||
- (void)visibleNodeDidScroll:(ASCellNode *)node inScrollView:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
@@ -120,7 +111,6 @@ typedef NSUInteger ASCellNodeAnimation;
|
||||
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
|
||||
|
||||
- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#import "ASCellNode.h"
|
||||
|
||||
#import "ASInternalHelpers.h"
|
||||
#import "ASCollectionView.h"
|
||||
#import <AsyncDisplayKit/_ASDisplayView.h>
|
||||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
||||
#import <AsyncDisplayKit/ASTextNode.h>
|
||||
@@ -24,7 +23,6 @@
|
||||
UIViewController *_viewController;
|
||||
ASDisplayNode *_viewControllerNode;
|
||||
}
|
||||
@property (nonatomic, assign, readwrite) BOOL shouldMonitorScrollViewDidScroll;
|
||||
|
||||
@end
|
||||
|
||||
@@ -38,9 +36,6 @@
|
||||
// Use UITableViewCell defaults
|
||||
_selectionStyle = UITableViewCellSelectionStyleDefault;
|
||||
self.clipsToBounds = YES;
|
||||
if ([self.layoutDelegate respondsToSelector:@selector(visibleNodeDidScroll:inScrollView:withCellFrame:)]) {
|
||||
self.shouldMonitorScrollViewDidScroll = YES;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -61,9 +56,6 @@
|
||||
[self addSubnode:_viewControllerNode];
|
||||
}
|
||||
|
||||
if ([self.layoutDelegate respondsToSelector:@selector(visibleNodeDidScroll:inScrollView:withCellFrame:)]) {
|
||||
self.shouldMonitorScrollViewDidScroll = YES;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -143,9 +135,7 @@
|
||||
|
||||
- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame
|
||||
{
|
||||
if (self.shouldMonitorScrollViewDidScroll) {
|
||||
[self.layoutDelegate visibleNodeDidScroll:self inScrollView:scrollView withCellFrame:cellFrame];
|
||||
}
|
||||
// To be overriden by subclasses
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#import "ASAssert.h"
|
||||
#import "ASBatchFetching.h"
|
||||
#import "ASDelegateProxy.h"
|
||||
#import "ASCellNode+Internal.h"
|
||||
#import "ASCollectionNode.h"
|
||||
#import "ASCollectionDataController.h"
|
||||
#import "ASCollectionViewLayoutController.h"
|
||||
@@ -541,7 +542,9 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
if (cellNode.neverShowPlaceholders) {
|
||||
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
||||
}
|
||||
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(_visibleNodeDidScroll:withCellFrame:))) {
|
||||
[_cellsForVisibilityUpdates addObject:cell];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
@@ -553,7 +556,10 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
ASDisplayNodeAssertNotNil(node, @"Expected node associated with removed cell not to be nil.");
|
||||
[_asyncDelegate collectionView:self didEndDisplayingNode:node forItemAtIndexPath:indexPath];
|
||||
}
|
||||
if ([_cellsForVisibilityUpdates containsObject:cell]) {
|
||||
[_cellsForVisibilityUpdates removeObject:cell];
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNodeForItemAtIndexPath:)]) {
|
||||
@@ -674,9 +680,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
{
|
||||
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
|
||||
ASCellNode *node = [collectionCell node];
|
||||
if (node.shouldMonitorScrollViewDidScroll) {
|
||||
[node _visibleNodeDidScroll:scrollView withCellFrame: node.frame];
|
||||
}
|
||||
// Only nodes that respond to the selector are added to _cellsForVisibilityUpdates
|
||||
[node _visibleNodeDidScroll:scrollView withCellFrame:collectionCell.frame];
|
||||
}
|
||||
if (_asyncDelegateImplementsScrollviewDidScroll) {
|
||||
[_asyncDelegate scrollViewDidScroll:scrollView];
|
||||
|
||||
Reference in New Issue
Block a user