Skip to content

Commit

Permalink
Support supplementaryViews created from storyboard
Browse files Browse the repository at this point in the history
Summary:
Miss this in the previous PR #92. Will add unit test soon.
Closes #123

Differential Revision: D4101594

Pulled By: rnystrom

fbshipit-source-id: 820030358532b0878f6d9e9092834266c9260a38
  • Loading branch information
Bofei Zhu authored and Facebook Github Bot committed Nov 1, 2016
1 parent 9685f2b commit 158d04e
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 27 deletions.
40 changes: 34 additions & 6 deletions IGListKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
5C81083F8E7AEF4B3EBE8871 /* Pods_IGListKitTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FD40284889DE182FFC7F471E /* Pods_IGListKitTests.framework */; };
821BC4C01DB8C9D500172ED0 /* IGListSingleStoryboardItemControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4BE1DB8C95300172ED0 /* IGListSingleStoryboardItemControllerTests.m */; };
821BC4C41DB8CEF800172ED0 /* IGTestStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 821BC4C21DB8CAE900172ED0 /* IGTestStoryboard.storyboard */; };
821BC4CB1DB8D60100172ED0 /* IGTestSingleStoryboardViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4C81DB8D5B200172ED0 /* IGTestSingleStoryboardViewController.m */; };
821BC4CB1DB8D60100172ED0 /* IGTestStoryboardViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4C81DB8D5B200172ED0 /* IGTestStoryboardViewController.m */; };
821BC4D01DB8D90900172ED0 /* IGTestStoryboardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4CD1DB8D8C500172ED0 /* IGTestStoryboardCell.m */; };
821BC4D31DB981AB00172ED0 /* IGTestSingleStoryboardItemDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4D21DB981AB00172ED0 /* IGTestSingleStoryboardItemDataSource.m */; };
8240C7F01DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8240C7EF1DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.m */; };
8240C7F21DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8240C7F11DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m */; };
8240C7F51DC2D99300B3AAE7 /* IGTestStoryboardSupplementarySource.m in Sources */ = {isa = PBXBuildFile; fileRef = 8240C7F41DC2D99300B3AAE7 /* IGTestStoryboardSupplementarySource.m */; };
8240C7F81DC2F3FB00B3AAE7 /* IGListTestStoryboardSection.m in Sources */ = {isa = PBXBuildFile; fileRef = 8240C7F71DC2F3FB00B3AAE7 /* IGListTestStoryboardSection.m */; };
8240C7FB1DC2F6CF00B3AAE7 /* IGListTestAdapterStoryboardDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 8240C7FA1DC2F6CF00B3AAE7 /* IGListTestAdapterStoryboardDataSource.m */; };
88144F071D870EDC007C7F66 /* IGListAdapterE2ETests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EE21D870EDC007C7F66 /* IGListAdapterE2ETests.m */; };
88144F081D870EDC007C7F66 /* IGListAdapterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EE31D870EDC007C7F66 /* IGListAdapterTests.m */; };
88144F091D870EDC007C7F66 /* IGListAdapterUpdaterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EE41D870EDC007C7F66 /* IGListAdapterUpdaterTests.m */; };
Expand Down Expand Up @@ -238,12 +243,21 @@
6BCA3FF59943AD1DAC2077E3 /* Pods-IGListKitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IGListKitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-IGListKitTests/Pods-IGListKitTests.release.xcconfig"; sourceTree = "<group>"; };
821BC4BE1DB8C95300172ED0 /* IGListSingleStoryboardItemControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListSingleStoryboardItemControllerTests.m; sourceTree = "<group>"; };
821BC4C21DB8CAE900172ED0 /* IGTestStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = IGTestStoryboard.storyboard; sourceTree = "<group>"; };
821BC4C71DB8D5B200172ED0 /* IGTestSingleStoryboardViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestSingleStoryboardViewController.h; sourceTree = "<group>"; };
821BC4C81DB8D5B200172ED0 /* IGTestSingleStoryboardViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestSingleStoryboardViewController.m; sourceTree = "<group>"; };
821BC4C71DB8D5B200172ED0 /* IGTestStoryboardViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestStoryboardViewController.h; sourceTree = "<group>"; };
821BC4C81DB8D5B200172ED0 /* IGTestStoryboardViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestStoryboardViewController.m; sourceTree = "<group>"; };
821BC4CC1DB8D8C500172ED0 /* IGTestStoryboardCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestStoryboardCell.h; sourceTree = "<group>"; };
821BC4CD1DB8D8C500172ED0 /* IGTestStoryboardCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestStoryboardCell.m; sourceTree = "<group>"; };
821BC4D11DB9816E00172ED0 /* IGTestSingleStoryboardItemDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestSingleStoryboardItemDataSource.h; sourceTree = "<group>"; };
821BC4D21DB981AB00172ED0 /* IGTestSingleStoryboardItemDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestSingleStoryboardItemDataSource.m; sourceTree = "<group>"; };
8240C7EE1DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestStoryboardSupplementaryView.h; sourceTree = "<group>"; };
8240C7EF1DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestStoryboardSupplementaryView.m; sourceTree = "<group>"; };
8240C7F11DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IGListAdapterStoryboardTests.m; path = Tests/IGListAdapterStoryboardTests.m; sourceTree = SOURCE_ROOT; };
8240C7F31DC2D99300B3AAE7 /* IGTestStoryboardSupplementarySource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGTestStoryboardSupplementarySource.h; sourceTree = "<group>"; };
8240C7F41DC2D99300B3AAE7 /* IGTestStoryboardSupplementarySource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGTestStoryboardSupplementarySource.m; sourceTree = "<group>"; };
8240C7F61DC2F3FB00B3AAE7 /* IGListTestStoryboardSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListTestStoryboardSection.h; sourceTree = "<group>"; };
8240C7F71DC2F3FB00B3AAE7 /* IGListTestStoryboardSection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListTestStoryboardSection.m; sourceTree = "<group>"; };
8240C7F91DC2F6CF00B3AAE7 /* IGListTestAdapterStoryboardDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListTestAdapterStoryboardDataSource.h; sourceTree = "<group>"; };
8240C7FA1DC2F6CF00B3AAE7 /* IGListTestAdapterStoryboardDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListTestAdapterStoryboardDataSource.m; sourceTree = "<group>"; };
841726B542A3E9A4BD48946F /* Pods-IGListKit-tvOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IGListKit-tvOSTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-IGListKit-tvOSTests/Pods-IGListKit-tvOSTests.debug.xcconfig"; sourceTree = "<group>"; };
88144EE21D870EDC007C7F66 /* IGListAdapterE2ETests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListAdapterE2ETests.m; sourceTree = "<group>"; };
88144EE31D870EDC007C7F66 /* IGListAdapterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListAdapterTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -401,10 +415,14 @@
children = (
88144EF11D870EDC007C7F66 /* IGListTestAdapterDataSource.h */,
88144EF21D870EDC007C7F66 /* IGListTestAdapterDataSource.m */,
8240C7F91DC2F6CF00B3AAE7 /* IGListTestAdapterStoryboardDataSource.h */,
8240C7FA1DC2F6CF00B3AAE7 /* IGListTestAdapterStoryboardDataSource.m */,
88144EF31D870EDC007C7F66 /* IGListTestOffsettingLayout.h */,
88144EF41D870EDC007C7F66 /* IGListTestOffsettingLayout.m */,
88144EF51D870EDC007C7F66 /* IGListTestSection.h */,
88144EF61D870EDC007C7F66 /* IGListTestSection.m */,
8240C7F61DC2F3FB00B3AAE7 /* IGListTestStoryboardSection.h */,
8240C7F71DC2F3FB00B3AAE7 /* IGListTestStoryboardSection.m */,
88144EF71D870EDC007C7F66 /* IGListTestUICollectionViewDataSource.h */,
88144EF81D870EDC007C7F66 /* IGListTestUICollectionViewDataSource.m */,
88144EF91D870EDC007C7F66 /* IGTestCell.h */,
Expand All @@ -421,14 +439,18 @@
26271C891DAE94E40073E116 /* IGTestSingleNibItemDataSource.m */,
821BC4D11DB9816E00172ED0 /* IGTestSingleStoryboardItemDataSource.h */,
821BC4D21DB981AB00172ED0 /* IGTestSingleStoryboardItemDataSource.m */,
821BC4C71DB8D5B200172ED0 /* IGTestSingleStoryboardViewController.h */,
821BC4C81DB8D5B200172ED0 /* IGTestSingleStoryboardViewController.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 */,
);
path = Objects;
sourceTree = "<group>";
Expand Down Expand Up @@ -540,6 +562,7 @@
294369AF1DB1B7AE0025F6E7 /* Assets */,
88144EE21D870EDC007C7F66 /* IGListAdapterE2ETests.m */,
88144EE31D870EDC007C7F66 /* IGListAdapterTests.m */,
8240C7F11DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m */,
88144EE41D870EDC007C7F66 /* IGListAdapterUpdaterTests.m */,
88144EE51D870EDC007C7F66 /* IGListBatchUpdateDataTests.m */,
88144EE61D870EDC007C7F66 /* IGListDiffSwiftTests.swift */,
Expand Down Expand Up @@ -1027,10 +1050,12 @@
88144F1C1D870EDC007C7F66 /* IGTestStackedDataSource.m in Sources */,
88144F181D870EDC007C7F66 /* IGTestDelegateController.m in Sources */,
88144F0D1D870EDC007C7F66 /* IGListDisplayHandlerTests.m in Sources */,
8240C7F51DC2D99300B3AAE7 /* IGTestStoryboardSupplementarySource.m in Sources */,
88144F1B1D870EDC007C7F66 /* IGTestSingleItemDataSource.m in Sources */,
88144F171D870EDC007C7F66 /* IGTestCell.m in Sources */,
821BC4C01DB8C9D500172ED0 /* IGListSingleStoryboardItemControllerTests.m in Sources */,
88144F141D870EDC007C7F66 /* IGListTestOffsettingLayout.m in Sources */,
8240C7FB1DC2F6CF00B3AAE7 /* IGListTestAdapterStoryboardDataSource.m in Sources */,
88144F131D870EDC007C7F66 /* IGListTestAdapterDataSource.m in Sources */,
88144F071D870EDC007C7F66 /* IGListAdapterE2ETests.m in Sources */,
88144F111D870EDC007C7F66 /* IGListStackSectionControllerTests.m in Sources */,
Expand All @@ -1046,11 +1071,14 @@
88144F151D870EDC007C7F66 /* IGListTestSection.m in Sources */,
88144F1D1D870EDC007C7F66 /* IGTestSupplementarySource.m in Sources */,
88144F081D870EDC007C7F66 /* IGListAdapterTests.m in Sources */,
821BC4CB1DB8D60100172ED0 /* IGTestSingleStoryboardViewController.m in Sources */,
8240C7F21DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m in Sources */,
8240C7F01DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.m in Sources */,
821BC4CB1DB8D60100172ED0 /* IGTestStoryboardViewController.m in Sources */,
821BC4D01DB8D90900172ED0 /* IGTestStoryboardCell.m in Sources */,
88144F161D870EDC007C7F66 /* IGListTestUICollectionViewDataSource.m in Sources */,
88144F091D870EDC007C7F66 /* IGListAdapterUpdaterTests.m in Sources */,
88144F0F1D870EDC007C7F66 /* IGListObjectMapTests.m in Sources */,
8240C7F81DC2F3FB00B3AAE7 /* IGListTestStoryboardSection.m in Sources */,
26271C8A1DAE94E40073E116 /* IGTestSingleNibItemDataSource.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
15 changes: 15 additions & 0 deletions Source/IGListAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,21 @@ - (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(N
return [collectionView dequeueReusableSupplementaryViewOfKind:elementKind withReuseIdentifier:identifier forIndexPath:indexPath];
}

- (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewFromStoryboardOfKind:(NSString *)elementKind
withIdentifier:(NSString *)identifier
forSectionController:(IGListSectionController <IGListSectionType> *)sectionController
atIndex:(NSInteger)index {
IGAssertMainThread();
IGParameterAssert(elementKind.length > 0);
IGParameterAssert(identifier.length > 0);
IGParameterAssert(sectionController != nil);
IGParameterAssert(index >= 0);
UICollectionView *collectionView = self.collectionView;
IGAssert(collectionView != nil, @"Dequeueing Supplementary View from storyboard of kind %@ with identifier %@ for section controller %@ without a collection view at index %zi", elementKind, identifier, sectionController, index);
NSIndexPath *indexPath = [self indexPathForSectionController:sectionController index:index];
return [collectionView dequeueReusableSupplementaryViewOfKind:elementKind withReuseIdentifier:identifier forIndexPath:indexPath];
}

- (void)reloadInSectionController:(IGListSectionController<IGListSectionType> *)sectionController atIndexes:(NSIndexSet *)indexes {
IGAssertMainThread();
IGParameterAssert(indexes != nil);
Expand Down
17 changes: 15 additions & 2 deletions Source/IGListCollectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ NS_ASSUME_NONNULL_BEGIN
@param index The index of the cell.
@return A cell dequeued from the reuse pool or newly created.
@note This method uses a string representation of the cell class as the identifier.
*/
- (__kindof UICollectionViewCell *)dequeueReusableCellFromStoryboardWithIdentifier:(NSString *)identifier
forSectionController:(IGListSectionController <IGListSectionType> *)sectionController
Expand All @@ -140,6 +138,21 @@ 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 identifier The identifier of the supplementary view in storyboard.
@param sectionController The section controller requesting this information.
@param index The index of the supplementary vew.
@return A supplementary view dequeued from the reuse pool or newly created.
*/
- (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewFromStoryboardOfKind:(NSString *)elementKind
withIdentifier:(NSString *)identifier
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
atIndex:(NSInteger)index;

/**
Reloads cells in the section controller.
Expand Down
15 changes: 13 additions & 2 deletions Source/IGListStackedSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ - (UICollectionViewCell *)dequeueReusableCellFromStoryboardWithIdentifier:(NSStr
atIndex:(NSInteger)index {
const NSUInteger offset = [self offsetForSectionController:sectionController];
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableCellFromStoryboardWithIdentifier:identifier
forSectionController:self
atIndex:(index + offset)];
forSectionController:self
atIndex:(index + offset)];
}

- (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind
Expand All @@ -227,6 +227,17 @@ - (UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *
atIndex:(index + offset)];
}

- (UICollectionReusableView *)dequeueReusableSupplementaryViewFromStoryboardOfKind:(NSString *)elementKind
withIdentifier:(NSString *)identifier
forSectionController:(IGListSectionController<IGListSectionType> *)sectionController
atIndex:(NSInteger)index {
const NSUInteger offset = [self offsetForSectionController:sectionController];
return (UICollectionViewCell *_Nonnull)[self.collectionContext dequeueReusableSupplementaryViewFromStoryboardOfKind:elementKind
withIdentifier:identifier
forSectionController:self
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
Loading

0 comments on commit 158d04e

Please sign in to comment.