ASPagerNode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // ASPagerNode.h
  3. // AsyncDisplayKit
  4. //
  5. // Created by Levi McCallum on 12/7/15.
  6. //
  7. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  8. // This source code is licensed under the BSD-style license found in the
  9. // LICENSE file in the root directory of this source tree. An additional grant
  10. // of patent rights can be found in the PATENTS file in the same directory.
  11. //
  12. #import <AsyncDisplayKit/ASCollectionNode.h>
  13. @class ASPagerNode;
  14. @class ASPagerFlowLayout;
  15. NS_ASSUME_NONNULL_BEGIN
  16. #define ASPagerNodeDataSource ASPagerDataSource
  17. @protocol ASPagerDataSource <NSObject>
  18. /**
  19. * This method replaces -collectionView:numberOfItemsInSection:
  20. *
  21. * @param pagerNode The sender.
  22. * @return The total number of pages that can display in the pagerNode.
  23. */
  24. - (NSInteger)numberOfPagesInPagerNode:(ASPagerNode *)pagerNode;
  25. @optional
  26. /**
  27. * This method replaces -collectionView:nodeForItemAtIndexPath:
  28. *
  29. * @param pagerNode The sender.
  30. * @param index The index of the requested node.
  31. * @return a node for display at this index. This will be called on the main thread and should
  32. * not implement reuse (it will be called once per row). Unlike UICollectionView's version,
  33. * this method is not called when the row is about to display.
  34. */
  35. - (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index;
  36. /**
  37. * This method replaces -collectionView:nodeBlockForItemAtIndexPath:
  38. * This method takes precedence over pagerNode:nodeAtIndex: if implemented.
  39. *
  40. * @param pagerNode The sender.
  41. * @param index The index of the requested node.
  42. * @return a block that creates the node for display at this index.
  43. * Must be thread-safe (can be called on the main thread or a background
  44. * queue) and should not implement reuse (it will be called once per row).
  45. */
  46. - (ASCellNodeBlock)pagerNode:(ASPagerNode *)pagerNode nodeBlockAtIndex:(NSInteger)index;
  47. @end
  48. @protocol ASPagerDelegate <ASCollectionDelegate>
  49. @optional
  50. /**
  51. * Provides the constrained size range for measuring the node at the index.
  52. *
  53. * @param pagerNode The sender.
  54. * @param index The index of the node.
  55. * @return A constrained size range for layout the node at this index.
  56. */
  57. - (ASSizeRange)pagerNode:(ASPagerNode *)pagerNode constrainedSizeForNodeAtIndex:(NSInteger)index;
  58. @end
  59. @interface ASPagerNode : ASCollectionNode
  60. /**
  61. * Configures a default horizontal, paging flow layout with 0 inter-item spacing.
  62. */
  63. - (instancetype)init;
  64. /**
  65. * Initializer with custom-configured flow layout properties.
  66. */
  67. - (instancetype)initWithCollectionViewLayout:(ASPagerFlowLayout *)flowLayout;
  68. /**
  69. * Data Source is required, and uses a different protocol from ASCollectionNode.
  70. */
  71. - (void)setDataSource:(nullable id <ASPagerDataSource>)dataSource;
  72. - (nullable id <ASPagerDataSource>)dataSource AS_WARN_UNUSED_RESULT;
  73. /**
  74. * Delegate is optional.
  75. * This includes UIScrollViewDelegate as well as most methods from UICollectionViewDelegate, like willDisplay...
  76. */
  77. - (void)setDelegate:(nullable id <ASPagerDelegate>)delegate;
  78. - (nullable id <ASPagerDelegate>)delegate AS_WARN_UNUSED_RESULT;
  79. /**
  80. * The underlying ASCollectionView object.
  81. */
  82. @property (nonatomic, readonly) ASCollectionView *view;
  83. /**
  84. * Returns the current page index
  85. */
  86. @property (nonatomic, assign, readonly) NSInteger currentPageIndex;
  87. /**
  88. * Scroll the contents of the receiver to ensure that the page is visible
  89. */
  90. - (void)scrollToPageAtIndex:(NSInteger)index animated:(BOOL)animated;
  91. /**
  92. * Returns the node for the passed page index
  93. */
  94. - (ASCellNode *)nodeForPageAtIndex:(NSInteger)index AS_WARN_UNUSED_RESULT;
  95. /**
  96. * Returns the index of the page for the cell passed or NSNotFound
  97. */
  98. - (NSInteger)indexOfPageWithNode:(ASCellNode *)node;
  99. @end
  100. NS_ASSUME_NONNULL_END