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

Commit 4a6ba27

Browse files
author
Adlai Holler
authored
ASDataController: Correctly Handle Nil IndexPath in nodeForIndexPath: Methods (#2856)
* ASDataController: Correctly handle fetching node at nil index path (return nil). * Be more aggressive, in order to avoid needlessly waiting for updates to complete
1 parent 99c5021 commit 4a6ba27

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ - (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath
612612

613613
- (NSIndexPath *)convertIndexPathFromCollectionNode:(NSIndexPath *)indexPath waitingIfNeeded:(BOOL)wait
614614
{
615+
if (indexPath == nil) {
616+
return nil;
617+
}
618+
615619
// If this is a section index path, we don't currently have a method
616620
// to do a mapping.
617621
if (indexPath.item == NSNotFound) {

AsyncDisplayKit/ASTableView.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,10 @@ - (nullable NSIndexPath *)validateIndexPath:(nullable NSIndexPath *)indexPath
591591

592592
- (nullable NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode waitingIfNeeded:(BOOL)wait
593593
{
594+
if (cellNode == nil) {
595+
return nil;
596+
}
597+
594598
NSIndexPath *indexPath = [_dataController completedIndexPathForNode:cellNode];
595599
indexPath = [self validateIndexPath:indexPath];
596600
if (indexPath == nil && wait) {

AsyncDisplayKit/Details/ASDataController.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,9 @@ - (NSUInteger)completedNumberOfRowsInSection:(NSUInteger)section
952952
- (ASCellNode *)nodeAtIndexPath:(NSIndexPath *)indexPath
953953
{
954954
ASDisplayNodeAssertMainThread();
955+
if (indexPath == nil) {
956+
return nil;
957+
}
955958

956959
NSArray *contexts = _nodeContexts[ASDataControllerRowNodeKind];
957960
NSInteger section = indexPath.section;
@@ -971,6 +974,9 @@ - (ASCellNode *)nodeAtIndexPath:(NSIndexPath *)indexPath
971974
- (ASCellNode *)nodeAtCompletedIndexPath:(NSIndexPath *)indexPath
972975
{
973976
ASDisplayNodeAssertMainThread();
977+
if (indexPath == nil) {
978+
return nil;
979+
}
974980

975981
NSArray *completedNodes = [self completedNodes];
976982
NSInteger section = indexPath.section;

0 commit comments

Comments
 (0)