mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-22 00:38:42 +00:00
Fix visible section controllers bug (#643)
Summary: Issue fixed: #643 - [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) Closes https://github.com/Instagram/IGListKit/pull/868 Reviewed By: manicakes Differential Revision: D5553538 Pulled By: rnystrom fbshipit-source-id: 25d98a28d47a15d494ba530c850e0335d87d758c
This commit is contained in:
parent
85afdfa54b
commit
bb9b037ed3
3 changed files with 23 additions and 4 deletions
|
|
@ -8,6 +8,7 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag
|
|||
### Fixes
|
||||
|
||||
- Prevent a crash when update queued immediately after item batch update. [Ryan Nystrom](https://github.com/rnystrom) (tbd)
|
||||
- Return correct `-[IGListAdapter visibleSectionControllers]` when section has no items, but has supplementary views. [Mani Ghasemlou](https://github.com/manicakes) [(#643)](https://github.com/Instagram/IGListKit/issues/643)
|
||||
|
||||
### Enhancements
|
||||
|
||||
|
|
|
|||
|
|
@ -424,11 +424,12 @@
|
|||
|
||||
- (NSArray<IGListSectionController *> *)visibleSectionControllers {
|
||||
IGAssertMainThread();
|
||||
NSArray<UICollectionViewCell *> *visibleCells = [self.collectionView visibleCells];
|
||||
NSMutableSet *visibleSectionControllers = [NSMutableSet new];
|
||||
for (UICollectionViewCell *cell in visibleCells) {
|
||||
IGListSectionController *sectionController = [self sectionControllerForView:cell];
|
||||
IGAssert(sectionController != nil, @"Section controller nil for cell %@", cell);
|
||||
NSArray<UICollectionViewLayoutAttributes *> *attributes =
|
||||
[self.collectionView.collectionViewLayout layoutAttributesForElementsInRect:self.collectionView.bounds];
|
||||
for (UICollectionViewLayoutAttributes* attribute in attributes) {
|
||||
IGListSectionController *sectionController = [self sectionControllerForSection:attribute.indexPath.section];
|
||||
IGAssert(sectionController != nil, @"Section controller nil for cell in section %zd", attribute.indexPath.section);
|
||||
if (sectionController) {
|
||||
[visibleSectionControllers addObject:sectionController];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,6 +262,23 @@
|
|||
XCTAssertTrue([visibleSectionControllers containsObject:[self.adapter sectionControllerForObject:@4]]);
|
||||
}
|
||||
|
||||
- (void) test_withEmptySectionPlusFooter_thatVisibleSectionControllersAreCorrect {
|
||||
self.dataSource.objects = @[@0];
|
||||
[self.adapter reloadDataWithCompletion:nil];
|
||||
IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new];
|
||||
supplementarySource.dequeueFromNib = YES;
|
||||
supplementarySource.collectionContext = self.adapter;
|
||||
supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter];
|
||||
IGListSectionController *controller = [self.adapter sectionControllerForObject:@0];
|
||||
controller.supplementaryViewSource = supplementarySource;
|
||||
supplementarySource.sectionController = controller;
|
||||
[self.adapter performUpdatesAnimated:NO completion:nil];
|
||||
NSArray<IGListSectionController *> *visibleSectionControllers = [self.adapter visibleSectionControllers];
|
||||
|
||||
XCTAssertTrue([visibleSectionControllers count] == 1);
|
||||
XCTAssertTrue(visibleSectionControllers.firstObject.supplementaryViewSource == supplementarySource);
|
||||
}
|
||||
|
||||
- (void)test_whenCellsExtendBeyondBounds_thatVisibleCellsExistForSectionControllers {
|
||||
self.dataSource.objects = @[@2, @3, @4, @5, @6];
|
||||
[self.adapter reloadDataWithCompletion:nil];
|
||||
|
|
|
|||
Loading…
Reference in a new issue