@@ -124,6 +124,8 @@ @interface ASTableView () <ASRangeControllerDelegate, ASDataControllerSource> {
124124 BOOL _asyncDataFetchingEnabled;
125125
126126 ASBatchContext *_batchContext;
127+
128+ NSIndexPath *_pendingVisibleIndexPath;
127129}
128130
129131@property (atomic , assign ) BOOL asyncDataSourceLocked;
@@ -421,6 +423,8 @@ - (ASScrollDirection)scrollDirection
421423
422424- (void )tableView : (UITableView *)tableView willDisplayCell : (UITableViewCell *)cell forRowAtIndexPath : (NSIndexPath *)indexPath
423425{
426+ _pendingVisibleIndexPath = indexPath;
427+
424428 [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection: self .scrollDirection];
425429
426430 if ([_asyncDelegate respondsToSelector: @selector (tableView:willDisplayNodeForRowAtIndexPath: )]) {
@@ -430,6 +434,10 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce
430434
431435- (void )tableView : (UITableView *)tableView didEndDisplayingCell : (UITableViewCell *)cell forRowAtIndexPath : (NSIndexPath *)indexPath
432436{
437+ if ([_pendingVisibleIndexPath isEqual: indexPath]) {
438+ _pendingVisibleIndexPath = nil ;
439+ }
440+
433441 [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection: self .scrollDirection];
434442
435443 if ([_asyncDelegate respondsToSelector: @selector (tableView:didEndDisplayingNodeForRowAtIndexPath: )]) {
@@ -500,7 +508,21 @@ - (void)rangeControllerEndUpdates:(ASRangeController *)rangeController completio
500508- (NSArray *)rangeControllerVisibleNodeIndexPaths : (ASRangeController *)rangeController
501509{
502510 ASDisplayNodeAssertMainThread ();
503- return [self indexPathsForVisibleRows ];
511+
512+ NSArray *visibleIndexPaths = self.indexPathsForVisibleRows ;
513+
514+ if ( _pendingVisibleIndexPath ) {
515+ NSMutableSet *indexPaths = [NSMutableSet setWithArray: self .indexPathsForVisibleRows];
516+
517+ if ( [indexPaths containsObject: _pendingVisibleIndexPath]) {
518+ _pendingVisibleIndexPath = nil ; // once it has shown up in visibleIndexPaths, we can stop tracking it
519+ } else {
520+ [indexPaths addObject: _pendingVisibleIndexPath];
521+ visibleIndexPaths = indexPaths.allObjects ;
522+ }
523+ }
524+
525+ return visibleIndexPaths;
504526}
505527
506528- (NSArray *)rangeController : (ASRangeController *)rangeController nodesAtIndexPaths : (NSArray *)indexPaths
0 commit comments