[ASRangeController] Don't bother asking UIKit for the visible index paths if view is zero-sized, as it triggers a reloadData.

This commit is contained in:
Scott Goodson
2016-03-10 19:10:25 -08:00
parent aab2ecc26e
commit 0e460ca00a
3 changed files with 21 additions and 5 deletions

View File

@@ -149,6 +149,17 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive;
return;
}
// allNodes is a 2D array: it contains arrays for each section, each containing nodes.
NSArray<NSArray *> *allNodes = [_dataSource completedNodes];
NSUInteger numberOfSections = [allNodes count];
if (_allPreviousIndexPaths.count == 0 && allNodes.count == 0) {
// In certain cases, such as on app suspend, an update may be triggered before we've loaded anything.
// For example, an ASCollectionNode inside another scrollable area will not load content until it has entered
// the display range, but the object may have been allocated by a cell and added to the set of active range controllers.
return;
}
// TODO: Consider if we need to use this codepath, or can rely on something more similar to the data & display ranges
// Example: ... = [_layoutController indexPathsForScrolling:_scrollDirection rangeType:ASLayoutRangeTypeVisible];
NSArray<NSIndexPath *> *visibleNodePaths = [_dataSource visibleNodeIndexPathsForRangeController:self];
@@ -165,10 +176,6 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive;
[_layoutController setVisibleNodeIndexPaths:visibleNodePaths];
}
// allNodes is a 2D array: it contains arrays for each section, each containing nodes.
NSArray<NSArray *> *allNodes = [_dataSource completedNodes];
NSUInteger numberOfSections = [allNodes count];
NSArray<ASDisplayNode *> *currentSectionNodes = nil;
NSInteger currentSectionIndex = -1; // Set to -1 so we don't match any indexPath.section on the first iteration.
NSUInteger numberOfNodesInSection = 0;