Revert to using a single NSIndexPath for the pending visible item

This commit is contained in:
Ethan Nagel 2015-06-24 13:13:43 -07:00
parent 8bdcbe1be0
commit 0e37bff7c1

View File

@ -125,7 +125,7 @@ static BOOL _isInterceptedSelector(SEL sel)
ASBatchContext *_batchContext; ASBatchContext *_batchContext;
NSMutableSet *_pendingVisibleIndexPaths; NSIndexPath *_pendingVisibleIndexPath;
} }
@property (atomic, assign) BOOL asyncDataSourceLocked; @property (atomic, assign) BOOL asyncDataSourceLocked;
@ -174,8 +174,6 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
_leadingScreensForBatching = 1.0; _leadingScreensForBatching = 1.0;
_batchContext = [[ASBatchContext alloc] init]; _batchContext = [[ASBatchContext alloc] init];
_pendingVisibleIndexPaths = [[NSMutableSet alloc] init];
} }
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
@ -433,7 +431,7 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{ {
[_pendingVisibleIndexPaths addObject:indexPath]; _pendingVisibleIndexPath = indexPath;
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection]; [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
@ -444,8 +442,8 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{ {
if ([_pendingVisibleIndexPaths containsObject:indexPath]) { if ([_pendingVisibleIndexPath isEqual:indexPath]) {
[_pendingVisibleIndexPaths removeObject:indexPath]; _pendingVisibleIndexPath = nil;
} }
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection]; [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];
@ -519,15 +517,20 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
{ {
ASDisplayNodeAssertMainThread(); ASDisplayNodeAssertMainThread();
NSMutableSet *visibleIndexPaths = [NSMutableSet setWithArray:[self indexPathsForVisibleRows]]; NSArray *visibleIndexPaths = self.indexPathsForVisibleRows;
// First, remove any index paths we're tracking that UIKit has now proven it can remember :) if ( _pendingVisibleIndexPath ) {
[_pendingVisibleIndexPaths minusSet:visibleIndexPaths]; NSMutableSet *indexPaths = [NSMutableSet setWithArray:self.indexPathsForVisibleRows];
// Next, add all remaining index paths that we know should be visible (from willDisplayCell) but are not in the set. if ( [indexPaths containsObject:_pendingVisibleIndexPath]) {
[visibleIndexPaths unionSet:_pendingVisibleIndexPaths]; _pendingVisibleIndexPath = nil; // once it has shown up in visibleIndexPaths, we can stop tracking it
} else {
return visibleIndexPaths.allObjects; [indexPaths addObject:_pendingVisibleIndexPath];
visibleIndexPaths = indexPaths.allObjects;
}
}
return visibleIndexPaths;
} }
- (NSArray *)rangeController:(ASRangeController *)rangeController nodesAtIndexPaths:(NSArray *)indexPaths - (NSArray *)rangeController:(ASRangeController *)rangeController nodesAtIndexPaths:(NSArray *)indexPaths
@ -544,7 +547,7 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
- (void)rangeController:(ASRangeController *)rangeController didInsertNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOption:(ASDataControllerAnimationOptions)animationOption - (void)rangeController:(ASRangeController *)rangeController didInsertNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOption:(ASDataControllerAnimationOptions)animationOption
{ {
ASDisplayNodeAssertMainThread(); ASDisplayNodeAssertMainThread();
BOOL preventAnimation = animationOption == UITableViewRowAnimationNone; BOOL preventAnimation = animationOption == UITableViewRowAnimationNone;
ASPerformBlockWithoutAnimation(preventAnimation, ^{ ASPerformBlockWithoutAnimation(preventAnimation, ^{
[super insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOption]; [super insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOption];