[ASRangeController] Inspect delegate's ASInterfaceState to delay preloading beyond viewport until visible.

This commit is contained in:
Scott Goodson
2016-01-03 19:14:07 -08:00
parent 95bd2c264c
commit 984fe43997
10 changed files with 181 additions and 49 deletions

View File

@@ -782,6 +782,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
return self.bounds.size;
}
- (ASInterfaceState)interfaceStateForRangeController:(ASRangeController *)rangeController
{
return self.collectionNode.interfaceState;
}
- (NSArray *)rangeController:(ASRangeController *)rangeController nodesAtIndexPaths:(NSArray *)indexPaths
{
return [_dataController nodesAtIndexPaths:indexPaths];
@@ -944,6 +949,27 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
}
}
#pragma mark - _ASDisplayView behavior substitutions
// Need these to drive interfaceState so we know when we are visible, if not nested in another range-managing element.
// Because our superclass is a true UIKit class, we cannot also subclass _ASDisplayView.
- (void)willMoveToWindow:(UIWindow *)newWindow
{
BOOL visible = (newWindow != nil);
ASDisplayNode *node = self.collectionNode;
if (visible && !node.inHierarchy) {
[node __enterHierarchy];
}
}
- (void)didMoveToWindow
{
BOOL visible = (self.window != nil);
ASDisplayNode *node = self.collectionNode;
if (!visible && node.inHierarchy) {
[node __exitHierarchy];
}
}
#pragma mark - UICollectionView dead-end intercepts
#if ASDISPLAYNODE_ASSERTIONS_ENABLED // Remove implementations entirely for efficiency if not asserting.