ASIGListKitMethodImplementations.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // ASIGListKitMethodImplementations.h
  3. // AsyncDisplayKit
  4. //
  5. // Created by Adlai Holler on 1/19/17.
  6. // Copyright © 2017 Facebook. All rights reserved.
  7. //
  8. /**
  9. * If you are using AsyncDisplayKit with IGListKit, you should use
  10. * these macros to provide implementations of methods like
  11. * -cellForItemAtIndex: that don't apply when used with AsyncDisplayKit.
  12. *
  13. * Your section controllers should also conform to @c ASSectionController and your
  14. * supplementary view sources should conform to @c ASSupplementaryNodeSource.
  15. */
  16. #if IG_LIST_KIT
  17. #import <AsyncDisplayKit/_ASCollectionViewCell.h>
  18. /**
  19. * The implementation of viewForSupplementaryElementOfKind that connects
  20. * IGSupplementaryViewSource to AsyncDisplayKit. Add this into the .m file
  21. * for your `ASIGListSupplementaryViewSource` and implement the ASDK-specific
  22. * method `nodeForSupplementaryElementOfKind:` to provide your node.
  23. *
  24. * @param sectionController The section controller this supplementary source is
  25. * working on behalf of. For example, `self` or `self.sectionController`.
  26. */
  27. #define ASIGSupplementarySourceViewForSupplementaryElementImplementation(sectionController) \
  28. - (__kindof UICollectionReusableView *)viewForSupplementaryElementOfKind:(NSString *)elementKind atIndex:(NSInteger)index { \
  29. return [self.collectionContext dequeueReusableSupplementaryViewOfKind:elementKind forSectionController:sectionController class:[UICollectionReusableView class] atIndex:index]; \
  30. }
  31. /**
  32. * The implementation of sizeForSupplementaryViewOfKind that connects
  33. * IGSupplementaryViewSource to AsyncDisplayKit. Add this into the .m file
  34. * for your `ASIGListSupplementaryViewSource` and implement the ASDK-specific
  35. * method `nodeForSupplementaryElementOfKind:` to provide your node which should
  36. * size itself. You can set `node.style.preferredSize` if you want to fix the size.
  37. *
  38. * @param sectionController The section controller this supplementary source is
  39. * working on behalf of. For example, `self` or `self.sectionController`.
  40. */
  41. #define ASIGSupplementarySourceSizeForSupplementaryElementImplementation \
  42. - (CGSize)sizeForSupplementaryViewOfKind:(NSString *)elementKind atIndex:(NSInteger)index {\
  43. ASDisplayNodeFailAssert(@"Did not expect %@ to be called.", NSStringFromSelector(_cmd)); \
  44. return CGSizeZero; \
  45. }
  46. #define ASIGSectionControllerCellForIndexImplementation \
  47. - (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index\
  48. {\
  49. return [self.collectionContext dequeueReusableCellOfClass:[_ASCollectionViewCell class] forSectionController:self atIndex:index]; \
  50. }\
  51. #define ASIGSectionControllerSizeForItemImplementation \
  52. - (CGSize)sizeForItemAtIndex:(NSInteger)index \
  53. {\
  54. ASDisplayNodeFailAssert(@"Did not expect %@ to be called.", NSStringFromSelector(_cmd)); \
  55. return CGSizeZero;\
  56. }
  57. #endif // IG_LIST_KIT