mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-08 21:49:41 +00:00
[ASCellNode] Upgrades to ASCellNodeVisibilityEvent to ensure it is always synchronized with visibilityDidChange:
This commit is contained in:
parent
c2b0670132
commit
ff8ffffb7b
@ -32,4 +32,9 @@
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, weak) id<ASCellNodeLayoutDelegate> layoutDelegate;
|
@property (nonatomic, weak) id<ASCellNodeLayoutDelegate> layoutDelegate;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Back-pointer to the containing scrollView instance, set only for visible cells. Used for Cell Visibility Event callbacks.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, weak) UIScrollView *scrollView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -188,6 +188,20 @@
|
|||||||
// To be overriden by subclasses
|
// To be overriden by subclasses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)visibilityDidChange:(BOOL)isVisible
|
||||||
|
{
|
||||||
|
[super visibilityDidChange:isVisible];
|
||||||
|
|
||||||
|
CGRect cellFrame = CGRectZero;
|
||||||
|
if (_scrollView) {
|
||||||
|
// It is not safe to message nil with a structure return value, so ensure our _scrollView has not died.
|
||||||
|
cellFrame = [self.view convertRect:self.bounds toView:_scrollView];
|
||||||
|
}
|
||||||
|
[self cellNodeVisibilityEvent:isVisible ? ASCellNodeVisibilityEventVisible : ASCellNodeVisibilityEventInvisible
|
||||||
|
inScrollView:_scrollView
|
||||||
|
withCellFrame:cellFrame];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -532,39 +532,35 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
|
|
||||||
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(_ASCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(_ASCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
ASCellNode *cellNode = [cell node];
|
||||||
|
cellNode.scrollView = collectionView;
|
||||||
|
|
||||||
if ([_asyncDelegate respondsToSelector:@selector(collectionView:willDisplayNodeForItemAtIndexPath:)]) {
|
if ([_asyncDelegate respondsToSelector:@selector(collectionView:willDisplayNodeForItemAtIndexPath:)]) {
|
||||||
[_asyncDelegate collectionView:self willDisplayNodeForItemAtIndexPath:indexPath];
|
[_asyncDelegate collectionView:self willDisplayNodeForItemAtIndexPath:indexPath];
|
||||||
}
|
}
|
||||||
|
|
||||||
ASCellNode *cellNode = [cell node];
|
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
||||||
|
|
||||||
if (cellNode.neverShowPlaceholders) {
|
if (cellNode.neverShowPlaceholders) {
|
||||||
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
||||||
}
|
}
|
||||||
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(cellNodeVisibilityEvent:inScrollView: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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(_ASCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
||||||
|
|
||||||
|
ASCellNode *cellNode = [cell node];
|
||||||
|
|
||||||
if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNode:forItemAtIndexPath:)]) {
|
if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNode:forItemAtIndexPath:)]) {
|
||||||
ASCellNode *node = ((_ASCollectionViewCell *)cell).node;
|
ASDisplayNodeAssertNotNil(cellNode, @"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:cellNode forItemAtIndexPath:indexPath];
|
||||||
[_asyncDelegate collectionView:self didEndDisplayingNode:node forItemAtIndexPath:indexPath];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([_cellsForVisibilityUpdates containsObject:cell]) {
|
if ([_cellsForVisibilityUpdates containsObject:cell]) {
|
||||||
ASCellNode *node = ((_ASCollectionViewCell *)cell).node;
|
|
||||||
[node cellNodeVisibilityEvent:ASCellNodeVisibilityEventInvisible
|
|
||||||
inScrollView:collectionView
|
|
||||||
withCellFrame:cell.frame];
|
|
||||||
[_cellsForVisibilityUpdates removeObject:cell];
|
[_cellsForVisibilityUpdates removeObject:cell];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,6 +570,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
|||||||
[_asyncDelegate collectionView:self didEndDisplayingNodeForItemAtIndexPath:indexPath];
|
[_asyncDelegate collectionView:self didEndDisplayingNodeForItemAtIndexPath:indexPath];
|
||||||
}
|
}
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
cellNode.scrollView = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
@ -615,24 +615,23 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
- (void)tableView:(UITableView *)tableView willDisplayCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
_pendingVisibleIndexPath = indexPath;
|
_pendingVisibleIndexPath = indexPath;
|
||||||
|
|
||||||
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
ASCellNode *cellNode = [cell node];
|
||||||
|
cellNode.scrollView = tableView;
|
||||||
|
|
||||||
if ([_asyncDelegate respondsToSelector:@selector(tableView:willDisplayNodeForRowAtIndexPath:)]) {
|
if ([_asyncDelegate respondsToSelector:@selector(tableView:willDisplayNodeForRowAtIndexPath:)]) {
|
||||||
[_asyncDelegate tableView:self willDisplayNodeForRowAtIndexPath:indexPath];
|
[_asyncDelegate tableView:self willDisplayNodeForRowAtIndexPath:indexPath];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
||||||
|
|
||||||
ASCellNode *cellNode = [cell node];
|
|
||||||
|
|
||||||
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(cellNodeVisibilityEvent:inScrollView:withCellFrame:))) {
|
|
||||||
[_cellsForVisibilityUpdates addObject:cell];
|
|
||||||
[cellNode cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisible
|
|
||||||
inScrollView:tableView
|
|
||||||
withCellFrame:cell.frame];
|
|
||||||
}
|
|
||||||
if (cellNode.neverShowPlaceholders) {
|
if (cellNode.neverShowPlaceholders) {
|
||||||
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
[cellNode recursivelyEnsureDisplaySynchronously:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(cellNodeVisibilityEvent:inScrollView:withCellFrame:))) {
|
||||||
|
[_cellsForVisibilityUpdates addObject:cell];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
|
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
|
||||||
@ -640,21 +639,18 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
if ([_pendingVisibleIndexPath isEqual:indexPath]) {
|
if ([_pendingVisibleIndexPath isEqual:indexPath]) {
|
||||||
_pendingVisibleIndexPath = nil;
|
_pendingVisibleIndexPath = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASCellNode *cellNode = [cell node];
|
||||||
|
|
||||||
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
|
||||||
|
|
||||||
if ([_asyncDelegate respondsToSelector:@selector(tableView:didEndDisplayingNode:forRowAtIndexPath:)]) {
|
if ([_asyncDelegate respondsToSelector:@selector(tableView:didEndDisplayingNode:forRowAtIndexPath:)]) {
|
||||||
ASCellNode *node = ((_ASTableViewCell *)cell).node;
|
ASDisplayNodeAssertNotNil(cellNode, @"Expected node associated with removed cell not to be nil.");
|
||||||
ASDisplayNodeAssertNotNil(node, @"Expected node associated with removed cell not to be nil.");
|
[_asyncDelegate tableView:self didEndDisplayingNode:cellNode forRowAtIndexPath:indexPath];
|
||||||
[_asyncDelegate tableView:self didEndDisplayingNode:node forRowAtIndexPath:indexPath];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([_cellsForVisibilityUpdates containsObject:cell]) {
|
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
|
||||||
@ -663,6 +659,8 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
[_asyncDelegate tableView:self didEndDisplayingNodeForRowAtIndexPath:indexPath];
|
[_asyncDelegate tableView:self didEndDisplayingNodeForRowAtIndexPath:indexPath];
|
||||||
}
|
}
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
cellNode.scrollView = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,7 +90,8 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive;
|
|||||||
{
|
{
|
||||||
_scrollDirection = scrollDirection;
|
_scrollDirection = scrollDirection;
|
||||||
|
|
||||||
[self scheduleRangeUpdate];
|
// Perform update immediately, so that cells receive a visibilityDidChange: call before their first pixel is visible.
|
||||||
|
[self performRangeUpdate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode
|
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user