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

Commit 88b36f5

Browse files
author
Scott Goodson
committed
Ensure an empty array is returned if visibleNodes is called before any nodes are complete.
1 parent f6cc206 commit 88b36f5

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,19 @@ - (NSArray *)visibleNodes
391391
{
392392
NSArray *indexPaths = [self indexPathsForVisibleItems];
393393
NSMutableArray *visibleNodes = [[NSMutableArray alloc] init];
394-
395-
[indexPaths enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
396-
ASCellNode *visibleNode = [self nodeForItemAtIndexPath:obj];
397-
[visibleNodes addObject:visibleNode];
398-
}];
399-
394+
395+
for (NSIndexPath *indexPath in indexPaths) {
396+
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath];
397+
if (node) {
398+
// It is possible for UICollectionView to return indexPaths before the node is completed.
399+
[visibleNodes addObject:node];
400+
}
401+
}
402+
400403
return visibleNodes;
401404
}
402405

406+
403407
#pragma mark Assertions.
404408

405409
- (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completion:(void (^)(BOOL))completion

AsyncDisplayKit/ASTableView.mm

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,14 @@ - (NSArray *)visibleNodes
379379
NSArray *indexPaths = [self indexPathsForVisibleRows];
380380
NSMutableArray *visibleNodes = [[NSMutableArray alloc] init];
381381

382-
[indexPaths enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
383-
ASCellNode *visibleNode = [self nodeForRowAtIndexPath:obj];
384-
[visibleNodes addObject:visibleNode];
385-
}];
386-
382+
for (NSIndexPath *indexPath in indexPaths) {
383+
ASCellNode *node = [self nodeForRowAtIndexPath:indexPath];
384+
if (node) {
385+
// It is possible for UITableView to return indexPaths before the node is completed.
386+
[visibleNodes addObject:node];
387+
}
388+
}
389+
387390
return visibleNodes;
388391
}
389392

AsyncDisplayKit/Details/ASDataController.mm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,20 @@ - (NSUInteger)numberOfRowsInSection:(NSUInteger)section
902902
- (ASCellNode *)nodeAtIndexPath:(NSIndexPath *)indexPath
903903
{
904904
ASDisplayNodeAssertMainThread();
905-
return [self completedNodes][indexPath.section][indexPath.row];
905+
906+
NSArray *completedNodes = [self completedNodes];
907+
NSInteger section = indexPath.section;
908+
NSInteger row = indexPath.row;
909+
ASCellNode *node = nil;
910+
911+
if (section >= 0 && row >= 0 && section < completedNodes.count) {
912+
NSArray *completedNodesSection = completedNodes[section];
913+
if (row < completedNodesSection.count) {
914+
node = completedNodesSection[row];
915+
}
916+
}
917+
918+
return node;
906919
}
907920

908921
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode;

examples/ASTableViewStressTest/Sample.xcodeproj/project.pbxproj

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
05E2127E19D4DB510098F589 /* Frameworks */,
119119
05E2127F19D4DB510098F589 /* Resources */,
120120
F012A6F39E0149F18F564F50 /* Copy Pods Resources */,
121-
E671F9E92DFB9088485E493B /* Embed Pods Frameworks */,
122121
);
123122
buildRules = (
124123
);
@@ -190,21 +189,6 @@
190189
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
191190
showEnvVarsInLog = 0;
192191
};
193-
E671F9E92DFB9088485E493B /* Embed Pods Frameworks */ = {
194-
isa = PBXShellScriptBuildPhase;
195-
buildActionMask = 2147483647;
196-
files = (
197-
);
198-
inputPaths = (
199-
);
200-
name = "Embed Pods Frameworks";
201-
outputPaths = (
202-
);
203-
runOnlyForDeploymentPostprocessing = 0;
204-
shellPath = /bin/sh;
205-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n";
206-
showEnvVarsInLog = 0;
207-
};
208192
F012A6F39E0149F18F564F50 /* Copy Pods Resources */ = {
209193
isa = PBXShellScriptBuildPhase;
210194
buildActionMask = 2147483647;

0 commit comments

Comments
 (0)