-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support supplementaryViews created from nibs #90
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ - (void)setCollectionView:(IGListCollectionView *)collectionView { | |
_registeredCellClasses = [NSMutableSet new]; | ||
_registeredNibNames = [NSMutableSet new]; | ||
_registeredSupplementaryViewIdentifiers = [NSMutableSet new]; | ||
_registeredSupplementaryViewNibNames = [NSMutableSet new]; | ||
|
||
_collectionView = collectionView; | ||
_collectionView.dataSource = self; | ||
|
@@ -731,6 +732,7 @@ - (UICollectionViewCell *)dequeueReusableCellWithNibName:(NSString *)nibName | |
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController | ||
atIndex:(NSInteger)index { | ||
IGAssertMainThread(); | ||
IGParameterAssert([nibName length] > 0); | ||
IGParameterAssert(sectionController != nil); | ||
UICollectionView *collectionView = self.collectionView; | ||
IGAssert(collectionView != nil, @"Reloading adapter without a collection view."); | ||
|
@@ -759,6 +761,25 @@ - (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(N | |
return [collectionView dequeueReusableSupplementaryViewOfKind:elementKind withReuseIdentifier:identifier forIndexPath:indexPath]; | ||
} | ||
|
||
- (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind | ||
forSectionController:(IGListSectionController <IGListSectionType> *)sectionController | ||
nibName:(NSString *)nibName | ||
bundle:(NSBundle *)bundle | ||
atIndex:(NSInteger)index { | ||
IGAssertMainThread(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also add: IGParameterAssert([nibName length] > 0);
IGParameterAssert([elementKind length] > 0); I realize those are also missing from other methods. Adding some starter tasks for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for that, I'm trying this framework, hope to have this feature ASAP, without attention to details There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rawlinxx no worries! PRs are an iterative process, its good to get something up and we can all work on it together 👨👩👧👦 |
||
IGParameterAssert([nibName length] > 0); | ||
IGParameterAssert([elementKind length] > 0); | ||
UICollectionView *collectionView = self.collectionView; | ||
IGAssert(collectionView != nil, @"Reloading adapter without a collection view."); | ||
NSIndexPath *indexPath = [self indexPathForSectionController:sectionController index:index]; | ||
if (![self.registeredSupplementaryViewNibNames containsObject:nibName]) { | ||
[self.registeredSupplementaryViewNibNames addObject:nibName]; | ||
UINib *nib = [UINib nibWithNibName:nibName bundle:bundle]; | ||
[collectionView registerNib:nib forSupplementaryViewOfKind:elementKind withReuseIdentifier:nibName]; | ||
} | ||
return [collectionView dequeueReusableSupplementaryViewOfKind:elementKind withReuseIdentifier:nibName forIndexPath:indexPath]; | ||
} | ||
|
||
- (void)reloadInSectionController:(IGListSectionController<IGListSectionType> *)sectionController atIndexes:(NSIndexSet *)indexes { | ||
IGAssertMainThread(); | ||
IGParameterAssert(indexes != nil); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,25 @@ NS_ASSUME_NONNULL_BEGIN | |
class:(Class)viewClass | ||
atIndex:(NSInteger)index; | ||
|
||
/** | ||
Dequeues a supplementary view from the UICollectionView reuse pool. | ||
|
||
@param elementKind The kind of supplementary veiw. | ||
@param sectionController The section controller requesting this information. | ||
@param nibName The name of the nib file. | ||
@param bundle The bundle in which to search for the nib file. If nil, this method looks for the nib file in the main bundle. | ||
@param index The index of the supplementary vew. | ||
|
||
@return A supplementary view dequeued from the reuse pool or newly created. | ||
|
||
@note This method uses a string representation of the view class as the identifier. | ||
*/ | ||
- (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind | ||
forSectionController:(IGListSectionController <IGListSectionType> *)sectionController | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: spacing between class and protocol |
||
nibName:(NSString *)nibName | ||
bundle:(nullable NSBundle *)bundle | ||
atIndex:(NSInteger)index; | ||
|
||
/** | ||
Reloads cells in the section controller. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,12 +213,26 @@ - (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString * | |
class:(Class)viewClass | ||
atIndex:(NSInteger)index { | ||
const NSUInteger offset = [self offsetForSectionController:sectionController]; | ||
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind | ||
return (UICollectionReusableView *_Nonnull)[self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind | ||
forSectionController:self | ||
class:viewClass | ||
atIndex:(index + offset)]; | ||
} | ||
|
||
- (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind | ||
forSectionController:(IGListSectionController <IGListSectionType> *)sectionController | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spacing between class/protocol |
||
nibName:(NSString *)nibName | ||
bundle:(NSBundle *)bundle | ||
atIndex:(NSInteger)index | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curly needs to be on the same line as the last param |
||
const NSUInteger offset = [self offsetForSectionController:sectionController]; | ||
return (UICollectionReusableView *_Nonnull)[self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm I'm actually not sure why we're casting it in the other methods. I just tried it locally and we can remove those. I wouldn't worry about it now. Can we revert the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
forSectionController:self | ||
nibName:nibName | ||
bundle:bundle | ||
atIndex:(index + offset)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we realign the colons? |
||
} | ||
|
||
- (void)reloadInSectionController:(IGListSectionController<IGListSectionType> *)sectionController atIndexes:(NSIndexSet *)indexes { | ||
NSIndexSet *itemIndexes = [self itemIndexesForSectionController:sectionController indexes:indexes]; | ||
[self.collectionContext reloadInSectionController:self atIndexes:itemIndexes]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's remove the space between
IGListSectionController<IGListSectionType>