Skip to content

Commit

Permalink
Merge pull request #176 from rafaelcr/patch-2
Browse files Browse the repository at this point in the history
Support simultaneous headers and footers
  • Loading branch information
chiahsien authored Jun 28, 2017
2 parents 380cd52 + c9cd67b commit 510875c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions CHTCollectionViewWaterfallLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSInteger i;
NSInteger begin = 0, end = self.unionRects.count;
NSMutableDictionary *cellAttrDict = [NSMutableDictionary dictionary];
NSMutableDictionary *supplAttrDict = [NSMutableDictionary dictionary];
NSMutableDictionary *supplHeaderAttrDict = [NSMutableDictionary dictionary];
NSMutableDictionary *supplFooterAttrDict = [NSMutableDictionary dictionary];
NSMutableDictionary *decorAttrDict = [NSMutableDictionary dictionary];

for (i = 0; i < self.unionRects.count; i++) {
Expand All @@ -448,7 +449,11 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
if (CGRectIntersectsRect(rect, attr.frame)) {
switch (attr.representedElementCategory) {
case UICollectionElementCategorySupplementaryView:
supplAttrDict[attr.indexPath] = attr;
if ([attr.representedElementKind isEqualToString:CHTCollectionElementKindSectionHeader]) {
supplHeaderAttrDict[attr.indexPath] = attr;
} else if ([attr.representedElementKind isEqualToString:CHTCollectionElementKindSectionFooter]) {
supplFooterAttrDict[attr.indexPath] = attr;
}
break;
case UICollectionElementCategoryDecorationView:
decorAttrDict[attr.indexPath] = attr;
Expand All @@ -460,7 +465,8 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
}
}

NSArray *result = [cellAttrDict.allValues arrayByAddingObjectsFromArray:supplAttrDict.allValues];
NSArray *result = [cellAttrDict.allValues arrayByAddingObjectsFromArray:supplHeaderAttrDict.allValues];
result = [result arrayByAddingObjectsFromArray:supplFooterAttrDict.allValues];
result = [result arrayByAddingObjectsFromArray:decorAttrDict.allValues];
return result;
}
Expand Down

0 comments on commit 510875c

Please sign in to comment.