mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 09:18:29 +00:00
Back out D5353285 which crashes custom layout
Summary: Public PR crashes our custom layout b/c requesting # of items doesn't trigger `prepareLayout` on the layout. End up w/ OOB exceptions. Differential Revision: D5622021 fbshipit-source-id: ecc8cc7bfb38e3ebe7f7433c96b816469f16774c
This commit is contained in:
parent
e8ddaf8740
commit
79b8290a1e
3 changed files with 9 additions and 58 deletions
|
|
@ -14,7 +14,6 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag
|
|||
- 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)
|
||||
- Call `[CATransaction commit]` before calling completion block in IGListAdapterUpdater to prevent animation issues. [Maxime Ollivier](https://github.com/maxoll) (tbd)
|
||||
- Fix `scrollToObject:supplementaryKinds:...` not scrolling when section is empty but does have supplymentary views
|
||||
|
||||
### Enhancements
|
||||
|
||||
|
|
|
|||
|
|
@ -172,33 +172,21 @@
|
|||
}
|
||||
|
||||
UICollectionView *collectionView = self.collectionView;
|
||||
UICollectionViewLayout *layout = self.collectionView.collectionViewLayout;
|
||||
|
||||
const NSInteger numberOfItems = [collectionView numberOfItemsInSection:section];
|
||||
if (numberOfItems == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// force layout before continuing
|
||||
// this method is typcially called before pushing a view controller
|
||||
// thus, before the layout process has actually happened
|
||||
[collectionView layoutIfNeeded];
|
||||
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
|
||||
|
||||
// collect the layout attributes for the cell and supplementary views for the first index
|
||||
// this will break if there are supplementary views beyond item 0
|
||||
NSArray *attributes = nil;
|
||||
|
||||
const NSInteger numberOfItems = [collectionView numberOfItemsInSection:section];
|
||||
if (numberOfItems > 0) {
|
||||
attributes = [self layoutAttributesForIndexPath:indexPath supplementaryKinds:supplementaryKinds];
|
||||
} else {
|
||||
NSMutableArray *supplementaryAttributes = [NSMutableArray new];
|
||||
for (NSString* supplementaryKind in supplementaryKinds) {
|
||||
UICollectionViewLayoutAttributes *supplementaryAttribute = [layout layoutAttributesForSupplementaryViewOfKind:supplementaryKind atIndexPath:indexPath];
|
||||
if (supplementaryAttribute != nil) {
|
||||
[supplementaryAttributes addObject: supplementaryAttribute];
|
||||
}
|
||||
}
|
||||
attributes = supplementaryAttributes;
|
||||
}
|
||||
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
|
||||
NSArray *attributes = [self layoutAttributesForIndexPath:indexPath supplementaryKinds:supplementaryKinds];
|
||||
|
||||
CGFloat offsetMin = 0.0;
|
||||
CGFloat offsetMax = 0.0;
|
||||
for (UICollectionViewLayoutAttributes *attribute in attributes) {
|
||||
|
|
@ -727,6 +715,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - IGListCollectionContext
|
||||
|
||||
- (CGSize)containerSize {
|
||||
|
|
|
|||
|
|
@ -652,43 +652,6 @@
|
|||
IGAssertEqualPoint([self.collectionView contentOffset], 0, 60);
|
||||
}
|
||||
|
||||
- (void)test_whenScrollVerticallyToItemInASectionWithNoCellsAndNoSupplymentaryView {
|
||||
self.dataSource.objects = @[@1, @0, @300];
|
||||
[self.adapter reloadDataWithCompletion:nil];
|
||||
XCTAssertEqual([self.collectionView numberOfSections], 3);
|
||||
[self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO];
|
||||
IGAssertEqualPoint([self.collectionView contentOffset], 0, 0);
|
||||
[self.adapter scrollToObject:@0 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO];
|
||||
IGAssertEqualPoint([self.collectionView contentOffset], 0, 0);
|
||||
[self.adapter scrollToObject:@300 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO];
|
||||
IGAssertEqualPoint([self.collectionView contentOffset], 0, 10);
|
||||
}
|
||||
|
||||
- (void)test_whenScrollVerticallyToItemInASectionWithNoCellsButAHeaderSupplymentaryView {
|
||||
self.dataSource.objects = @[@1, @0, @300];
|
||||
[self.adapter reloadDataWithCompletion:nil];
|
||||
|
||||
IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new];
|
||||
supplementarySource.collectionContext = self.adapter;
|
||||
supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionHeader];
|
||||
|
||||
IGListSectionController *controller = [self.adapter sectionControllerForObject:@0];
|
||||
controller.supplementaryViewSource = supplementarySource;
|
||||
supplementarySource.sectionController = controller;
|
||||
|
||||
[self.adapter performUpdatesAnimated:NO completion:nil];
|
||||
|
||||
XCTAssertEqual([self.collectionView numberOfSections], 3);
|
||||
[self.adapter scrollToObject:@1 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO];
|
||||
IGAssertEqualPoint([self.collectionView contentOffset], 0, 0);
|
||||
[self.adapter scrollToObject:@0 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO];
|
||||
IGAssertEqualPoint([self.collectionView contentOffset], 0, 0);
|
||||
[self.adapter scrollToObject:@0 supplementaryKinds:@[UICollectionElementKindSectionHeader] scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionTop animated:NO];
|
||||
IGAssertEqualPoint([self.collectionView contentOffset], 0, 10);
|
||||
[self.adapter scrollToObject:@300 supplementaryKinds:nil scrollDirection:UICollectionViewScrollDirectionVertical scrollPosition:UICollectionViewScrollPositionNone animated:NO];
|
||||
IGAssertEqualPoint([self.collectionView contentOffset], 0, 20);
|
||||
}
|
||||
|
||||
- (void)test_whenScrollHorizontallyToItem {
|
||||
// # of items for each object == [item integerValue], so @2 has 2 items (cells)
|
||||
IGListTestAdapterHorizontalDataSource *dataSource = [[IGListTestAdapterHorizontalDataSource alloc] init];
|
||||
|
|
|
|||
Loading…
Reference in a new issue