ASCellNode.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (c) 2014-present, Facebook, Inc.
  2. * All rights reserved.
  3. *
  4. * This source code is licensed under the BSD-style license found in the
  5. * LICENSE file in the root directory of this source tree. An additional grant
  6. * of patent rights can be found in the PATENTS file in the same directory.
  7. */
  8. #import <AsyncDisplayKit/ASDisplayNode.h>
  9. @class ASCellNode;
  10. typedef NSUInteger ASCellNodeAnimation;
  11. @protocol ASCellNodeLayoutDelegate <NSObject>
  12. /**
  13. * Notifies the delegate that the specified cell node has done a relayout.
  14. * The notification is done on main thread.
  15. *
  16. * @param node A node informing the delegate about the relayout.
  17. */
  18. - (void)nodeDidRelayout:(ASCellNode *)node;
  19. @end
  20. /**
  21. * Generic cell node. Subclass this instead of `ASDisplayNode` to use with `ASTableView` and `ASCollectionView`.
  22. */
  23. @interface ASCellNode : ASDisplayNode
  24. /**
  25. * @abstract When enabled, ensures that the cell is completely displayed before allowed onscreen.
  26. *
  27. * @default NO
  28. * @discussion Normally, ASCellNodes are preloaded and have finished display before they are onscreen.
  29. * However, if the Table or Collection's rangeTuningParameters are set to small values (or 0),
  30. * or if the user is scrolling rapidly on a slow device, it is possible for a cell's display to
  31. * be incomplete when it becomes visible.
  32. *
  33. * In this case, normally placeholder states are shown and scrolling continues uninterrupted.
  34. * The finished, drawn content is then shown as soon as it is ready.
  35. *
  36. * With this property set to YES, the main thread will be blocked until display is complete for
  37. * the cell. This is more similar to UIKit, and in fact makes AsyncDisplayKit scrolling visually
  38. * indistinguishible from UIKit's, except being faster.
  39. *
  40. * Using this option does not eliminate all of the performance advantages of AsyncDisplayKit.
  41. * Normally, a cell has been preloading and is almost done when it reaches the screen, so the
  42. * blocking time is very short. If the rangeTuningParameters are set to 0, still this option
  43. * outperforms UIKit: while the main thread is waiting, subnode display executes concurrently.
  44. */
  45. @property (nonatomic, assign) BOOL neverShowPlaceholders;
  46. /*
  47. * ASTableView uses these properties when configuring UITableViewCells that host ASCellNodes.
  48. */
  49. //@property (atomic, retain) UIColor *backgroundColor;
  50. @property (nonatomic) UITableViewCellSelectionStyle selectionStyle;
  51. /*
  52. * A Boolean value that indicates whether the node is selected.
  53. */
  54. @property (nonatomic, assign) BOOL selected;
  55. /*
  56. * A Boolean value that indicates whether the node is highlighted.
  57. */
  58. @property (nonatomic, assign) BOOL highlighted;
  59. /*
  60. * A delegate to be notified (on main thread) after a relayout.
  61. */
  62. @property (nonatomic, weak) id<ASCellNodeLayoutDelegate> layoutDelegate;
  63. /*
  64. * ASCellNode must forward touch events in order for UITableView and UICollectionView tap handling to work. Overriding
  65. * these methods (e.g. for highlighting) requires the super method be called.
  66. */
  67. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event ASDISPLAYNODE_REQUIRES_SUPER;
  68. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event ASDISPLAYNODE_REQUIRES_SUPER;
  69. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event ASDISPLAYNODE_REQUIRES_SUPER;
  70. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event ASDISPLAYNODE_REQUIRES_SUPER;
  71. /**
  72. * Marks the node as needing layout. Convenience for use whether the view / layer is loaded or not.
  73. *
  74. * If this node was measured, calling this method triggers an internal relayout: the calculated layout is invalidated,
  75. * and the supernode is notified or (if this node is the root one) a full measurement pass is executed using the old constrained size.
  76. * The delegate will then be notified on main thread.
  77. *
  78. * This method can be called inside of an animation block (to animate all of the layout changes).
  79. */
  80. - (void)setNeedsLayout;
  81. @end
  82. /**
  83. * Simple label-style cell node. Read its source for an example of custom <ASCellNode>s.
  84. */
  85. @interface ASTextCellNode : ASCellNode
  86. /**
  87. * Text to display.
  88. */
  89. @property (nonatomic, copy) NSString *text;
  90. @end