mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-04 11:50:38 +00:00
Remove ASTableView's pendingVisibleIndexPath system (#3125)
This commit is contained in:
parent
2785a0bcd8
commit
fad40c26c2
@ -136,8 +136,6 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
|
|
||||||
ASBatchContext *_batchContext;
|
ASBatchContext *_batchContext;
|
||||||
|
|
||||||
NSIndexPath *_pendingVisibleIndexPath;
|
|
||||||
|
|
||||||
// When we update our data controller in response to an interactive move,
|
// When we update our data controller in response to an interactive move,
|
||||||
// we don't want to tell the table view about the change (it knows!)
|
// we don't want to tell the table view about the change (it knows!)
|
||||||
BOOL _updatingInResponseToInteractiveMove;
|
BOOL _updatingInResponseToInteractiveMove;
|
||||||
@ -949,8 +947,6 @@ 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;
|
|
||||||
|
|
||||||
ASCellNode *cellNode = [cell node];
|
ASCellNode *cellNode = [cell node];
|
||||||
cellNode.scrollView = tableView;
|
cellNode.scrollView = tableView;
|
||||||
|
|
||||||
@ -977,10 +973,6 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
|
|
||||||
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
if (ASObjectIsEqual(_pendingVisibleIndexPath, indexPath)) {
|
|
||||||
_pendingVisibleIndexPath = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASCellNode *cellNode = [cell node];
|
ASCellNode *cellNode = [cell node];
|
||||||
|
|
||||||
[_rangeController setNeedsUpdate];
|
[_rangeController setNeedsUpdate];
|
||||||
@ -1377,9 +1369,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
return @[];
|
return @[];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *visibleIndexPaths = [self.indexPathsForVisibleRows mutableCopy];
|
NSArray *visibleIndexPaths = self.indexPathsForVisibleRows;
|
||||||
|
|
||||||
[visibleIndexPaths sortUsingSelector:@selector(compare:)];
|
|
||||||
|
|
||||||
// In some cases (grouped-style tables with particular geometry) indexPathsForVisibleRows will return extra index paths.
|
// In some cases (grouped-style tables with particular geometry) indexPathsForVisibleRows will return extra index paths.
|
||||||
// This is a very serious issue because we rely on the fact that any node that is marked Visible is hosted inside of a cell,
|
// This is a very serious issue because we rely on the fact that any node that is marked Visible is hosted inside of a cell,
|
||||||
@ -1388,29 +1378,11 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
// It would be possible to cache this NSPredicate as an ivar, but that would require unsafeifying self and calling @c bounds
|
// It would be possible to cache this NSPredicate as an ivar, but that would require unsafeifying self and calling @c bounds
|
||||||
// for each item. Since the performance cost is pretty small, prefer simplicity.
|
// for each item. Since the performance cost is pretty small, prefer simplicity.
|
||||||
if (self.style == UITableViewStyleGrouped && visibleIndexPaths.count != self.visibleCells.count) {
|
if (self.style == UITableViewStyleGrouped && visibleIndexPaths.count != self.visibleCells.count) {
|
||||||
[visibleIndexPaths filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSIndexPath *indexPath, NSDictionary<NSString *,id> * _Nullable bindings) {
|
visibleIndexPaths = [visibleIndexPaths filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSIndexPath *indexPath, NSDictionary<NSString *,id> * _Nullable bindings) {
|
||||||
return CGRectIntersectsRect(bounds, [self rectForRowAtIndexPath:indexPath]);
|
return CGRectIntersectsRect(bounds, [self rectForRowAtIndexPath:indexPath]);
|
||||||
}]];
|
}]];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSIndexPath *pendingVisibleIndexPath = _pendingVisibleIndexPath;
|
|
||||||
if (pendingVisibleIndexPath == nil) {
|
|
||||||
return visibleIndexPaths;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL isPendingIndexPathVisible = (NSNotFound != [visibleIndexPaths indexOfObject:pendingVisibleIndexPath inSortedRange:NSMakeRange(0, visibleIndexPaths.count) options:kNilOptions usingComparator:^(id _Nonnull obj1, id _Nonnull obj2) {
|
|
||||||
return [obj1 compare:obj2];
|
|
||||||
}]);
|
|
||||||
|
|
||||||
if (isPendingIndexPathVisible) {
|
|
||||||
_pendingVisibleIndexPath = nil; // once it has shown up in visibleIndexPaths, we can stop tracking it
|
|
||||||
} else if ([self isIndexPath:visibleIndexPaths.firstObject immediateSuccessorOfIndexPath:pendingVisibleIndexPath]) {
|
|
||||||
[visibleIndexPaths insertObject:pendingVisibleIndexPath atIndex:0];
|
|
||||||
} else if ([self isIndexPath:pendingVisibleIndexPath immediateSuccessorOfIndexPath:visibleIndexPaths.lastObject]) {
|
|
||||||
[visibleIndexPaths addObject:pendingVisibleIndexPath];
|
|
||||||
} else {
|
|
||||||
_pendingVisibleIndexPath = nil; // not contiguous, ignore.
|
|
||||||
}
|
|
||||||
return visibleIndexPaths;
|
return visibleIndexPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1835,31 +1807,6 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @note This should be a UIKit index path.
|
|
||||||
- (BOOL)isIndexPath:(NSIndexPath *)indexPath immediateSuccessorOfIndexPath:(NSIndexPath *)anchor
|
|
||||||
{
|
|
||||||
if (!anchor || !indexPath) {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
if (indexPath.section == anchor.section) {
|
|
||||||
return (indexPath.row == anchor.row+1); // assumes that indexes are valid
|
|
||||||
|
|
||||||
} else if (indexPath.section > anchor.section && indexPath.row == 0) {
|
|
||||||
if (anchor.row != [self numberOfRowsInSection:anchor.section] -1) {
|
|
||||||
return NO; // anchor is not at the end of the section
|
|
||||||
}
|
|
||||||
|
|
||||||
NSInteger nextSection = anchor.section+1;
|
|
||||||
while([self numberOfRowsInSection:nextSection] == 0) {
|
|
||||||
++nextSection;
|
|
||||||
}
|
|
||||||
|
|
||||||
return indexPath.section == nextSection;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - _ASDisplayView behavior substitutions
|
#pragma mark - _ASDisplayView behavior substitutions
|
||||||
// Need these to drive interfaceState so we know when we are visible, if not nested in another range-managing element.
|
// Need these to drive interfaceState so we know when we are visible, if not nested in another range-managing element.
|
||||||
// Because our superclass is a true UIKit class, we cannot also subclass _ASDisplayView.
|
// Because our superclass is a true UIKit class, we cannot also subclass _ASDisplayView.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user