mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 17:28:22 +00:00
Create private method in IGListStackedSectionController to get relative index
Summary: Fixes from PR #273 rebase. jessesquires rnystrom this should look a little better and be able to merge. - [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 have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/275 Differential Revision: D4271440 Pulled By: rnystrom fbshipit-source-id: a85b8c80b5504640d7f82b183ed5b5d0d0ea5c1b
This commit is contained in:
parent
f2a9d93be8
commit
36363f42aa
1 changed files with 20 additions and 16 deletions
|
|
@ -109,6 +109,11 @@ static void * kStackedSectionControllerIndexKey = &kStackedSectionControllerInde
|
|||
return index - offset;
|
||||
}
|
||||
|
||||
- (NSInteger)relativeIndexForSectionController:(IGListSectionController<IGListSectionType> *)sectionController fromLocalIndex:(NSInteger)index {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
return index + offset;
|
||||
}
|
||||
|
||||
- (NSIndexSet *)itemIndexesForSectionController:(IGListSectionController<IGListSectionType> *)sectionController indexes:(NSIndexSet *)indexes {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
NSMutableIndexSet *itemIndexes = [[NSMutableIndexSet alloc] init];
|
||||
|
|
@ -161,8 +166,7 @@ static void * kStackedSectionControllerIndexKey = &kStackedSectionControllerInde
|
|||
}
|
||||
|
||||
- (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController:(IGListSectionController<IGListSectionType> *)sectionController {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
return [self.collectionContext cellForItemAtIndex:(index + offset) sectionController:self];
|
||||
return [self.collectionContext cellForItemAtIndex: [self relativeIndexForSectionController:sectionController fromLocalIndex:index] sectionController:self];
|
||||
}
|
||||
|
||||
- (NSArray<UICollectionViewCell *> *)visibleCellsForSectionController:(IGListSectionController<IGListSectionType> *)sectionController {
|
||||
|
|
@ -190,52 +194,52 @@ static void * kStackedSectionControllerIndexKey = &kStackedSectionControllerInde
|
|||
- (UICollectionViewCell *)dequeueReusableCellOfClass:(Class)cellClass
|
||||
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
|
||||
atIndex:(NSInteger)index {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
const NSInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index];
|
||||
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableCellOfClass:cellClass
|
||||
forSectionController:self
|
||||
atIndex:(index + offset)];
|
||||
atIndex:offsetIndex];
|
||||
}
|
||||
|
||||
- (UICollectionViewCell *)dequeueReusableCellWithNibName:(NSString *)nibName
|
||||
bundle:(NSBundle *)bundle
|
||||
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
|
||||
atIndex:(NSInteger)index {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
const NSInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index];
|
||||
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableCellWithNibName:nibName
|
||||
bundle:bundle
|
||||
forSectionController:self
|
||||
atIndex:(index + offset)];
|
||||
atIndex:offsetIndex];
|
||||
}
|
||||
|
||||
- (UICollectionViewCell *)dequeueReusableCellFromStoryboardWithIdentifier:(NSString *)identifier
|
||||
forSectionController:(IGListSectionController <IGListSectionType> *)sectionController
|
||||
atIndex:(NSInteger)index {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
const NSInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index];
|
||||
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableCellFromStoryboardWithIdentifier:identifier
|
||||
forSectionController:self
|
||||
atIndex:(index + offset)];
|
||||
atIndex:offsetIndex];
|
||||
}
|
||||
|
||||
- (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind
|
||||
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
|
||||
class:(Class)viewClass
|
||||
atIndex:(NSInteger)index {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
const NSInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index];
|
||||
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind
|
||||
forSectionController:self
|
||||
class:viewClass
|
||||
atIndex:(index + offset)];
|
||||
atIndex:offsetIndex];
|
||||
}
|
||||
|
||||
- (UICollectionReusableView *)dequeueReusableSupplementaryViewFromStoryboardOfKind:(NSString *)elementKind
|
||||
withIdentifier:(NSString *)identifier
|
||||
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
|
||||
atIndex:(NSInteger)index {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
const NSInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index];
|
||||
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableSupplementaryViewFromStoryboardOfKind:elementKind
|
||||
withIdentifier:identifier
|
||||
forSectionController:self
|
||||
atIndex:(index + offset)];
|
||||
atIndex:offsetIndex];
|
||||
}
|
||||
|
||||
- (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind
|
||||
|
|
@ -243,12 +247,12 @@ static void * kStackedSectionControllerIndexKey = &kStackedSectionControllerInde
|
|||
nibName:(NSString *)nibName
|
||||
bundle:(NSBundle *)bundle
|
||||
atIndex:(NSInteger)index {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
const NSInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index];
|
||||
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind
|
||||
forSectionController:self
|
||||
nibName:nibName
|
||||
bundle:bundle
|
||||
atIndex:(index + offset)];
|
||||
atIndex:offsetIndex];
|
||||
}
|
||||
|
||||
- (void)reloadInSectionController:(IGListSectionController<IGListSectionType> *)sectionController atIndexes:(NSIndexSet *)indexes {
|
||||
|
|
@ -288,9 +292,9 @@ static void * kStackedSectionControllerIndexKey = &kStackedSectionControllerInde
|
|||
atIndex:(NSInteger)index
|
||||
scrollPosition:(UICollectionViewScrollPosition)scrollPosition
|
||||
animated:(BOOL)animated {
|
||||
const NSUInteger offset = [self offsetForSectionController:sectionController];
|
||||
const NSUInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index];
|
||||
[self.collectionContext scrollToSectionController:self
|
||||
atIndex:(offset + index)
|
||||
atIndex:offsetIndex
|
||||
scrollPosition:scrollPosition
|
||||
animated:animated];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue