From 0e37bff7c1930dced2c4ebc8e07ffeb45c4cebce Mon Sep 17 00:00:00 2001 From: Ethan Nagel Date: Wed, 24 Jun 2015 13:13:43 -0700 Subject: [PATCH] Revert to using a single NSIndexPath for the pending visible item --- AsyncDisplayKit/ASTableView.mm | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 080fe4f570..2288958d3c 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -125,7 +125,7 @@ static BOOL _isInterceptedSelector(SEL sel) ASBatchContext *_batchContext; - NSMutableSet *_pendingVisibleIndexPaths; + NSIndexPath *_pendingVisibleIndexPath; } @property (atomic, assign) BOOL asyncDataSourceLocked; @@ -174,8 +174,6 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) { _leadingScreensForBatching = 1.0; _batchContext = [[ASBatchContext alloc] init]; - - _pendingVisibleIndexPaths = [[NSMutableSet alloc] init]; } - (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 { - [_pendingVisibleIndexPaths addObject:indexPath]; + _pendingVisibleIndexPath = indexPath; [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection]; @@ -444,8 +442,8 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) { - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath { - if ([_pendingVisibleIndexPaths containsObject:indexPath]) { - [_pendingVisibleIndexPaths removeObject:indexPath]; + if ([_pendingVisibleIndexPath isEqual:indexPath]) { + _pendingVisibleIndexPath = nil; } [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection]; @@ -519,15 +517,20 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) { { ASDisplayNodeAssertMainThread(); - NSMutableSet *visibleIndexPaths = [NSMutableSet setWithArray:[self indexPathsForVisibleRows]]; - - // First, remove any index paths we're tracking that UIKit has now proven it can remember :) - [_pendingVisibleIndexPaths minusSet:visibleIndexPaths]; - - // Next, add all remaining index paths that we know should be visible (from willDisplayCell) but are not in the set. - [visibleIndexPaths unionSet:_pendingVisibleIndexPaths]; - - return visibleIndexPaths.allObjects; + NSArray *visibleIndexPaths = self.indexPathsForVisibleRows; + + if ( _pendingVisibleIndexPath ) { + NSMutableSet *indexPaths = [NSMutableSet setWithArray:self.indexPathsForVisibleRows]; + + if ( [indexPaths containsObject:_pendingVisibleIndexPath]) { + _pendingVisibleIndexPath = nil; // once it has shown up in visibleIndexPaths, we can stop tracking it + } else { + [indexPaths addObject:_pendingVisibleIndexPath]; + visibleIndexPaths = indexPaths.allObjects; + } + } + + return visibleIndexPaths; } - (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 { ASDisplayNodeAssertMainThread(); - + BOOL preventAnimation = animationOption == UITableViewRowAnimationNone; ASPerformBlockWithoutAnimation(preventAnimation, ^{ [super insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOption];