2017-02-11 01:58:52 +00:00
|
|
|
/**
|
|
|
|
|
* 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 {
|
Add horizontal scrolling support to IGListCollectionViewLayout
Summary:
Issue fixed: #752
- [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)
This PR generalizes the layout logic in `IGListCollectionViewLayout.mm` to handle horizontally scrolling layouts, mainly by generalizing references to `width`, `height`, `x` and `y` to take scrolling direction into account. This changes the signature of `IGListCollectionViewLayout.init` as well as the names of a few properties, so it would be a breaking change.
I added a couple of unit tests specifically for horizontal layouts -- but held off from adding a horizontal version of *every* unit test for this class, as it would basically double the number of tests. But if you want that, just let me know and I'm happy to do it.
Also let me know if you want me to add a demo VC to the Examples project that uses this new horizontal flow layout -- I have some demo code handy (I used it for testing), but didn't want to clutter up the PR if you didn't want/need it.
Closes https://github.com/Instagram/IGListKit/pull/857
Reviewed By: ryanolsonk
Differential Revision: D5547266
Pulled By: rnystrom
fbshipit-source-id: 6094c45069fc265273d0f95c296fa78e47470384
2017-08-07 16:22:40 +00:00
|
|
|
return CGSizeMake(self.sections[section].headerHeight, self.sections[section].headerHeight); // Only the dimension along scrolling direction is used
|
2017-02-11 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|