IGListKit/Tests/Objects/IGTestDelegateController.m
Ryan Nystrom 6bdcac81d8 Layout invalidation API
Summary:
Adding a new layout-invalidation API, telling the layout object to query and rebuild the layout for all items in the section controller. This works with `UICollectionViewFlowLayout` and should work with other custom layouts (including our own).

Issue fixed: #360, #459

- [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.
Closes https://github.com/Instagram/IGListKit/pull/499

Reviewed By: jessesquires

Differential Revision: D4590274

Pulled By: rnystrom

fbshipit-source-id: f87235be4e6c024bf979b831a8938be68895e011
2017-02-21 15:30:56 -08:00

94 lines
3.2 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 "IGTestDelegateController.h"
#import "IGTestCell.h"
#import "IGTestObject.h"
@implementation IGTestDelegateController
- (instancetype)init {
if (self = [super init]) {
_willDisplayCellIndexes = [NSCountedSet new];
_didEndDisplayCellIndexes = [NSCountedSet new];
_height = 10.0;
self.workingRangeDelegate = self;
}
return self;
}
- (NSInteger)numberOfItems {
if ([self.item.value isKindOfClass:[NSNumber class]]) {
return [self.item.value integerValue];
}
return 1;
}
- (CGSize)sizeForItemAtIndex:(NSInteger)index {
return CGSizeMake(self.collectionContext.containerSize.width, self.height);
}
- (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index {
IGTestCell *cell = [self.collectionContext dequeueReusableCellOfClass:IGTestCell.class
forSectionController:self atIndex:index];
[[cell label] setText:[NSString stringWithFormat:@"%@", self.item.value]];
[cell setDelegate:self];
if (self.cellConfigureBlock) {
self.cellConfigureBlock(self);
}
return cell;
}
- (void)didUpdateToObject:(id)object {
_updateCount++;
_item = object;
if (self.itemUpdateBlock) {
self.itemUpdateBlock();
}
}
- (id<IGListDisplayDelegate>)displayDelegate {
return self;
}
- (void)didSelectItemAtIndex:(NSInteger)index {}
#pragma mark - IGListDisplayDelegate
- (void)listAdapter:(IGListAdapter *)listAdapter willDisplaySectionController:(IGListSectionController <IGListSectionType> *)sectionController {
self.willDisplayCount++;
}
- (void)listAdapter:(IGListAdapter *)listAdapter didEndDisplayingSectionController:(IGListSectionController <IGListSectionType> *)sectionController {
self.didEndDisplayCount++;
}
- (void)listAdapter:(IGListAdapter *)listAdapter willDisplaySectionController:(IGListSectionController <IGListSectionType> *)sectionController
cell:(UICollectionViewCell *)cell
atIndex:(NSInteger)index {
[self.willDisplayCellIndexes addObject:@(index)];
}
- (void)listAdapter:(IGListAdapter *)listAdapter didEndDisplayingSectionController:(IGListSectionController <IGListSectionType> *)sectionController
cell:(UICollectionViewCell *)cell
atIndex:(NSInteger)index {
[self.didEndDisplayCellIndexes addObject:@(index)];
}
- (void)listAdapter:(IGListAdapter *)listAdapter didScrollSectionController:(IGListSectionController <IGListSectionType> *)sectionController {}
#pragma mark - IGListWorkingRangeDelegate
- (void)listAdapter:(IGListAdapter *)listAdapter sectionControllerWillEnterWorkingRange:(IGListSectionController<IGListSectionType> *)sectionController {
__unused UICollectionViewCell *cell = [self.collectionContext cellForItemAtIndex:0 sectionController:self];
}
- (void)listAdapter:(IGListAdapter *)listAdapter sectionControllerDidExitWorkingRange:(IGListSectionController<IGListSectionType> *)sectionController {}
@end