mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-06 06:58:26 +00:00
Summary: Working on porting our collection view layout to IGListKit. I'm doing this because its a solid layout, and we just finished preparing it to work with inline sections. It is designed to work in tandem with IGListKit, so we're adding it. This is still a WIP as I add more tests, but I'd love as much feedback as possible. Aside from the glob of header documentation, this has the following features: - Infinite sections that each have infinite items. Sections and items can fall inline. When they break the width of their container they will fall on the next row. - Sections can have their own insets, line spacing, and interitem spacing. - Sticky header support! When you use headers, it will always newline the section. - Maximum width with a border decoration view - Use this to pinch in your content on larger devices Followup to #423 - [ ] ~~Move decoration view support to delegate~~ removed - [x] Unit test changing [top y sticky inset](https://coveralls.io/builds/9977284/source?filen Closes https://github.com/Instagram/IGListKit/pull/484 Differential Revision: D4547760 Pulled By: rnystrom fbshipit-source-id: 879e2da16eb78bb6a90967e77d9ad0bbf7c69594
70 lines
3.1 KiB
Objective-C
70 lines
3.1 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";
|
|
|
|
@implementation IGLayoutTestDataSource
|
|
|
|
- (void)configCollectionView:(UICollectionView *)collectionView {
|
|
[collectionView registerClass:[UICollectionViewCell class]
|
|
forCellWithReuseIdentifier:kCellIdentifier];
|
|
[collectionView registerClass:[UICollectionReusableView class]
|
|
forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
|
|
withReuseIdentifier:kHeaderIdentifier];
|
|
}
|
|
|
|
#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 {
|
|
return [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
|
|
withReuseIdentifier:kHeaderIdentifier
|
|
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(CGRectGetWidth(collectionView.bounds), self.sections[section].headerHeight);
|
|
}
|
|
|
|
@end
|