Update docs

This commit is contained in:
Garrett Moon 2017-04-13 11:49:30 -07:00
parent 8b41c8c300
commit f67376a4c3
11 changed files with 78 additions and 56 deletions

View File

@ -22,7 +22,7 @@ nextPage: containers-aspagernode.html
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
</pre> </pre>
</div> </div>
</div> </div>
@ -37,7 +37,7 @@ with your choice of **_one_** of the following methods
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath - (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
override func collectionNode(collectionNode: ASCollectionNode, nodeForItemAtIndexPath indexPath: NSIndexPath) -> ASCellNode override func collectionNode(_ collectionNode: ASCollectionNode, nodeForItemAt indexPath: IndexPath) -> ASCellNode
</pre> </pre>
</div> </div>
</div> </div>
@ -54,7 +54,7 @@ or
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath - (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
override func collectionNode(collectionNode: ASCollectionNode, nodeBlockForItemAtIndexPath indexPath: NSIndexPath) -> ASCellNodeBlock override func collectionNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock
</pre> </pre>
</div> </div>
</div> </div>
@ -96,7 +96,7 @@ Consider the following `-collectionNode:nodeBlockForItemAtIndexPath:` method.
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func tableNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock { func collectionNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock {
guard photoFeed.count > indexPath.row else { return { ASCellNode() } } guard photoFeed.count > indexPath.row else { return { ASCellNode() } }
let photoModel = photoFeed[indexPath.row] let photoModel = photoFeed[indexPath.row]
@ -130,13 +130,13 @@ An ASCollectionNode is assigned to be managed by an `ASViewController` in its `-
<pre lang="objc" class="objcCode"> <pre lang="objc" class="objcCode">
- (instancetype)init - (instancetype)init
{ {
_flowLayout = [[UICollectionViewFlowLayout alloc] init]; _flowLayout = [[UICollectionViewFlowLayout alloc] init];
_collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:_flowLayout]; _collectionNode = [[ASCollectionNode alloc] initWithCollectionViewLayout:_flowLayout];
self = [super initWithNode:_collectionNode]; self = [super initWithNode:_collectionNode];
if (self) { if (self) {
_flowLayout.minimumInteritemSpacing = 1; _flowLayout.minimumInteritemSpacing = 1;
_flowLayout.minimumLineSpacing = 1; _flowLayout.minimumLineSpacing = 1;
} }
return self; return self;
@ -145,13 +145,13 @@ An ASCollectionNode is assigned to be managed by an `ASViewController` in its `-
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
init() { init() {
flowLayout = UICollectionViewFlowLayout() flowLayout = UICollectionViewFlowLayout()
collectionNode = ASCollectionNode(collectionViewLayout: flowLayout) collectionNode = ASCollectionNode(collectionViewLayout: flowLayout)
super.init(node: collectionNode) super.init(node: collectionNode)
flowLayout.minimumInteritemSpacing = 1 flowLayout.minimumInteritemSpacing = 1
flowLayout.minimumLineSpacing = 1 flowLayout.minimumLineSpacing = 1
} }
</pre> </pre>
</div> </div>
@ -178,7 +178,7 @@ The `LocationCollectionNodeController` above accesses the `ASCollectionView` dir
{ {
[super viewDidLoad]; [super viewDidLoad];
_collectionNode.delegate = self; _collectionNode.delegate = self;
_collectionNode.dataSource = self; _collectionNode.dataSource = self;
_collectionNode.view.allowsSelection = NO; _collectionNode.view.allowsSelection = NO;
_collectionNode.view.backgroundColor = [UIColor whiteColor]; _collectionNode.view.backgroundColor = [UIColor whiteColor];
@ -189,10 +189,10 @@ The `LocationCollectionNodeController` above accesses the `ASCollectionView` dir
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
collectionNode.delegate = self collectionNode.delegate = self
collectionNode.dataSource = self collectionNode.dataSource = self
collectionNode.view.allowsSelection = false collectionNode.view.allowsSelection = false
collectionNode.view.backgroundColor = UIColor.whiteColor() collectionNode.view.backgroundColor = .white
} }
</pre> </pre>
</div> </div>

View File

@ -20,7 +20,7 @@ The main dataSource methods are:
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func numberOfPagesInPagerNode(pagerNode: ASPagerNode!) -> Int func numberOfPages(in pagerNode: ASPagerNode) -> Int
</pre> </pre>
</div> </div>
</div> </div>
@ -35,7 +35,7 @@ and
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeAtIndex index: Int) -> ASCellNode! func pagerNode(_ pagerNode: ASPagerNode, nodeAt index: Int) -> ASCellNode
</pre> </pre>
</div> </div>
</div> </div>
@ -50,7 +50,7 @@ or
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeBlockAtIndex index: Int) -> ASCellNodeBlock! func pagerNode(_ pagerNode: ASPagerNode, nodeBlockAt index: Int) -> ASCellNodeBlock
</pre> </pre>
</div> </div>
</div> </div>
@ -86,8 +86,8 @@ In the example below, you can see how the index is used to access the photo mode
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeBlockAtIndex index: Int) -> ASCellNodeBlock! { func pagerNode(_ pagerNode: ASPagerNode, nodeBlockAt index: Int) -> ASCellNodeBlock {
guard photoFeed.count > index else { return nil } guard photoFeed.count > index else { return { ASCellNode() } }
let photoModel = photoFeed[index] let photoModel = photoFeed[index]
let cellNodeBlock = { () -> ASCellNode in let cellNodeBlock = { () -> ASCellNode in
@ -123,8 +123,8 @@ One especially useful pattern is to return an `ASCellNode` that is initialized w
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeAtIndex index: Int) -> ASCellNode! { func pagerNode(_ pagerNode: ASPagerNode, nodeAt index: Int) -> ASCellNode {
guard animals.count > index else { return nil } guard animals.count > index else { return ASCellNode() }
let animal = animals[index] let animal = animals[index]
let node = ASCellNode(viewControllerBlock: { () -> UIViewController in let node = ASCellNode(viewControllerBlock: { () -> UIViewController in

View File

@ -45,18 +45,16 @@ This table node is assigned to the `ASViewController` in its `-initWithNode:` de
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func initWithModel(models: Array&lt;Model&gt;) { init(models: [Model]) {
let tableNode = ASTableNode(style:.Plain) let tableNode = ASTableNode(style: .plain)
super.initWithNode(tableNode) super.init(node: tableNode)
self.models = models self.models = models
self.tableNode = tableNode self.tableNode = tableNode
self.tableNode.delegate = self self.tableNode.delegate = self
self.tableNode.dataSource = self self.tableNode.dataSource = self
return self
} }
</pre> </pre>
</div> </div>

View File

@ -69,8 +69,8 @@ editableTextNode.typingAttributes = @{NSForegroundColorAttributeName: [UIColor b
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
editableTextNode.typingAttributes = [NSForegroundColorAttributeName: UIColor.blueColor(), editableTextNode.typingAttributes = [NSForegroundColorAttributeName: UIColor.blue,
NSBackgroundColorAttributeName: UIColor.redColor()] NSBackgroundColorAttributeName: UIColor.red]
</pre> </pre>
</div> </div>
</div> </div>

View File

@ -27,7 +27,7 @@ imageNode.contentMode = UIViewContentModeScaleAspectFill;
let imageNode = ASImageNode() let imageNode = ASImageNode()
imageNode.image = UIImage(named: "someImage") imageNode.image = UIImage(named: "someImage")
imageNode.contentMode = .ScaleAspectFill imageNode.contentMode = .scaleAspectFill
</pre> </pre>
</div> </div>
</div> </div>

View File

@ -27,14 +27,20 @@ ASDimensionMake(@"50%");
ASDimensionMakeWithFraction(0.5); ASDimensionMakeWithFraction(0.5);
<b>// dimension returned in points</b> <b>// dimension returned in points</b>
ASDimensionMake(@"70pt") ASDimensionMake(@"70pt");
ASDimensionMake(70); ASDimensionMake(70);
ASDimensionMakeWithPoints(70); ASDimensionMakeWithPoints(70);
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
<b>// dimension returned is relative (%)</b>
ASDimensionMake("50%")
ASDimensionMakeWithFraction(0.5)
<b>// dimension returned in points</b>
ASDimensionMake("70pt")
ASDimensionMake(70)
ASDimensionMakeWithPoints(70)
</pre> </pre>
</div>
</div>
### Example using `ASDimension` ### Example using `ASDimension`
@ -59,9 +65,11 @@ self.rightStack.style.flexBasis = ASDimensionMake(@"60%");
[horizontalStack setChildren:@[self.leftStack, self.rightStack]]; [horizontalStack setChildren:@[self.leftStack, self.rightStack]];
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
self.leftStack.style.flexBasis = ASDimensionMake("40%")
self.rightStack.style.flexBasis = ASDimensionMake("60%")
horizontalStack.children = [self.leftStack, self.rightStack]]
</pre> </pre>
</div>
</div>
## Sizes (`CGSize`, `ASLayoutSize`) ## Sizes (`CGSize`, `ASLayoutSize`)
@ -77,6 +85,7 @@ self.rightStack.style.flexBasis = ASDimensionMake(@"60%");
ASLayoutSizeMake(ASDimension width, ASDimension height); ASLayoutSizeMake(ASDimension width, ASDimension height);
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
ASLayoutSizeMake(_ width: ASDimension, _ height: ASDimension)
</pre> </pre>
</div> </div>
</div> </div>
@ -99,6 +108,12 @@ ASDimension height = ASDimensionMake(@"50%");
layoutElement.style.preferredLayoutSize = ASLayoutSizeMake(width, height); layoutElement.style.preferredLayoutSize = ASLayoutSizeMake(width, height);
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
// Dimension type "Auto" indicates that the layout element may
// be resolved in whatever way makes most sense given the circumstances
let width = ASDimensionMake(.auto, 0)
let height = ASDimensionMake("50%")
layoutElement.style.preferredLayoutSize = ASLayoutSizeMake(width, height)
</pre> </pre>
</div> </div>
</div> </div>
@ -116,6 +131,7 @@ If you do not need relative values, you can set the layout element's `.preferred
layoutElement.style.preferredSize = CGSizeMake(30, 160); layoutElement.style.preferredSize = CGSizeMake(30, 160);
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
layoutElement.style.preferredSize = CGSize(width: 30, height: 60)
</pre> </pre>
</div> </div>
</div> </div>
@ -139,6 +155,13 @@ layoutElement.style.minHeight = ASDimensionMake(@"50%");
layoutElement.style.maxHeight = ASDimensionMake(@"50%"); layoutElement.style.maxHeight = ASDimensionMake(@"50%");
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
layoutElement.style.width = ASDimensionMake("50%")
layoutElement.style.minWidth = ASDimensionMake("50%")
layoutElement.style.maxWidth = ASDimensionMake("50%")
layoutElement.style.height = ASDimensionMake("50%")
layoutElement.style.minHeight = ASDimensionMake("50%")
layoutElement.style.maxHeight = ASDimensionMake("50%")
</pre> </pre>
</div> </div>
</div> </div>
@ -159,6 +182,7 @@ layoutElement.style.maxHeight = ASDimensionMake(@"50%");
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize; - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize;
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec
</pre> </pre>
</div> </div>
</div> </div>

View File

@ -275,7 +275,7 @@ If the center spec's width or height is unconstrained, it shrinks to the size of
{ {
ASStaticSizeDisplayNode *subnode = ASDisplayNodeWithBackgroundColor([UIColor greenColor], CGSizeMake(70, 100)); ASStaticSizeDisplayNode *subnode = ASDisplayNodeWithBackgroundColor([UIColor greenColor], CGSizeMake(70, 100));
return [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY return [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY
sizingOptions:ASRelativeLayoutSpecSizingOptionDefault sizingOptions:ASCenterLayoutSpecSizingOptionDefault
child:subnode] child:subnode]
} }
</pre> </pre>

View File

@ -18,7 +18,7 @@ Let's say you'd like to show a snapshot of San Francisco. All you need are the
<div class = "code"> <div class = "code">
<pre lang="objc" class="objcCode"> <pre lang="objc" class="objcCode">
ASMapNode *mapNode = [[ASMapNode alloc] init]; ASMapNode *mapNode = [[ASMapNode alloc] init];
mapNode.preferredFrameSize = CGSizeMake(300.0, 300.0); mapNode.style.preferredSize = CGSizeMake(300.0, 300.0);
// San Francisco // San Francisco
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.7749, -122.4194); CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.7749, -122.4194);
@ -29,7 +29,7 @@ mapNode.region = MKCoordinateRegionMakeWithDistance(coord, 20000, 20000);
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
let mapNode = ASMapNode() let mapNode = ASMapNode()
mapNode.preferredFrameSize = CGSize(width: 300.0, height: 300.0) mapNode.style.preferredSize = CGSize(width: 300.0, height: 300.0)
// San Francisco // San Francisco
let coord = CLLocationCoordinate2DMake(37.7749, -122.4194) let coord = CLLocationCoordinate2DMake(37.7749, -122.4194)
@ -71,7 +71,7 @@ mapNode.options = options;
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
let options = MKMapSnapshotOptions() let options = MKMapSnapshotOptions()
options.mapType = .Satellite options.mapType = .satellite
options.region = MKCoordinateRegionMakeWithDistance(coord, 20000, 20000) options.region = MKCoordinateRegionMakeWithDistance(coord, 20000, 20000)
mapNode.options = options mapNode.options = options

View File

@ -37,7 +37,7 @@ Then, assign an array of keys to the property `imageIdentifiers`. This list sho
init(urls: [String: NSURL]) { init(urls: [String: NSURL]) {
imageURLs = urls imageURLs = urls
multiplexImageNode = ASMultiplexImageNode(cache: nil, downloader: ASBasicImageDownloader.sharedImageDownloader()) multiplexImageNode = ASMultiplexImageNode(cache: nil, downloader: ASBasicImageDownloader.shared())
multiplexImageNode.downloadsIntermediateImages = true multiplexImageNode.downloadsIntermediateImages = true
multiplexImageNode.imageIdentifiers = ["original", "medium", "thumb" ] multiplexImageNode.imageIdentifiers = ["original", "medium", "thumb" ]
@ -67,7 +67,7 @@ Then, if you've set up a simple dictionary that holds the keys you provided earl
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func multiplexImageNode(imageNode: ASMultiplexImageNode, URLForImageIdentifier imageIdentifier: ASImageIdentifier) -> NSURL? { func multiplexImageNode(_ imageNode: ASMultiplexImageNode, urlForImageIdentifier imageIdentifier: ASImageIdentifier) -> URL? {
return imageURLs[imageIdentifier] return imageURLs[imageIdentifier]
} }
</pre> </pre>
@ -96,11 +96,11 @@ For example, in the case that you want to react to the fact that a new image arr
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
func multiplexImageNode(imageNode: ASMultiplexImageNode, func multiplexImageNode(_ imageNode: ASMultiplexImageNode,
didUpdateImage image: UIImage?, didUpdate image: UIImage?,
withIdentifier imageIdentifier: ASImageIdentifier?, withIdentifier imageIdentifier: ASImageIdentifier?,
fromImage previousImage: UIImage?, from previousImage: UIImage?,
withIdentifier previousImageIdentifier: ASImageIdentifier?) { withIdentifier previousImageIdentifier: ASImageIdentifier?) {
// this is optional, in case you want to react to the fact that a new image came in // this is optional, in case you want to react to the fact that a new image came in
} }
</pre> </pre>

View File

@ -19,7 +19,7 @@ imageNode.URL = [NSURL URLWithString:@"https://someurl.com/image_uri"];
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
let imageNode = ASNetworkImageNode() let imageNode = ASNetworkImageNode()
imageNode.URL = NSURL(string: "https://someurl.com/image_uri") imageNode.url = URL(string: "https://someurl.com/image_uri")
</pre> </pre>
</div> </div>
</div> </div>
@ -39,15 +39,15 @@ If you have a standard size you want the image node's frame size to be you can u
<pre lang="objc" class="objcCode"> <pre lang="objc" class="objcCode">
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constraint - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constraint
{ {
imageNode.preferredFrameSize = CGSizeMake(100, 200); imageNode.style.preferredSize = CGSizeMake(100, 200);
... ...
return finalLayoutSpec; return finalLayoutSpec;
} }
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec { override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
imageNode.preferredFrameSize = CGSize(width: 100, height: 200) imageNode.style.preferredSize = CGSize(width: 100, height: 200)
... ...
return finalLayoutSpec return finalLayoutSpec
} }
@ -74,7 +74,7 @@ This is also a perfect place to use `ASRatioLayoutSpec`. Instead of assigning a
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec { override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let ratio: CGFloat = 3.0/1.0 let ratio: CGFloat = 3.0/1.0
let imageRatioSpec = ASRatioLayoutSpec(ratio:ratio, child:self.imageNode) let imageRatioSpec = ASRatioLayoutSpec(ratio:ratio, child:self.imageNode)
... ...

View File

@ -28,7 +28,7 @@ videoNode.asset = asset;
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
let videoNode = ASVideoNode() let videoNode = ASVideoNode()
let asset = AVAsset(URL: NSURL(string: "http://www.w3schools.com/html/mov_bbb.mp4")) let asset = AVAsset(url: URL(string: "http://www.w3schools.com/html/mov_bbb.mp4")!)
videoNode.asset = asset videoNode.asset = asset
</pre> </pre>
</div> </div>
@ -78,7 +78,7 @@ There are a ton of delegate methods available to you that allow you to react to
- (void)videoNode:(ASVideoNode *)videoNode willChangePlayerState:(ASVideoNodePlayerState)state toState:(ASVideoNodePlayerState)toState; - (void)videoNode:(ASVideoNode *)videoNode willChangePlayerState:(ASVideoNodePlayerState)state toState:(ASVideoNodePlayerState)toState;
</pre> </pre>
<pre lang="swift" class = "swiftCode hidden"> <pre lang="swift" class = "swiftCode hidden">
videoNode(videoNode:willChangePlayerState:toState:) videoNode(_:willChange:to:)
</pre> </pre>
</div> </div>
</div> </div>