Skip to content

Commit

Permalink
Support supplementaryViews created from nibs (continued)
Browse files Browse the repository at this point in the history
Summary:
Continuing the work on #90. I don't believe I can push directly to that PR since the origin is `master` of a repo I don't have access to.

https://help.github.com/articles/checking-out-pull-requests-locally/

I went ahead and added another supplementary view test copying the old one we had.

cc jessesquires in case there's something else I can do here. I believe this will still give rawlinxx credit?
Closes #162

Differential Revision: D4137364

Pulled By: rnystrom

fbshipit-source-id: d8418ac5728fd6d9570fa1d1568f4343f5c4112b
  • Loading branch information
Ryan Nystrom authored and Facebook Github Bot committed Nov 5, 2016
1 parent dca2478 commit f533911
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This release closes the [2.0.0 milestone](https://github.com/Instagram/IGListKit

### Enhancements

- Added support for supplementaryViews created from nibs. [Rawlinxx](https://github.com/rawlinxx) [(#90)](https://github.com/Instagram/IGListKit/pull/90)
- Added support for cells created from nibs. [Sven Bacia](https://github.com/svenbacia) [(#56)](https://github.com/Instagram/IGListKit/pull/56)
- Added an additional initializer for `IGListSingleSectionController` to be able to support single sections created from nibs. An example can be found [here](Example/IGListKitExamples/ViewControllers/SingleSectionViewController.swift).
- Fixed `-[IGListAdapter reloadDataWithCompletion:]` not returning early when `collectionView` or `dataSource` is nil and `completion` is nil. [Ben Asher](https://github.com/benasher44) [(#51)](https://github.com/Instagram/IGListKit/pull/51)
Expand Down
26 changes: 20 additions & 6 deletions IGListKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
01E12EE2D2F55E9DE8928E1E /* Pods_IGListKit_tvOSTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 529C388FDB3DF79737F3496A /* Pods_IGListKit_tvOSTests.framework */; };
26271C8A1DAE94E40073E116 /* IGTestSingleNibItemDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 26271C891DAE94E40073E116 /* IGTestSingleNibItemDataSource.m */; };
26271C8C1DAE96740073E116 /* IGListSingleNibItemControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 26271C8B1DAE96740073E116 /* IGListSingleNibItemControllerTests.m */; };
290486201DCD02750007F41D /* IGTestNibSupplementaryView.h in Headers */ = {isa = PBXBuildFile; fileRef = 2904861E1DCD02750007F41D /* IGTestNibSupplementaryView.h */; };
290486211DCD02750007F41D /* IGTestNibSupplementaryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2904861F1DCD02750007F41D /* IGTestNibSupplementaryView.m */; };
2914BEE91DCD15F400C96401 /* IGTestNibSupplementaryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2904861C1DCD02140007F41D /* IGTestNibSupplementaryView.xib */; };
2914BEEA1DCD15F400C96401 /* IGTestNibSupplementaryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2904861C1DCD02140007F41D /* IGTestNibSupplementaryView.xib */; };
296176F71D9D54C100F40F34 /* IGListScrollDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 296176EF1D9D54C100F40F34 /* IGListScrollDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
296176F81D9D54C100F40F34 /* IGListSectionController.h in Headers */ = {isa = PBXBuildFile; fileRef = 296176F01D9D54C100F40F34 /* IGListSectionController.h */; settings = {ATTRIBUTES = (Public, ); }; };
296176F91D9D54C100F40F34 /* IGListSectionController.m in Sources */ = {isa = PBXBuildFile; fileRef = 296176F11D9D54C100F40F34 /* IGListSectionController.m */; };
Expand Down Expand Up @@ -194,7 +198,7 @@
885FE2401DC51B86009CE2B4 /* IGTestSingleItemDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144F021D870EDC007C7F66 /* IGTestSingleItemDataSource.m */; };
885FE2411DC51B86009CE2B4 /* IGTestSingleNibItemDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 26271C891DAE94E40073E116 /* IGTestSingleNibItemDataSource.m */; };
885FE2421DC51B86009CE2B4 /* IGTestSingleStoryboardItemDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4D21DB981AB00172ED0 /* IGTestSingleStoryboardItemDataSource.m */; };
885FE2431DC51B86009CE2B4 /* IGTestSingleStoryboardViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4C81DB8D5B200172ED0 /* IGTestSingleStoryboardViewController.m */; };
885FE2431DC51B86009CE2B4 /* IGTestStoryboardViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4C81DB8D5B200172ED0 /* IGTestStoryboardViewController.m */; };
885FE2441DC51B86009CE2B4 /* IGTestStackedDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144F041D870EDC007C7F66 /* IGTestStackedDataSource.m */; };
885FE2451DC51B86009CE2B4 /* IGTestStoryboardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4CD1DB8D8C500172ED0 /* IGTestStoryboardCell.m */; };
885FE2461DC51B86009CE2B4 /* IGTestSupplementarySource.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144F061D870EDC007C7F66 /* IGTestSupplementarySource.m */; };
Expand Down Expand Up @@ -226,6 +230,9 @@
26271C881DAE94E40073E116 /* IGTestSingleNibItemDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestSingleNibItemDataSource.h; sourceTree = "<group>"; };
26271C891DAE94E40073E116 /* IGTestSingleNibItemDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestSingleNibItemDataSource.m; sourceTree = "<group>"; };
26271C8B1DAE96740073E116 /* IGListSingleNibItemControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListSingleNibItemControllerTests.m; sourceTree = "<group>"; };
2904861C1DCD02140007F41D /* IGTestNibSupplementaryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = IGTestNibSupplementaryView.xib; sourceTree = "<group>"; };
2904861E1DCD02750007F41D /* IGTestNibSupplementaryView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestNibSupplementaryView.h; sourceTree = "<group>"; };
2904861F1DCD02750007F41D /* IGTestNibSupplementaryView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestNibSupplementaryView.m; sourceTree = "<group>"; };
294369B01DB1B7AE0025F6E7 /* IGTestNibCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = IGTestNibCell.xib; sourceTree = "<group>"; };
296176EF1D9D54C100F40F34 /* IGListScrollDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListScrollDelegate.h; sourceTree = "<group>"; };
296176F01D9D54C100F40F34 /* IGListSectionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListSectionController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -394,6 +401,7 @@
isa = PBXGroup;
children = (
294369B01DB1B7AE0025F6E7 /* IGTestNibCell.xib */,
2904861C1DCD02140007F41D /* IGTestNibSupplementaryView.xib */,
821BC4C21DB8CAE900172ED0 /* IGTestStoryboard.storyboard */,
);
path = Assets;
Expand Down Expand Up @@ -431,6 +439,8 @@
88144EFC1D870EDC007C7F66 /* IGTestDelegateController.m */,
88144EFD1D870EDC007C7F66 /* IGTestDelegateDataSource.h */,
88144EFE1D870EDC007C7F66 /* IGTestDelegateDataSource.m */,
2904861E1DCD02750007F41D /* IGTestNibSupplementaryView.h */,
2904861F1DCD02750007F41D /* IGTestNibSupplementaryView.m */,
88144EFF1D870EDC007C7F66 /* IGTestObject.h */,
88144F001D870EDC007C7F66 /* IGTestObject.m */,
88144F011D870EDC007C7F66 /* IGTestSingleItemDataSource.h */,
Expand All @@ -439,18 +449,18 @@
26271C891DAE94E40073E116 /* IGTestSingleNibItemDataSource.m */,
821BC4D11DB9816E00172ED0 /* IGTestSingleStoryboardItemDataSource.h */,
821BC4D21DB981AB00172ED0 /* IGTestSingleStoryboardItemDataSource.m */,
821BC4C71DB8D5B200172ED0 /* IGTestStoryboardViewController.h */,
821BC4C81DB8D5B200172ED0 /* IGTestStoryboardViewController.m */,
88144F031D870EDC007C7F66 /* IGTestStackedDataSource.h */,
88144F041D870EDC007C7F66 /* IGTestStackedDataSource.m */,
821BC4CC1DB8D8C500172ED0 /* IGTestStoryboardCell.h */,
821BC4CD1DB8D8C500172ED0 /* IGTestStoryboardCell.m */,
88144F051D870EDC007C7F66 /* IGTestSupplementarySource.h */,
88144F061D870EDC007C7F66 /* IGTestSupplementarySource.m */,
8240C7F31DC2D99300B3AAE7 /* IGTestStoryboardSupplementarySource.h */,
8240C7F41DC2D99300B3AAE7 /* IGTestStoryboardSupplementarySource.m */,
8240C7EE1DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.h */,
8240C7EF1DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.m */,
821BC4C71DB8D5B200172ED0 /* IGTestStoryboardViewController.h */,
821BC4C81DB8D5B200172ED0 /* IGTestStoryboardViewController.m */,
88144F051D870EDC007C7F66 /* IGTestSupplementarySource.h */,
88144F061D870EDC007C7F66 /* IGTestSupplementarySource.m */,
);
path = Objects;
sourceTree = "<group>";
Expand Down Expand Up @@ -658,6 +668,7 @@
88144F6C1D870F3E007C7F66 /* IGListDisplayDelegate.h in Headers */,
88144F811D870F3E007C7F66 /* IGListUpdatingDelegate.h in Headers */,
88144F6D1D870F3E007C7F66 /* IGListExperiments.h in Headers */,
290486201DCD02750007F41D /* IGTestNibSupplementaryView.h in Headers */,
88144F5E1D870F3E007C7F66 /* IGListAdapterDataSource.h in Headers */,
88144F621D870F3E007C7F66 /* IGListAdapterUpdaterDelegate.h in Headers */,
88144F971D870F3E007C7F66 /* NSObject+IGListDiffable.h in Headers */,
Expand Down Expand Up @@ -837,6 +848,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2914BEEA1DCD15F400C96401 /* IGTestNibSupplementaryView.xib in Resources */,
885FE2471DC51B90009CE2B4 /* IGTestNibCell.xib in Resources */,
885FE2481DC51B90009CE2B4 /* IGTestStoryboard.storyboard in Resources */,
);
Expand All @@ -853,6 +865,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2914BEE91DCD15F400C96401 /* IGTestNibSupplementaryView.xib in Resources */,
29EA6C491DB43A8000957A88 /* IGTestNibCell.xib in Resources */,
821BC4C41DB8CEF800172ED0 /* IGTestStoryboard.storyboard in Resources */,
);
Expand Down Expand Up @@ -1010,7 +1023,7 @@
885FE2411DC51B86009CE2B4 /* IGTestSingleNibItemDataSource.m in Sources */,
885FE2441DC51B86009CE2B4 /* IGTestStackedDataSource.m in Sources */,
885FE2461DC51B86009CE2B4 /* IGTestSupplementarySource.m in Sources */,
885FE2431DC51B86009CE2B4 /* IGTestSingleStoryboardViewController.m in Sources */,
885FE2431DC51B86009CE2B4 /* IGTestStoryboardViewController.m in Sources */,
885FE23A1DC51B86009CE2B4 /* IGListTestSection.m in Sources */,
885FE23E1DC51B86009CE2B4 /* IGTestDelegateDataSource.m in Sources */,
);
Expand All @@ -1034,6 +1047,7 @@
296176FC1D9D54C100F40F34 /* IGListSingleSectionController.m in Sources */,
296177051D9D54E300F40F34 /* IGListSectionMap.m in Sources */,
88144F771D870F3E007C7F66 /* IGListMoveIndex.m in Sources */,
290486211DCD02750007F41D /* IGTestNibSupplementaryView.m in Sources */,
88144F921D870F3E007C7F66 /* IGListWorkingRangeHandler.mm in Sources */,
88144F5D1D870F3E007C7F66 /* IGListAdapter.m in Sources */,
88144F611D870F3E007C7F66 /* IGListAdapterUpdater.m in Sources */,
Expand Down
26 changes: 23 additions & 3 deletions Source/IGListAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -706,7 +707,7 @@ - (void)deselectItemAtIndex:(NSInteger)index
}

- (__kindof UICollectionViewCell *)dequeueReusableCellOfClass:(Class)cellClass
forSectionController:(IGListSectionController <IGListSectionType> *)sectionController
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
atIndex:(NSInteger)index {
IGAssertMainThread();
IGParameterAssert(sectionController != nil);
Expand Down Expand Up @@ -740,7 +741,7 @@ - (UICollectionViewCell *)dequeueReusableCellWithNibName:(NSString *)nibName
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
atIndex:(NSInteger)index {
IGAssertMainThread();
IGParameterAssert(nibName != nil);
IGParameterAssert([nibName length] > 0);
IGParameterAssert(sectionController != nil);
IGParameterAssert(index >= 0);
UICollectionView *collectionView = self.collectionView;
Expand All @@ -755,7 +756,7 @@ - (UICollectionViewCell *)dequeueReusableCellWithNibName:(NSString *)nibName
}

- (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind
forSectionController:(IGListSectionController <IGListSectionType> *)sectionController
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
class:(Class)viewClass
atIndex:(NSInteger)index {
IGAssertMainThread();
Expand Down Expand Up @@ -789,6 +790,25 @@ - (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewFromStory
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();
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);
Expand Down
18 changes: 18 additions & 0 deletions Source/IGListCollectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@ NS_ASSUME_NONNULL_BEGIN
withIdentifier:(NSString *)identifier
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
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
nibName:(NSString *)nibName
bundle:(nullable NSBundle *)bundle
atIndex:(NSInteger)index;

/**
Reloads cells in the section controller.
Expand Down
13 changes: 13 additions & 0 deletions Source/IGListStackedSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ - (UICollectionReusableView *)dequeueReusableSupplementaryViewFromStoryboardOfKi
atIndex:(index + offset)];
}

- (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
nibName:(NSString *)nibName
bundle:(NSBundle *)bundle
atIndex:(NSInteger)index {
const NSUInteger offset = [self offsetForSectionController:sectionController];
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind
forSectionController:self
nibName:nibName
bundle:bundle
atIndex:(index + offset)];
}

- (void)reloadInSectionController:(IGListSectionController<IGListSectionType> *)sectionController atIndexes:(NSIndexSet *)indexes {
NSIndexSet *itemIndexes = [self itemIndexesForSectionController:sectionController indexes:indexes];
[self.collectionContext reloadInSectionController:self atIndexes:itemIndexes];
Expand Down
1 change: 1 addition & 0 deletions Source/Internal/IGListAdapterInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ IGListCollectionContext
@property (nonatomic, strong) NSMutableSet<Class> *registeredCellClasses;
@property (nonatomic, strong) NSMutableSet<NSString *> *registeredNibNames;
@property (nonatomic, strong) NSMutableSet<NSString *> *registeredSupplementaryViewIdentifiers;
@property (nonatomic, strong) NSMutableSet<NSString *> *registeredSupplementaryViewNibNames;

- (NSArray *)indexPathsFromSectionController:(IGListSectionController <IGListSectionType> *)sectionController
indexes:(NSIndexSet *)indexes
Expand Down
Loading

0 comments on commit f533911

Please sign in to comment.