Merge in downstream changes.

Introduce `ASTableView`, a UITableView subclass that uses `ASCellNode`
instead of UITableViewCell.  Add working range support via
`ASRangeController`, which observes the visible range, maintains a
working range, and handles most ASDK machinery.  ASRangeController is
loosely-enough coupled that it should be easily adapted to
UICollectionView if that's desired in the future.

Notable considerations in the ASRangeController architecture:

* There's no sense rewriting UITableView -- the real win comes from
  using nodes instead of UITableViewCells (easily parallelisable
  computation, large number of cells vs. few table views, etc.).  So,
  use a UITableView with empty cells, using UITableViewCell's
  contentView as a host for arbitrary node hierarchies.

* Instead of lazy-loading cells the instant they're needed by
  UITableView, load them in advance.  Preload a substantial number of
  nodes in the direction of scroll, as well as a small buffer in the
  other direction.

* Maintain compatibility with UITableView's API, with one primary change
  -- consumer code yields configured ASCellNodes, not UITableViewCells.

* Don't use -tableView:heightForRowAtIndexPath:.  Nodes already compute
  their preferred sizes and cache results for use at layout-time, so
  ASTableView uses their calculatedSizes directly.

* Corollary:  ASTableView is only aware of nodes that have been sized.
  This means that, if a cell appears onscreen, it has layout data and
  can display a "realistic placeholder", e.g. by making its subnodes'
  background colour grey.

Other improvements:

* Remove dead references and update headers (fixes #7, #20).

* Rename `-[ASDisplayNode sizeToFit:]` to `-measure:` and fix
  `constrainedSizeForCalulatedSize` typo (fixes #15).

* Rename `-willAppear` and `-didDisappear` to `-willEnterHierarchy` and
  `-didExitHierarchy`.  Remove `-willDisappear` -- it was redundant, and
  there was no counterpart `-didAppear`.

* Rename `viewLoaded` to `nodeLoaded`.
This commit is contained in:
Nadine Salter
2014-09-22 14:16:28 -07:00
parent 0053e00a52
commit 7dd94a6102
19 changed files with 1821 additions and 232 deletions

View File

@@ -16,9 +16,7 @@
* An `ASDisplayNode` is an abstraction over `UIView` and `CALayer` that allows you to perform calculations about a view
* hierarchy off the main thread, and could do rendering off the main thread as well.
*
* The node API is designed to be as similar as possible to `UIView`.
*
* TODO add more details + example
* The node API is designed to be as similar as possible to `UIView`. See the README for examples.
*
* ## Subclassing
*
@@ -97,11 +95,11 @@
@property (nonatomic, readonly, retain) UIView *view;
/**
* @abstract Returns whether a view is loaded.
* @abstract Returns whether a node's backing view or layer is loaded.
*
* @return YES if a view is loaded, or if isLayerBacked is YES and layer is not nil; NO otherwise.
*/
@property (atomic, readonly, assign, getter=isViewLoaded) BOOL viewLoaded; //TODO Rename to isBackingLoaded?
@property (atomic, readonly, assign, getter=isNodeLoaded) BOOL nodeLoaded;
/**
* @abstract Returns whether the node rely on a layer instead of a view.
@@ -140,13 +138,13 @@
*
* @see calculateSizeThatFits:
*/
- (CGSize)sizeToFit:(CGSize)constrainedSize; //TODO UIView names it sizeThatFits ("that" instead of "to")
- (CGSize)measure:(CGSize)constrainedSize;
/**
* @abstract Return the calculated size.
*
* @discussion Ideal for use by subclasses in -layout, having already prompted their subnodes to calculate their size by
* calling -sizeToFit: on them in -calculateSizeThatFits:.
* calling -measure: on them in -calculateSizeThatFits:.
*
* @return Size already calculated by calculateSizeThatFits:.
*
@@ -159,7 +157,7 @@
*
* @return The constrained size used by calculateSizeThatFits:.
*/
@property (nonatomic, readonly, assign) CGSize constrainedSizeForCalulatedSize;
@property (nonatomic, readonly, assign) CGSize constrainedSizeForCalculatedSize;
/** @name Managing the nodes hierarchy */
@@ -269,16 +267,11 @@
/** @name Observing node-related changes */
// TODO rename these to the UIView selectors, willMoveToSuperview etc
// Called just before the view is added to a superview.
- (void)willAppear;
- (void)willEnterHierarchy;
// Called after the view is removed from the window
- (void)willDisappear;
// Called after the view is removed from the window
- (void)didDisappear;
// Called after the view is removed from the window.
- (void)didExitHierarchy;
/** @name Drawing and Updating the View */