diff --git a/ASDKListKit/ASDKListKitTests/ASListTestSection.m b/ASDKListKit/ASDKListKitTests/ASListTestSection.m index 239819b14f..eac14aec0f 100644 --- a/ASDKListKit/ASDKListKitTests/ASListTestSection.m +++ b/ASDKListKit/ASDKListKitTests/ASListTestSection.m @@ -27,11 +27,13 @@ - (CGSize)sizeForItemAtIndex:(NSInteger)index { - ASDisplayNodeFailAssert(@"Did not expect %@ to be called.", NSStringFromSelector(_cmd)); - return CGSizeMake(100, 10); + return [ASIGListSectionControllerMethods sizeForItemAtIndex:index]; } -ASIGSectionControllerCellForIndexImplementation +- (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index +{ + return [ASIGListSectionControllerMethods cellForItemAtIndex:index sectionController:self]; +} - (void)didUpdateToObject:(id)object { diff --git a/ASDKListKit/ASDKListKitTests/ASListTestSupplementarySource.m b/ASDKListKit/ASDKListKitTests/ASListTestSupplementarySource.m index 6197d2c4c8..2184258a53 100644 --- a/ASDKListKit/ASDKListKitTests/ASListTestSupplementarySource.m +++ b/ASDKListKit/ASDKListKitTests/ASListTestSupplementarySource.m @@ -11,14 +11,23 @@ @implementation ASListTestSupplementarySource -ASIGSupplementarySourceViewForSupplementaryElementImplementation(self.sectionController) -ASIGSupplementarySourceSizeForSupplementaryElementImplementation - -- (ASCellNode *)nodeForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index +- (__kindof UICollectionReusableView *)viewForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index { - ASListTestSupplementaryNode *node = [[ASListTestSupplementaryNode alloc] init]; - node.style.preferredSize = CGSizeMake(100, 10); - return node; + return [ASIGListSupplementaryViewSourceMethods viewForSupplementaryElementOfKind:elementKind atIndex:index sectionController:self.sectionController]; +} + +- (CGSize)sizeForSupplementaryViewOfKind:(NSString *)elementKind atIndex:(NSInteger)index +{ + return [ASIGListSupplementaryViewSourceMethods sizeForSupplementaryViewOfKind:elementKind atIndex:index]; +} + +- (ASCellNodeBlock)nodeBlockForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index +{ + return ^{ + ASListTestSupplementaryNode *node = [[ASListTestSupplementaryNode alloc] init]; + node.style.preferredSize = CGSizeMake(100, 10); + return node; + }; } @end diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index a682b83a8a..669519e353 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -305,6 +305,8 @@ CC034A0D1E60C3D500626263 /* ASRectTable.h in Headers */ = {isa = PBXBuildFile; fileRef = CC034A0B1E60C3D500626263 /* ASRectTable.h */; }; CC034A0E1E60C3D500626263 /* ASRectTable.m in Sources */ = {isa = PBXBuildFile; fileRef = CC034A0C1E60C3D500626263 /* ASRectTable.m */; }; CC034A101E60C9BF00626263 /* ASRectTableTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC034A0F1E60C9BF00626263 /* ASRectTableTests.m */; }; + CC034A131E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = CC034A111E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.h */; }; + CC034A141E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = CC034A121E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.m */; }; CC051F1F1D7A286A006434CB /* ASCALayerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC051F1E1D7A286A006434CB /* ASCALayerTests.m */; }; CC0AEEA41D66316E005D1C78 /* ASUICollectionViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC0AEEA31D66316E005D1C78 /* ASUICollectionViewTests.m */; }; CC0F885B1E42807F00576FED /* ASCollectionViewFlowLayoutInspector.m in Sources */ = {isa = PBXBuildFile; fileRef = CC0F88591E42807F00576FED /* ASCollectionViewFlowLayoutInspector.m */; }; @@ -693,6 +695,8 @@ CC034A0B1E60C3D500626263 /* ASRectTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASRectTable.h; sourceTree = ""; }; CC034A0C1E60C3D500626263 /* ASRectTable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASRectTable.m; sourceTree = ""; }; CC034A0F1E60C9BF00626263 /* ASRectTableTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASRectTableTests.m; sourceTree = ""; }; + CC034A111E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AsyncDisplayKit+IGListKitMethods.h"; sourceTree = ""; }; + CC034A121E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AsyncDisplayKit+IGListKitMethods.m"; sourceTree = ""; }; CC051F1E1D7A286A006434CB /* ASCALayerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCALayerTests.m; sourceTree = ""; }; CC0AEEA31D66316E005D1C78 /* ASUICollectionViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASUICollectionViewTests.m; sourceTree = ""; }; CC0F88591E42807F00576FED /* ASCollectionViewFlowLayoutInspector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCollectionViewFlowLayoutInspector.m; sourceTree = ""; }; @@ -740,7 +744,6 @@ CCE04B201E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "IGListAdapter+AsyncDisplayKit.h"; sourceTree = ""; }; CCE04B211E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "IGListAdapter+AsyncDisplayKit.m"; sourceTree = ""; }; CCE04B2B1E314A32006AEBBB /* ASSupplementaryNodeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASSupplementaryNodeSource.h; sourceTree = ""; }; - CCF92DCC1E3155180019E9C6 /* ASIGListKitMethodImplementations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIGListKitMethodImplementations.h; sourceTree = ""; }; D3779BCFF841AD3EB56537ED /* Pods-AsyncDisplayKitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AsyncDisplayKitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests.release.xcconfig"; sourceTree = ""; }; D785F6601A74327E00291744 /* ASScrollNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASScrollNode.h; sourceTree = ""; }; D785F6611A74327E00291744 /* ASScrollNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASScrollNode.mm; sourceTree = ""; }; @@ -1350,7 +1353,8 @@ CCF92DCE1E315FC50019E9C6 /* IGListKit Support */ = { isa = PBXGroup; children = ( - CCF92DCC1E3155180019E9C6 /* ASIGListKitMethodImplementations.h */, + CC034A111E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.h */, + CC034A121E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.m */, CCE04B201E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.h */, CCE04B211E313EB9006AEBBB /* IGListAdapter+AsyncDisplayKit.m */, ); @@ -1490,6 +1494,7 @@ DEC146B71C37A16A004A0EE7 /* ASCollectionInternal.h in Headers */, 68B8A4E21CBDB958007E4543 /* ASWeakProxy.h in Headers */, 9F98C0271DBE29FC00476D92 /* ASControlTargetAction.h in Headers */, + CC034A131E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.h in Headers */, 690ED5961E36D118000627C0 /* ASControlNode+tvOS.h in Headers */, 695943401D70815300B0EE1F /* ASDisplayNodeLayout.h in Headers */, 0442850E1BAA64EC00D16268 /* ASMultidimensionalArrayUtils.h in Headers */, @@ -1921,6 +1926,7 @@ B350620E1B010EFD0018CF92 /* ASTextNode.mm in Sources */, 6959433F1D70815300B0EE1F /* ASDisplayNodeLayout.mm in Sources */, 68355B3E1CB57A60001D4E68 /* ASPINRemoteImageDownloader.m in Sources */, + CC034A141E649F1300626263 /* AsyncDisplayKit+IGListKitMethods.m in Sources */, 509E68661B3AEDD7009B9150 /* CoreGraphics+ASConvenience.m in Sources */, 254C6B871BF94F8A003EC431 /* ASTextKitEntityAttribute.m in Sources */, 34566CB31BC1213700715E6B /* ASPhotosFrameworkImageRequest.m in Sources */, diff --git a/Source/ASIGListKitMethodImplementations.h b/Source/ASIGListKitMethodImplementations.h deleted file mode 100644 index 0caac0434a..0000000000 --- a/Source/ASIGListKitMethodImplementations.h +++ /dev/null @@ -1,66 +0,0 @@ -// -// ASIGListKitMethodImplementations.h -// AsyncDisplayKit -// -// Created by Adlai Holler on 1/19/17. -// Copyright © 2017 Facebook. All rights reserved. -// - -/** - * If you are using AsyncDisplayKit with IGListKit, you should use - * these macros to provide implementations of methods like - * -cellForItemAtIndex: that don't apply when used with AsyncDisplayKit. - * - * Your section controllers should also conform to @c ASSectionController and your - * supplementary view sources should conform to @c ASSupplementaryNodeSource. - */ - -#if IG_LIST_KIT - -#import - -/** - * The implementation of viewForSupplementaryElementOfKind that connects - * IGSupplementaryViewSource to AsyncDisplayKit. Add this into the .m file - * for your `ASIGListSupplementaryViewSource` and implement the ASDK-specific - * method `nodeForSupplementaryElementOfKind:` to provide your node. - * - * @param sectionController The section controller this supplementary source is - * working on behalf of. For example, `self` or `self.sectionController`. - */ -#define ASIGSupplementarySourceViewForSupplementaryElementImplementation(sectionController) \ -- (__kindof UICollectionReusableView *)viewForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index { \ - return [self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind forSectionController:sectionController class:[UICollectionReusableView class] atIndex:index]; \ -} - -/** - * The implementation of sizeForSupplementaryViewOfKind that connects - * IGSupplementaryViewSource to AsyncDisplayKit. Add this into the .m file - * for your `ASIGListSupplementaryViewSource` and implement the ASDK-specific - * method `nodeForSupplementaryElementOfKind:` to provide your node which should - * size itself. You can set `node.style.preferredSize` if you want to fix the size. - * - * @param sectionController The section controller this supplementary source is - * working on behalf of. For example, `self` or `self.sectionController`. - */ -#define ASIGSupplementarySourceSizeForSupplementaryElementImplementation \ -- (CGSize)sizeForSupplementaryViewOfKind:(NSString *)elementKind atIndex:(NSInteger)index {\ - ASDisplayNodeFailAssert(@"Did not expect %@ to be called.", NSStringFromSelector(_cmd)); \ - return CGSizeZero; \ -} - - -#define ASIGSectionControllerCellForIndexImplementation \ -- (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index\ -{\ - return [self.collectionContext dequeueReusableCellOfClass:[_ASCollectionViewCell class] forSectionController:self atIndex:index]; \ -}\ - -#define ASIGSectionControllerSizeForItemImplementation \ -- (CGSize)sizeForItemAtIndex:(NSInteger)index \ -{\ - ASDisplayNodeFailAssert(@"Did not expect %@ to be called.", NSStringFromSelector(_cmd)); \ - return CGSizeZero;\ -} - -#endif // IG_LIST_KIT diff --git a/Source/AsyncDisplayKit+IGListKitMethods.h b/Source/AsyncDisplayKit+IGListKitMethods.h new file mode 100644 index 0000000000..5bc08f613b --- /dev/null +++ b/Source/AsyncDisplayKit+IGListKitMethods.h @@ -0,0 +1,61 @@ +// +// AsyncDisplayKit+IGListKitMethods.h +// AsyncDisplayKit +// +// Created by Adlai Holler on 2/27/17. +// Copyright © 2017 Facebook. All rights reserved. +// + +#if IG_LIST_KIT + +#import +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * If you are using AsyncDisplayKit with IGListKit, you should use + * these methods to provide implementations for methods like + * -cellForItemAtIndex: that don't apply when used with AsyncDisplayKit. + * + * Your section controllers should also conform to @c ASSectionController and your + * supplementary view sources should conform to @c ASSupplementaryNodeSource. + */ + +AS_SUBCLASSING_RESTRICTED +@interface ASIGListSectionControllerMethods : NSObject + +/** + * Call this for your section controller's @c cellForItemAtIndex: method. + */ ++ (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController:(IGListSectionController *)sectionController; + +/** + * Call this for your section controller's @c sizeForItemAtIndex: method. + */ ++ (CGSize)sizeForItemAtIndex:(NSInteger)index; + +@end + +AS_SUBCLASSING_RESTRICTED +@interface ASIGListSupplementaryViewSourceMethods : NSObject + +/** + * Call this for your supplementary source's @c viewForSupplementaryElementOfKind:atIndex: method. + */ ++ (__kindof UICollectionReusableView *)viewForSupplementaryElementOfKind:(NSString *)elementKind + atIndex:(NSInteger)index + sectionController:(IGListSectionController *)sectionController; + +/** + * Call this for your supplementary source's @c sizeForSupplementaryViewOfKind:atIndex: method. + */ ++ (CGSize)sizeForSupplementaryViewOfKind:(NSString *)elementKind atIndex:(NSInteger)index; + +@end + +NS_ASSUME_NONNULL_END + +#endif diff --git a/Source/AsyncDisplayKit+IGListKitMethods.m b/Source/AsyncDisplayKit+IGListKitMethods.m new file mode 100644 index 0000000000..a4ac764c53 --- /dev/null +++ b/Source/AsyncDisplayKit+IGListKitMethods.m @@ -0,0 +1,47 @@ +// +// AsyncDisplayKit+IGListKitMethods.m +// AsyncDisplayKit +// +// Created by Adlai Holler on 2/27/17. +// Copyright © 2017 Facebook. All rights reserved. +// + +#if IG_LIST_KIT + +#import "AsyncDisplayKit+IGListKitMethods.h" +#import +#import + +@implementation ASIGListSectionControllerMethods + ++ (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController:(IGListSectionController *)sectionController +{ + return [sectionController.collectionContext dequeueReusableCellOfClass:[_ASCollectionViewCell class] forSectionController:sectionController atIndex:index]; +} + ++ (CGSize)sizeForItemAtIndex:(NSInteger)index +{ + ASDisplayNodeFailAssert(@"Did not expect %@ to be called.", NSStringFromSelector(_cmd)); + return CGSizeZero; +} + +@end + +@implementation ASIGListSupplementaryViewSourceMethods + ++ (__kindof UICollectionReusableView *)viewForSupplementaryElementOfKind:(NSString *)elementKind + atIndex:(NSInteger)index + sectionController:(IGListSectionController *)sectionController +{ + return [sectionController.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind forSectionController:sectionController class:[UICollectionReusableView class] atIndex:index]; +} + ++ (CGSize)sizeForSupplementaryViewOfKind:(NSString *)elementKind atIndex:(NSInteger)index +{ + ASDisplayNodeFailAssert(@"Did not expect %@ to be called.", NSStringFromSelector(_cmd)); + return CGSizeZero; +} + +@end + +#endif // IG_LIST_KIT diff --git a/Source/AsyncDisplayKit.h b/Source/AsyncDisplayKit.h index 0a0708c7bd..45c406c869 100644 --- a/Source/AsyncDisplayKit.h +++ b/Source/AsyncDisplayKit.h @@ -40,7 +40,7 @@ #import #if IG_LIST_KIT #import -#import +#import #endif #import diff --git a/examples/ASDKgram/Sample/PhotoFeedSectionController.m b/examples/ASDKgram/Sample/PhotoFeedSectionController.m index 07be3dcd93..190a817853 100644 --- a/examples/ASDKgram/Sample/PhotoFeedSectionController.m +++ b/examples/ASDKgram/Sample/PhotoFeedSectionController.m @@ -36,9 +36,15 @@ [self setItems:_photoFeed.photos animated:NO completion:nil]; } +- (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index +{ + return [ASIGListSectionControllerMethods cellForItemAtIndex:index sectionController:self]; +} -ASIGSectionControllerSizeForItemImplementation; -ASIGSectionControllerCellForIndexImplementation; +- (CGSize)sizeForItemAtIndex:(NSInteger)index +{ + return [ASIGListSectionControllerMethods sizeForItemAtIndex:index]; +} - (void)didSelectItemAtIndex:(NSInteger)index { @@ -120,7 +126,14 @@ ASIGSectionControllerCellForIndexImplementation; return @[ UICollectionElementKindSectionHeader ]; } -ASIGSupplementarySourceViewForSupplementaryElementImplementation(self); -ASIGSupplementarySourceSizeForSupplementaryElementImplementation; +- (__kindof UICollectionReusableView *)viewForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index +{ + return [ASIGListSupplementaryViewSourceMethods viewForSupplementaryElementOfKind:elementKind atIndex:index sectionController:self]; +} + +- (CGSize)sizeForSupplementaryViewOfKind:(NSString *)elementKind atIndex:(NSInteger)index +{ + return [ASIGListSupplementaryViewSourceMethods sizeForSupplementaryViewOfKind:elementKind atIndex:index]; +} @end