Merge pull request #919 from facebook/ASDataControllerVisibleNodes

[ASDataController] Ensure an empty array is returned if visibleNodes is called before any nodes are complete.
This commit is contained in:
appleguy
2015-12-06 22:01:27 -08:00
4 changed files with 32 additions and 28 deletions

View File

@@ -391,15 +391,19 @@ static BOOL _isInterceptedSelector(SEL sel)
{
NSArray *indexPaths = [self indexPathsForVisibleItems];
NSMutableArray *visibleNodes = [[NSMutableArray alloc] init];
[indexPaths enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
ASCellNode *visibleNode = [self nodeForItemAtIndexPath:obj];
[visibleNodes addObject:visibleNode];
}];
for (NSIndexPath *indexPath in indexPaths) {
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath];
if (node) {
// It is possible for UICollectionView to return indexPaths before the node is completed.
[visibleNodes addObject:node];
}
}
return visibleNodes;
}
#pragma mark Assertions.
- (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completion:(void (^)(BOOL))completion

View File

@@ -379,11 +379,14 @@ static BOOL _isInterceptedSelector(SEL sel)
NSArray *indexPaths = [self indexPathsForVisibleRows];
NSMutableArray *visibleNodes = [[NSMutableArray alloc] init];
[indexPaths enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
ASCellNode *visibleNode = [self nodeForRowAtIndexPath:obj];
[visibleNodes addObject:visibleNode];
}];
for (NSIndexPath *indexPath in indexPaths) {
ASCellNode *node = [self nodeForRowAtIndexPath:indexPath];
if (node) {
// It is possible for UITableView to return indexPaths before the node is completed.
[visibleNodes addObject:node];
}
}
return visibleNodes;
}

View File

@@ -902,7 +902,20 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
- (ASCellNode *)nodeAtIndexPath:(NSIndexPath *)indexPath
{
ASDisplayNodeAssertMainThread();
return [self completedNodes][indexPath.section][indexPath.row];
NSArray *completedNodes = [self completedNodes];
NSInteger section = indexPath.section;
NSInteger row = indexPath.row;
ASCellNode *node = nil;
if (section >= 0 && row >= 0 && section < completedNodes.count) {
NSArray *completedNodesSection = completedNodes[section];
if (row < completedNodesSection.count) {
node = completedNodesSection[row];
}
}
return node;
}
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode;

View File

@@ -118,7 +118,6 @@
05E2127E19D4DB510098F589 /* Frameworks */,
05E2127F19D4DB510098F589 /* Resources */,
F012A6F39E0149F18F564F50 /* Copy Pods Resources */,
E671F9E92DFB9088485E493B /* Embed Pods Frameworks */,
);
buildRules = (
);
@@ -190,21 +189,6 @@
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";
showEnvVarsInLog = 0;
};
E671F9E92DFB9088485E493B /* Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
F012A6F39E0149F18F564F50 /* Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;