Don't pre-render cell nodes of collection view when it is not visible or not scrolling

This commit is contained in:
Huy Nguyen
2016-01-31 00:53:28 -08:00
parent 6d2628104b
commit b889d81de8
4 changed files with 40 additions and 14 deletions

View File

@@ -14,6 +14,7 @@
#import "ASCollectionView.h"
#import "CGRect+ASConvenience.h"
#import "UICollectionViewLayout+ASConvenience.h"
#import "ASDisplayNodeExtras.h"
struct ASRangeGeometry {
CGRect rangeBounds;
@@ -164,4 +165,19 @@ typedef struct ASRangeGeometry ASRangeGeometry;
return CGRectExpandToRangeWithScrollableDirections(rect, tuningParameters, _scrollableDirections, scrollDirection);
}
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType
{
BOOL isVisible = ASInterfaceStateIncludesVisible(_collectionView.interfaceState);
BOOL isScrolling = (_collectionView.scrollDirection != ASScrollDirectionNone);
// When the collecion view is not visible or not scrolling, make display range only as big as visible range.
// This reduce early creation of views and layers.
if (!isVisible || !isScrolling) {
if (rangeType == ASLayoutRangeTypeDisplay) {
return [super tuningParametersForRangeType:ASLayoutRangeTypeVisible];
}
}
return [super tuningParametersForRangeType:rangeType];
}
@end