From f5339113df8324b13be2b2f751eec6cfcd803844 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Sat, 5 Nov 2016 16:27:32 -0700 Subject: [PATCH] Support supplementaryViews created from nibs (continued) 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 https://github.com/Instagram/IGListKit/pull/162 Differential Revision: D4137364 Pulled By: rnystrom fbshipit-source-id: d8418ac5728fd6d9570fa1d1568f4343f5c4112b --- CHANGELOG.md | 1 + IGListKit.xcodeproj/project.pbxproj | 26 ++++++++++---- Source/IGListAdapter.m | 26 ++++++++++++-- Source/IGListCollectionContext.h | 18 ++++++++++ Source/IGListStackedSectionController.m | 13 +++++++ Source/Internal/IGListAdapterInternal.h | 1 + Tests/Assets/IGTestNibSupplementaryView.xib | 40 +++++++++++++++++++++ Tests/IGListAdapterTests.m | 25 +++++++++++++ Tests/Objects/IGTestNibSupplementaryView.h | 18 ++++++++++ Tests/Objects/IGTestNibSupplementaryView.m | 14 ++++++++ Tests/Objects/IGTestSupplementarySource.h | 2 ++ Tests/Objects/IGTestSupplementarySource.m | 20 ++++++++--- 12 files changed, 191 insertions(+), 13 deletions(-) create mode 100644 Tests/Assets/IGTestNibSupplementaryView.xib create mode 100644 Tests/Objects/IGTestNibSupplementaryView.h create mode 100644 Tests/Objects/IGTestNibSupplementaryView.m diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ce0031ea..fc8a92008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/IGListKit.xcodeproj/project.pbxproj b/IGListKit.xcodeproj/project.pbxproj index bcc8532ea..459a77909 100644 --- a/IGListKit.xcodeproj/project.pbxproj +++ b/IGListKit.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 */; }; @@ -226,6 +230,9 @@ 26271C881DAE94E40073E116 /* IGTestSingleNibItemDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestSingleNibItemDataSource.h; sourceTree = ""; }; 26271C891DAE94E40073E116 /* IGTestSingleNibItemDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestSingleNibItemDataSource.m; sourceTree = ""; }; 26271C8B1DAE96740073E116 /* IGListSingleNibItemControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListSingleNibItemControllerTests.m; sourceTree = ""; }; + 2904861C1DCD02140007F41D /* IGTestNibSupplementaryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = IGTestNibSupplementaryView.xib; sourceTree = ""; }; + 2904861E1DCD02750007F41D /* IGTestNibSupplementaryView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestNibSupplementaryView.h; sourceTree = ""; }; + 2904861F1DCD02750007F41D /* IGTestNibSupplementaryView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestNibSupplementaryView.m; sourceTree = ""; }; 294369B01DB1B7AE0025F6E7 /* IGTestNibCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = IGTestNibCell.xib; sourceTree = ""; }; 296176EF1D9D54C100F40F34 /* IGListScrollDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListScrollDelegate.h; sourceTree = ""; }; 296176F01D9D54C100F40F34 /* IGListSectionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListSectionController.h; sourceTree = ""; }; @@ -394,6 +401,7 @@ isa = PBXGroup; children = ( 294369B01DB1B7AE0025F6E7 /* IGTestNibCell.xib */, + 2904861C1DCD02140007F41D /* IGTestNibSupplementaryView.xib */, 821BC4C21DB8CAE900172ED0 /* IGTestStoryboard.storyboard */, ); path = Assets; @@ -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 */, @@ -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 = ""; @@ -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 */, @@ -837,6 +848,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 2914BEEA1DCD15F400C96401 /* IGTestNibSupplementaryView.xib in Resources */, 885FE2471DC51B90009CE2B4 /* IGTestNibCell.xib in Resources */, 885FE2481DC51B90009CE2B4 /* IGTestStoryboard.storyboard in Resources */, ); @@ -853,6 +865,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 2914BEE91DCD15F400C96401 /* IGTestNibSupplementaryView.xib in Resources */, 29EA6C491DB43A8000957A88 /* IGTestNibCell.xib in Resources */, 821BC4C41DB8CEF800172ED0 /* IGTestStoryboard.storyboard in Resources */, ); @@ -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 */, ); @@ -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 */, diff --git a/Source/IGListAdapter.m b/Source/IGListAdapter.m index f696a8b9c..d6800a211 100644 --- a/Source/IGListAdapter.m +++ b/Source/IGListAdapter.m @@ -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; @@ -706,7 +707,7 @@ - (void)deselectItemAtIndex:(NSInteger)index } - (__kindof UICollectionViewCell *)dequeueReusableCellOfClass:(Class)cellClass - forSectionController:(IGListSectionController *)sectionController + forSectionController:(IGListSectionController *)sectionController atIndex:(NSInteger)index { IGAssertMainThread(); IGParameterAssert(sectionController != nil); @@ -740,7 +741,7 @@ - (UICollectionViewCell *)dequeueReusableCellWithNibName:(NSString *)nibName forSectionController:(IGListSectionController *)sectionController atIndex:(NSInteger)index { IGAssertMainThread(); - IGParameterAssert(nibName != nil); + IGParameterAssert([nibName length] > 0); IGParameterAssert(sectionController != nil); IGParameterAssert(index >= 0); UICollectionView *collectionView = self.collectionView; @@ -755,7 +756,7 @@ - (UICollectionViewCell *)dequeueReusableCellWithNibName:(NSString *)nibName } - (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind - forSectionController:(IGListSectionController *)sectionController + forSectionController:(IGListSectionController *)sectionController class:(Class)viewClass atIndex:(NSInteger)index { IGAssertMainThread(); @@ -789,6 +790,25 @@ - (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewFromStory return [collectionView dequeueReusableSupplementaryViewOfKind:elementKind withReuseIdentifier:identifier forIndexPath:indexPath]; } +- (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind + forSectionController:(IGListSectionController *)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 *)sectionController atIndexes:(NSIndexSet *)indexes { IGAssertMainThread(); IGParameterAssert(indexes != nil); diff --git a/Source/IGListCollectionContext.h b/Source/IGListCollectionContext.h index b88b5aac9..c491e9b5a 100644 --- a/Source/IGListCollectionContext.h +++ b/Source/IGListCollectionContext.h @@ -152,6 +152,24 @@ NS_ASSUME_NONNULL_BEGIN withIdentifier:(NSString *)identifier forSectionController:(IGListSectionController *)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 *)sectionController + nibName:(NSString *)nibName + bundle:(nullable NSBundle *)bundle + atIndex:(NSInteger)index; /** Reloads cells in the section controller. diff --git a/Source/IGListStackedSectionController.m b/Source/IGListStackedSectionController.m index 042ab0d9f..d307156a7 100644 --- a/Source/IGListStackedSectionController.m +++ b/Source/IGListStackedSectionController.m @@ -238,6 +238,19 @@ - (UICollectionReusableView *)dequeueReusableSupplementaryViewFromStoryboardOfKi atIndex:(index + offset)]; } +- (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind + forSectionController:(IGListSectionController *)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 *)sectionController atIndexes:(NSIndexSet *)indexes { NSIndexSet *itemIndexes = [self itemIndexesForSectionController:sectionController indexes:indexes]; [self.collectionContext reloadInSectionController:self atIndexes:itemIndexes]; diff --git a/Source/Internal/IGListAdapterInternal.h b/Source/Internal/IGListAdapterInternal.h index d14dca8f2..fc1def348 100644 --- a/Source/Internal/IGListAdapterInternal.h +++ b/Source/Internal/IGListAdapterInternal.h @@ -56,6 +56,7 @@ IGListCollectionContext @property (nonatomic, strong) NSMutableSet *registeredCellClasses; @property (nonatomic, strong) NSMutableSet *registeredNibNames; @property (nonatomic, strong) NSMutableSet *registeredSupplementaryViewIdentifiers; +@property (nonatomic, strong) NSMutableSet *registeredSupplementaryViewNibNames; - (NSArray *)indexPathsFromSectionController:(IGListSectionController *)sectionController indexes:(NSIndexSet *)indexes diff --git a/Tests/Assets/IGTestNibSupplementaryView.xib b/Tests/Assets/IGTestNibSupplementaryView.xib new file mode 100644 index 000000000..501e79ab1 --- /dev/null +++ b/Tests/Assets/IGTestNibSupplementaryView.xib @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index af94e9493..1c186db36 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -19,6 +19,7 @@ #import "IGListTestAdapterDataSource.h" #import "IGListTestSection.h" #import "IGTestSupplementarySource.h" +#import "IGTestNibSupplementaryView.h" @interface IGListAdapterTests : XCTestCase @@ -380,6 +381,30 @@ - (void)test_whenSupplementarySourceSupportsFooter_thatHeaderViewsAreNil { XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]); } +- (void)test_whenSupplementarySourceSupportsFooter_withNibs_thatHeaderViewsAreNil { + self.dataSource.objects = @[@1, @2]; + [self.adapter reloadDataWithCompletion:nil]; + + IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new]; + supplementarySource.dequeueFromNib = YES; + supplementarySource.collectionContext = self.adapter; + supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter]; + + IGListSectionController *controller = [self.adapter sectionControllerForObject:@1]; + controller.supplementaryViewSource = supplementarySource; + supplementarySource.sectionController = controller; + + [self.adapter performUpdatesAnimated:NO completion:nil]; + + id view = [self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; + XCTAssertTrue([view isKindOfClass:IGTestNibSupplementaryView.class]); + XCTAssertEqualObjects([[(IGTestNibSupplementaryView *)view label] text], @"Foo bar baz"); + + XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]); + XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]); + XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]); +} + - (void)test_whenAdapterReleased_withSectionControllerStrongRefToCell_thatSectionControllersRelease { __weak id weakCollectionView = nil, weakAdapter = nil, weakSectionController = nil; diff --git a/Tests/Objects/IGTestNibSupplementaryView.h b/Tests/Objects/IGTestNibSupplementaryView.h new file mode 100644 index 000000000..939491419 --- /dev/null +++ b/Tests/Objects/IGTestNibSupplementaryView.h @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2016-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import + +@interface IGTestNibSupplementaryView : UICollectionViewCell + +@property (nonatomic, weak) id delegate; + +@property (nonatomic, strong) IBOutlet UILabel *label; + +@end diff --git a/Tests/Objects/IGTestNibSupplementaryView.m b/Tests/Objects/IGTestNibSupplementaryView.m new file mode 100644 index 000000000..b1aaddbb1 --- /dev/null +++ b/Tests/Objects/IGTestNibSupplementaryView.m @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2016-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "IGTestNibSupplementaryView.h" + +@implementation IGTestNibSupplementaryView + +@end diff --git a/Tests/Objects/IGTestSupplementarySource.h b/Tests/Objects/IGTestSupplementarySource.h index 68ed602e0..f6a005fdd 100644 --- a/Tests/Objects/IGTestSupplementarySource.h +++ b/Tests/Objects/IGTestSupplementarySource.h @@ -13,6 +13,8 @@ @interface IGTestSupplementarySource : NSObject +@property (nonatomic, assign) BOOL dequeueFromNib; + @property (nonatomic, strong, readwrite) NSArray *supportedElementKinds; @property (nonatomic, weak) id collectionContext; diff --git a/Tests/Objects/IGTestSupplementarySource.m b/Tests/Objects/IGTestSupplementarySource.m index fca3d0e2a..34f57e0da 100644 --- a/Tests/Objects/IGTestSupplementarySource.m +++ b/Tests/Objects/IGTestSupplementarySource.m @@ -9,16 +9,28 @@ #import "IGTestSupplementarySource.h" +#import "IGTestNibSupplementaryView.h" + @implementation IGTestSupplementarySource #pragma mark - IGListSupplementaryViewSource - (UICollectionReusableView *)viewForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index { - return [self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind - forSectionController:self.sectionController - class:[UICollectionReusableView class] - atIndex:index]; + if (self.dequeueFromNib) { + IGTestNibSupplementaryView *view = [self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind + forSectionController:self.sectionController + nibName:@"IGTestNibSupplementaryView" + bundle:[NSBundle bundleForClass:self.class] + atIndex:index]; + view.label.text = @"Foo bar baz"; + return view; + } else { + return [self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind + forSectionController:self.sectionController + class:[UICollectionReusableView class] + atIndex:index]; + } } - (CGSize)sizeForSupplementaryViewOfKind:(NSString *)elementKind atIndex:(NSInteger)index {