Swiftgram/docs/_docs/layout-options.md
Garrett Moon 5c8b31684a Rename AsyncDisplayKit to Texture (#4)
* Rename AsyncDisplayKit to Texture

* More renaming
2017-04-14 09:37:38 -07:00

1.6 KiB
Executable File

title layout permalink prevPage nextPage
Layout Options docs /docs/layout-options.html automatic-layout-debugging.html layer-backing.html

When using Texture, you have three options for layout. Note that UIKit Autolayout is not supported by Texture. #Manual Sizing & Layout

This original layout method shipped with Texture 1.0 and is analogous to UIKit's layout methods. Use this method for ASViewControllers (unless you subclass the node).

[ASDisplayNode calculateSizeThatFits:] vs. [UIView sizeThatFits:]

[ASDisplayNode layout] vs. [UIView layoutSubviews]

###Advantages (over UIKit)

  • Eliminates all main thread layout cost
  • Results are cached

###Shortcomings (same as UIKit):

  • Code duplication between methods
  • Logic is not reusable

#Unified Sizing & Layout

This layout method does not have a UIKit analog. It is implemented by calling

- (ASLayout *)calculateLayoutThatFits: (ASSizeRange)constraint

###Advantages

  • zero duplication
  • still async, still cached

###Shortcomings

  • logic is not reusable, and is still manual

Automatic, Extensible Layout

This is the reccomended layout method. It does not have a UIKit analog and is implemented by calling

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constraint ###Advantages

  • can reuse even complex, custom layouts
  • built-in specs provide automatic layout
  • combine to compose new layouts easily
  • still async, cached, and zero duplication

The diagram below shows how options #2 and #3 above both result in an ASLayout, except that in option #3, the ASLayout is produced automatically by the ASLayoutSpec.