mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Adding scroll visibility
This commit is contained in:
@@ -16,6 +16,7 @@ typedef NSUInteger ASCellNodeAnimation;
|
||||
|
||||
@protocol ASCellNodeLayoutDelegate <NSObject>
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView cellFrameInScrollView:(CGRect)cellFrame;
|
||||
/**
|
||||
* Notifies the delegate that the specified cell node has done a relayout.
|
||||
* The notification is done on main thread.
|
||||
@@ -24,6 +25,8 @@ typedef NSUInteger ASCellNodeAnimation;
|
||||
* @param sizeChanged `YES` if the node's `calculatedSize` changed during the relayout, `NO` otherwise.
|
||||
*/
|
||||
- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
@@ -75,6 +78,7 @@ typedef NSUInteger ASCellNodeAnimation;
|
||||
*/
|
||||
@property (nonatomic, weak) id<ASCellNodeLayoutDelegate> layoutDelegate;
|
||||
|
||||
@property (nonatomic, assign) BOOL shouldObserveVisibility;
|
||||
/*
|
||||
* 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.
|
||||
@@ -107,6 +111,7 @@ typedef NSUInteger ASCellNodeAnimation;
|
||||
*/
|
||||
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
|
||||
|
||||
- (void)updateScrollSituationWithScrollVIew:(UIScrollView *)scrollView;
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -134,6 +134,12 @@
|
||||
[(_ASDisplayView *)self.view __forwardTouchesCancelled:touches withEvent:event];
|
||||
}
|
||||
|
||||
- (void)updateScrollSituationWithScrollVIew:(UIScrollView *)scrollView
|
||||
{
|
||||
// TODO(Max): Fix the cellFrame here
|
||||
[self.layoutDelegate scrollViewDidScroll:scrollView cellFrameInScrollView:CGRectZero];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
ASRangeController *_rangeController;
|
||||
ASCollectionViewLayoutController *_layoutController;
|
||||
ASCollectionViewFlowLayoutInspector *_flowLayoutInspector;
|
||||
|
||||
NSMutableArray *_cellsForVisibilityUpdates;
|
||||
id<ASCollectionViewLayoutFacilitatorProtocol> _layoutFacilitator;
|
||||
|
||||
BOOL _performingBatchUpdates;
|
||||
@@ -212,6 +212,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
|
||||
_registeredSupplementaryKinds = [NSMutableSet set];
|
||||
|
||||
_cellsForVisibilityUpdates = [[NSMutableArray alloc] init];
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[self registerClass:[_ASCollectionViewCell class] forCellWithReuseIdentifier:kCellReuseIdentifier];
|
||||
@@ -589,6 +590,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
if (cellNode.neverShowPlaceholders) {
|
||||
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
||||
}
|
||||
[_cellsForVisibilityUpdates addObject:cell];
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
@@ -600,6 +602,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
ASDisplayNodeAssertNotNil(node, @"Expected node associated with removed cell not to be nil.");
|
||||
[_asyncDelegate collectionView:self didEndDisplayingNode:node forItemAtIndexPath:indexPath];
|
||||
}
|
||||
[_cellsForVisibilityUpdates removeObject:cell];
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNodeForItemAtIndexPath:)]) {
|
||||
@@ -650,6 +653,17 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
|
||||
for (ASCellNode *node in _cellsForVisibilityUpdates) {
|
||||
if (node.shouldObserveVisibility) {
|
||||
[node updateScrollSituationWithScrollVIew:scrollView];
|
||||
}
|
||||
}
|
||||
if ([_asyncDelegate respondsToSelector:@selector(scrollViewDidScroll:)]) {
|
||||
[_asyncDelegate scrollViewDidScroll:scrollView];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)shouldBatchFetch
|
||||
{
|
||||
// if the delegate does not respond to this method, there is no point in starting to fetch
|
||||
|
||||
@@ -56,6 +56,9 @@
|
||||
// used for batch fetching API
|
||||
selector == @selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:) ||
|
||||
|
||||
// used for ASCellNode visibility
|
||||
selector == @selector(scrollViewDidScroll:) ||
|
||||
|
||||
// intercepted due to not being supported by ASCollectionView (prevent bugs caused by usage)
|
||||
selector == @selector(collectionView:canMoveItemAtIndexPath:) ||
|
||||
selector == @selector(collectionView:moveItemAtIndexPath:toIndexPath:) ||
|
||||
|
||||
Reference in New Issue
Block a user