Remove ASTableView's pendingVisibleIndexPath system (#3125)

This commit is contained in:
Adlai Holler 2017-03-04 12:52:28 -08:00 committed by GitHub
parent 2785a0bcd8
commit fad40c26c2

View File

@ -136,8 +136,6 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
ASBatchContext *_batchContext;
NSIndexPath *_pendingVisibleIndexPath;
// 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!)
BOOL _updatingInResponseToInteractiveMove;
@ -949,8 +947,6 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
- (void)tableView:(UITableView *)tableView willDisplayCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
_pendingVisibleIndexPath = indexPath;
ASCellNode *cellNode = [cell node];
cellNode.scrollView = tableView;
@ -977,10 +973,6 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (ASObjectIsEqual(_pendingVisibleIndexPath, indexPath)) {
_pendingVisibleIndexPath = nil;
}
ASCellNode *cellNode = [cell node];
[_rangeController setNeedsUpdate];
@ -1377,9 +1369,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
return @[];
}
NSMutableArray *visibleIndexPaths = [self.indexPathsForVisibleRows mutableCopy];
[visibleIndexPaths sortUsingSelector:@selector(compare:)];
NSArray *visibleIndexPaths = self.indexPathsForVisibleRows;
// 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,
@ -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
// for each item. Since the performance cost is pretty small, prefer simplicity.
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]);
}]];
}
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;
}
@ -1835,31 +1807,6 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
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
// 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.