ASTableView.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //
  2. // ASTableView.h
  3. // AsyncDisplayKit
  4. //
  5. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  6. // This source code is licensed under the BSD-style license found in the
  7. // LICENSE file in the root directory of this source tree. An additional grant
  8. // of patent rights can be found in the PATENTS file in the same directory.
  9. //
  10. #import <UIKit/UIKit.h>
  11. #import <AsyncDisplayKit/ASRangeController.h>
  12. #import <AsyncDisplayKit/ASTableViewProtocols.h>
  13. #import <AsyncDisplayKit/ASBaseDefines.h>
  14. #import <AsyncDisplayKit/ASBatchContext.h>
  15. NS_ASSUME_NONNULL_BEGIN
  16. @class ASCellNode;
  17. @protocol ASTableDataSource;
  18. @protocol ASTableDelegate;
  19. @class ASTableNode;
  20. /**
  21. * Asynchronous UITableView with Intelligent Preloading capabilities.
  22. *
  23. * @discussion ASTableView is a true subclass of UITableView, meaning it is pointer-compatible with code that
  24. * currently uses UITableView
  25. *
  26. * The main difference is that asyncDataSource expects -nodeForRowAtIndexPath, an ASCellNode, and
  27. * the heightForRowAtIndexPath: method is eliminated (as are the performance problems caused by it).
  28. * This is made possible because ASCellNodes can calculate their own size, and preload ahead of time.
  29. *
  30. * @note ASTableNode is strongly recommended over ASTableView. This class is provided for adoption convenience.
  31. */
  32. @interface ASTableView : UITableView
  33. /// The corresponding table node, or nil if one does not exist.
  34. @property (nonatomic, weak, readonly) ASTableNode *tableNode;
  35. /**
  36. * Retrieves the node for the row at the given index path.
  37. */
  38. - (nullable ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
  39. /**
  40. * YES to automatically adjust the contentOffset when cells are inserted or deleted "before"
  41. * visible cells, maintaining the users' visible scroll position. Currently this feature tracks insertions, moves and deletions of
  42. * cells, but section edits are ignored.
  43. *
  44. * default is NO.
  45. */
  46. @property (nonatomic) BOOL automaticallyAdjustsContentOffset;
  47. /**
  48. * The number of screens left to scroll before the delegate -tableView:beginBatchFetchingWithContext: is called.
  49. *
  50. * Defaults to two screenfuls.
  51. */
  52. @property (nonatomic, assign) CGFloat leadingScreensForBatching;
  53. /*
  54. * A Boolean value that determines whether the nodes that the data source renders will be flipped.
  55. */
  56. @property (nonatomic, assign) BOOL inverted;
  57. @end
  58. @interface ASTableView (Deprecated)
  59. @property (nonatomic, weak) id<ASTableDelegate> asyncDelegate ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's .delegate property instead.");
  60. @property (nonatomic, weak) id<ASTableDataSource> asyncDataSource ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode .dataSource property instead.");
  61. /**
  62. * Initializer.
  63. *
  64. * @param frame A rectangle specifying the initial location and size of the table view in its superview’€™s coordinates.
  65. * The frame of the table view changes as table cells are added and deleted.
  66. *
  67. * @param style A constant that specifies the style of the table view. See UITableViewStyle for descriptions of valid constants.
  68. */
  69. - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style ASDISPLAYNODE_DEPRECATED_MSG("Please use ASTableNode instead of ASTableView.");
  70. /**
  71. * Tuning parameters for a range type in full mode.
  72. *
  73. * @param rangeType The range type to get the tuning parameters for.
  74. *
  75. * @return A tuning parameter value for the given range type in full mode.
  76. *
  77. * @see ASLayoutRangeMode
  78. * @see ASLayoutRangeType
  79. */
  80. - (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  81. /**
  82. * Set the tuning parameters for a range type in full mode.
  83. *
  84. * @param tuningParameters The tuning parameters to store for a range type.
  85. * @param rangeType The range type to set the tuning parameters for.
  86. *
  87. * @see ASLayoutRangeMode
  88. * @see ASLayoutRangeType
  89. */
  90. - (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  91. /**
  92. * Tuning parameters for a range type in the specified mode.
  93. *
  94. * @param rangeMode The range mode to get the running parameters for.
  95. * @param rangeType The range type to get the tuning parameters for.
  96. *
  97. * @return A tuning parameter value for the given range type in the given mode.
  98. *
  99. * @see ASLayoutRangeMode
  100. * @see ASLayoutRangeType
  101. */
  102. - (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  103. /**
  104. * Set the tuning parameters for a range type in the specified mode.
  105. *
  106. * @param tuningParameters The tuning parameters to store for a range type.
  107. * @param rangeMode The range mode to set the running parameters for.
  108. * @param rangeType The range type to set the tuning parameters for.
  109. *
  110. * @see ASLayoutRangeMode
  111. * @see ASLayoutRangeType
  112. */
  113. - (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  114. - (nullable __kindof UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  115. - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  116. - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  117. @property (nonatomic, readonly, nullable) NSIndexPath *indexPathForSelectedRow ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");
  118. @property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForSelectedRows ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");
  119. @property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForVisibleRows ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode property instead.");
  120. - (nullable NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  121. - (nullable NSArray<NSIndexPath *> *)indexPathsForRowsInRect:(CGRect)rect ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  122. /**
  123. * Similar to -visibleCells.
  124. *
  125. * @return an array containing the cell nodes being displayed on screen.
  126. */
  127. - (NSArray<ASCellNode *> *)visibleNodes AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  128. /**
  129. * Similar to -indexPathForCell:.
  130. *
  131. * @param cellNode a cellNode part of the table view
  132. *
  133. * @return an indexPath for this cellNode
  134. */
  135. - (nullable NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  136. /**
  137. * Reload everything from scratch, destroying the working range and all cached nodes.
  138. *
  139. * @param completion block to run on completion of asynchronous loading or nil. If supplied, the block is run on
  140. * the main thread.
  141. * @warning This method is substantially more expensive than UITableView's version.
  142. */
  143. -(void)reloadDataWithCompletion:(void (^ _Nullable)())completion ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  144. /**
  145. * Reload everything from scratch, destroying the working range and all cached nodes.
  146. *
  147. * @warning This method is substantially more expensive than UITableView's version.
  148. */
  149. - (void)reloadData ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  150. /**
  151. * Reload everything from scratch entirely on the main thread, destroying the working range and all cached nodes.
  152. *
  153. * @warning This method is substantially more expensive than UITableView's version and will block the main thread while
  154. * all the cells load.
  155. */
  156. - (void)reloadDataImmediately ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's reloadDataWithCompletion: followed by ASTableNode's -waitUntilAllUpdatesAreCommitted instead.");
  157. /**
  158. * Triggers a relayout of all nodes.
  159. *
  160. * @discussion This method invalidates and lays out every cell node in the table view.
  161. */
  162. - (void)relayoutItems ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  163. - (void)beginUpdates ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's -performBatchUpdates:completion: instead.");
  164. - (void)endUpdates ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's -performBatchUpdates:completion: instead.");
  165. /**
  166. * Concludes a series of method calls that insert, delete, select, or reload rows and sections of the table view.
  167. * You call this method to bracket a series of method calls that begins with beginUpdates and that consists of operations
  168. * to insert, delete, select, and reload rows and sections of the table view. When you call endUpdates, ASTableView begins animating
  169. * the operations simultaneously. This method is must be called from the main thread. It's important to remember that the ASTableView will
  170. * be processing the updates asynchronously after this call and are not guaranteed to be reflected in the ASTableView until
  171. * the completion block is executed.
  172. *
  173. * @param animated NO to disable all animations.
  174. * @param completion A completion handler block to execute when all of the operations are finished. This block takes a single
  175. * Boolean parameter that contains the value YES if all of the related animations completed successfully or
  176. * NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread.
  177. */
  178. - (void)endUpdatesAnimated:(BOOL)animated completion:(void (^ _Nullable)(BOOL completed))completion ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's -performBatchUpdates:completion: instead.");
  179. /**
  180. * Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread.
  181. */
  182. - (void)waitUntilAllUpdatesAreCommitted ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  183. - (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  184. - (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  185. - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  186. - (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  187. - (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  188. - (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  189. - (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  190. - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode method instead.");
  191. /// Deprecated in 2.0. You should not call this method.
  192. - (void)clearContents ASDISPLAYNODE_DEPRECATED_MSG("You should not call this method directly. Intead, rely on the Interstate State callback methods.");
  193. /// Deprecated in 2.0. You should not call this method.
  194. - (void)clearFetchedData ASDISPLAYNODE_DEPRECATED_MSG("You should not call this method directly. Intead, rely on the Interstate State callback methods.");
  195. @end
  196. ASDISPLAYNODE_DEPRECATED_MSG("Renamed to ASTableDataSource.")
  197. @protocol ASTableViewDataSource <ASTableDataSource>
  198. @end
  199. ASDISPLAYNODE_DEPRECATED_MSG("Renamed to ASTableDelegate.")
  200. @protocol ASTableViewDelegate <ASTableDelegate>
  201. @end
  202. NS_ASSUME_NONNULL_END