mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +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;
|
- (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
|
@end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,7 +111,6 @@ typedef NSUInteger ASCellNodeAnimation;
|
|||||||
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
|
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
|
||||||
|
|
||||||
- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame;
|
- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#import "ASCellNode.h"
|
#import "ASCellNode.h"
|
||||||
|
|
||||||
#import "ASInternalHelpers.h"
|
#import "ASInternalHelpers.h"
|
||||||
#import "ASCollectionView.h"
|
|
||||||
#import <AsyncDisplayKit/_ASDisplayView.h>
|
#import <AsyncDisplayKit/_ASDisplayView.h>
|
||||||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
||||||
#import <AsyncDisplayKit/ASTextNode.h>
|
#import <AsyncDisplayKit/ASTextNode.h>
|
||||||
@@ -24,7 +23,6 @@
|
|||||||
UIViewController *_viewController;
|
UIViewController *_viewController;
|
||||||
ASDisplayNode *_viewControllerNode;
|
ASDisplayNode *_viewControllerNode;
|
||||||
}
|
}
|
||||||
@property (nonatomic, assign, readwrite) BOOL shouldMonitorScrollViewDidScroll;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -38,9 +36,6 @@
|
|||||||
// Use UITableViewCell defaults
|
// Use UITableViewCell defaults
|
||||||
_selectionStyle = UITableViewCellSelectionStyleDefault;
|
_selectionStyle = UITableViewCellSelectionStyleDefault;
|
||||||
self.clipsToBounds = YES;
|
self.clipsToBounds = YES;
|
||||||
if ([self.layoutDelegate respondsToSelector:@selector(visibleNodeDidScroll:inScrollView:withCellFrame:)]) {
|
|
||||||
self.shouldMonitorScrollViewDidScroll = YES;
|
|
||||||
}
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,10 +55,7 @@
|
|||||||
|
|
||||||
[self addSubnode:_viewControllerNode];
|
[self addSubnode:_viewControllerNode];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([self.layoutDelegate respondsToSelector:@selector(visibleNodeDidScroll:inScrollView:withCellFrame:)]) {
|
|
||||||
self.shouldMonitorScrollViewDidScroll = YES;
|
|
||||||
}
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,9 +135,7 @@
|
|||||||
|
|
||||||
- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame
|
- (void)_visibleNodeDidScroll:(UIScrollView *)scrollView withCellFrame:(CGRect)cellFrame
|
||||||
{
|
{
|
||||||
if (self.shouldMonitorScrollViewDidScroll) {
|
// To be overriden by subclasses
|
||||||
[self.layoutDelegate visibleNodeDidScroll:self inScrollView:scrollView withCellFrame:cellFrame];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#import "ASAssert.h"
|
#import "ASAssert.h"
|
||||||
#import "ASBatchFetching.h"
|
#import "ASBatchFetching.h"
|
||||||
#import "ASDelegateProxy.h"
|
#import "ASDelegateProxy.h"
|
||||||
|
#import "ASCellNode+Internal.h"
|
||||||
#import "ASCollectionNode.h"
|
#import "ASCollectionNode.h"
|
||||||
#import "ASCollectionDataController.h"
|
#import "ASCollectionDataController.h"
|
||||||
#import "ASCollectionViewLayoutController.h"
|
#import "ASCollectionViewLayoutController.h"
|
||||||
@@ -541,7 +542,9 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
if (cellNode.neverShowPlaceholders) {
|
if (cellNode.neverShowPlaceholders) {
|
||||||
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
||||||
}
|
}
|
||||||
[_cellsForVisibilityUpdates addObject:cell];
|
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(_visibleNodeDidScroll:withCellFrame:))) {
|
||||||
|
[_cellsForVisibilityUpdates addObject:cell];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
- (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.");
|
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]) {
|
||||||
|
[_cellsForVisibilityUpdates removeObject:cell];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||||
if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNodeForItemAtIndexPath:)]) {
|
if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNodeForItemAtIndexPath:)]) {
|
||||||
@@ -674,9 +680,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
{
|
{
|
||||||
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
|
for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
|
||||||
ASCellNode *node = [collectionCell node];
|
ASCellNode *node = [collectionCell node];
|
||||||
if (node.shouldMonitorScrollViewDidScroll) {
|
// Only nodes that respond to the selector are added to _cellsForVisibilityUpdates
|
||||||
[node _visibleNodeDidScroll:scrollView withCellFrame: node.frame];
|
[node _visibleNodeDidScroll:scrollView withCellFrame:collectionCell.frame];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (_asyncDelegateImplementsScrollviewDidScroll) {
|
if (_asyncDelegateImplementsScrollviewDidScroll) {
|
||||||
[_asyncDelegate scrollViewDidScroll:scrollView];
|
[_asyncDelegate scrollViewDidScroll:scrollView];
|
||||||
|
|||||||
Reference in New Issue
Block a user