Add support for sectionInset in ASCollectionView in property and delegate form

This commit is contained in:
Levi McCallum
2015-08-03 14:36:29 -07:00
parent 16ed66c3a1
commit 5eb75d6bc7
3 changed files with 27 additions and 2 deletions

View File

@@ -118,6 +118,7 @@ static BOOL _isInterceptedSelector(SEL sel)
NSMutableArray *_batchUpdateBlocks;
BOOL _asyncDataFetchingEnabled;
BOOL _implementsInsetSection;
ASBatchContext *_batchContext;
}
@@ -164,6 +165,8 @@ static BOOL _isInterceptedSelector(SEL sel)
_performingBatchUpdates = NO;
_batchUpdateBlocks = [NSMutableArray array];
_implementsInsetSection = ([_asyncDelegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)] ? 1 : 0);
[self registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"_ASCollectionViewCell"];
@@ -511,11 +514,16 @@ static BOOL _isInterceptedSelector(SEL sel)
- (CGSize)dataController:(ASDataController *)dataController constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
{
CGSize restrainedSize = self.bounds.size;
UIEdgeInsets sectionInset = [(UICollectionViewFlowLayout *)self.collectionViewLayout sectionInset];
if (_implementsInsetSection) {
sectionInset = [_asyncDelegate collectionView:self layout:self.collectionViewLayout insetForSectionAtIndex:indexPath.section];
}
if (ASScrollDirectionContainsHorizontalDirection([self scrollableDirections])) {
restrainedSize.width = FLT_MAX;
restrainedSize.width = MAX(0, FLT_MAX - sectionInset.left - sectionInset.right);
} else {
restrainedSize.height = FLT_MAX;
restrainedSize.height = MAX(0, FLT_MAX - sectionInset.top - sectionInset.bottom);
}
return restrainedSize;