IGListKit/Tests/Objects/IGLayoutTestDataSource.m
Igor Vasilenko a0cf76c757 Added support UICollectionElementKindSectionFooter for IGListCollectionViewLayout
Summary:
**Changes occurred only for the IGListCollectionViewLayout.**

**Specifically:**
1. Harnessed the hardcore to the fact that it is possible to use only headers.
2. Assertions removed
3. Caching for layout of attributes of footers
4. Implemented the location of the footers in any orientation scroll

Issue fixed: #898

I need this enhancement ASAP 🙏

**Example:**
Footers with user comments count
![simulator screen shot - iphone 6 - 2017-11-14 at 13 35 22](https://user-images.githubusercontent.com/7735730/32775551-c69868cc-c940-11e7-8307-ae2e353519ff.png)

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
- [x] I updated example project with implemented feature
Closes https://github.com/Instagram/IGListKit/pull/1017

Reviewed By: jeremycohen

Differential Revision: D6385893

Pulled By: rnystrom

fbshipit-source-id: 5f1bad5655d2df321f8c71496aa797ac8e3d226a
2017-11-21 12:45:38 -08:00

79 lines
3.8 KiB
Objective-C

/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "IGLayoutTestDataSource.h"
#import "IGLayoutTestItem.h"
#import "IGLayoutTestSection.h"
static NSString * const kCellIdentifier = @"cell";
static NSString * const kHeaderIdentifier = @"header";
static NSString * const kFooterIdentifier = @"footer";
@implementation IGLayoutTestDataSource
- (void)configCollectionView:(UICollectionView *)collectionView {
[collectionView registerClass:[UICollectionViewCell class]
forCellWithReuseIdentifier:kCellIdentifier];
[collectionView registerClass:[UICollectionReusableView class]
forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:kHeaderIdentifier];
[collectionView registerClass:[UICollectionReusableView class]
forSupplementaryViewOfKind:UICollectionElementKindSectionFooter
withReuseIdentifier:kFooterIdentifier];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return [self.sections count];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.sections[section].items count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
return [collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifier forIndexPath:indexPath];
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
NSString *reuseIdentifier = [kind isEqualToString:UICollectionElementKindSectionHeader]? kHeaderIdentifier : kFooterIdentifier;
return [collectionView dequeueReusableSupplementaryViewOfKind:kind
withReuseIdentifier:reuseIdentifier
forIndexPath:indexPath];
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return self.sections[section].insets;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return self.sections[indexPath.section].items[indexPath.item].size;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return self.sections[section].lineSpacing;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return self.sections[section].interitemSpacing;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
return CGSizeMake(self.sections[section].headerHeight, self.sections[section].headerHeight); // Only the dimension along scrolling direction is used
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
return CGSizeMake(self.sections[section].footerHeight, self.sections[section].footerHeight); // Only the dimension along scrolling direction is used
}
@end