Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 8043e36

Browse files
committed
Merge pull request #430 from eanagel/astableview-programmatic-scrolling-fix-v2
Bug Fix - ASTableView sometimes fails to render cell contents when scrolling programmatically.
2 parents 7e50f05 + 68e2e06 commit 8043e36

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

AsyncDisplayKit/ASTableView.mm

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)