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

View File

@ -20,7 +20,7 @@ The main dataSource methods are:
</pre>
<pre lang="swift" class = "swiftCode hidden">
func numberOfPagesInPagerNode(pagerNode: ASPagerNode!) -> Int
func numberOfPages(in pagerNode: ASPagerNode) -> Int
</pre>
</div>
</div>
@ -35,7 +35,7 @@ and
</pre>
<pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeAtIndex index: Int) -> ASCellNode!
func pagerNode(_ pagerNode: ASPagerNode, nodeAt index: Int) -> ASCellNode
</pre>
</div>
</div>
@ -50,7 +50,7 @@ or
</pre>
<pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeBlockAtIndex index: Int) -> ASCellNodeBlock!
func pagerNode(_ pagerNode: ASPagerNode, nodeBlockAt index: Int) -> ASCellNodeBlock
</pre>
</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 lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeBlockAtIndex index: Int) -> ASCellNodeBlock! {
guard photoFeed.count > index else { return nil }
func pagerNode(_ pagerNode: ASPagerNode, nodeBlockAt index: Int) -> ASCellNodeBlock {
guard photoFeed.count > index else { return { ASCellNode() } }
let photoModel = photoFeed[index]
let cellNodeBlock = { () -> ASCellNode in
@ -123,8 +123,8 @@ One especially useful pattern is to return an `ASCellNode` that is initialized w
</pre>
<pre lang="swift" class = "swiftCode hidden">
func pagerNode(pagerNode: ASPagerNode!, nodeAtIndex index: Int) -> ASCellNode! {
guard animals.count > index else { return nil }
func pagerNode(_ pagerNode: ASPagerNode, nodeAt index: Int) -> ASCellNode {
guard animals.count > index else { return ASCellNode() }
let animal = animals[index]
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 lang="swift" class = "swiftCode hidden">
func initWithModel(models: Array&lt;Model&gt;) {
let tableNode = ASTableNode(style:.Plain)
init(models: [Model]) {
let tableNode = ASTableNode(style: .plain)
super.initWithNode(tableNode)
super.init(node: tableNode)
self.models = models
self.tableNode = tableNode
self.tableNode.delegate = self
self.tableNode.dataSource = self
return self
self.models = models
self.tableNode = tableNode
self.tableNode.delegate = self
self.tableNode.dataSource = self
}
</pre>
</div>

View File

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

View File

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

View File

@ -27,14 +27,20 @@ ASDimensionMake(@"50%");
ASDimensionMakeWithFraction(0.5);
<b>// dimension returned in points</b>
ASDimensionMake(@"70pt")
ASDimensionMake(@"70pt");
ASDimensionMake(70);
ASDimensionMakeWithPoints(70);
</pre>
<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>
</div>
</div>
### Example using `ASDimension`
@ -59,9 +65,11 @@ self.rightStack.style.flexBasis = ASDimensionMake(@"60%");
[horizontalStack setChildren:@[self.leftStack, self.rightStack]];
</pre>
<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>
</div>
</div>
## Sizes (`CGSize`, `ASLayoutSize`)
@ -77,6 +85,7 @@ self.rightStack.style.flexBasis = ASDimensionMake(@"60%");
ASLayoutSizeMake(ASDimension width, ASDimension height);
</pre>
<pre lang="swift" class = "swiftCode hidden">
ASLayoutSizeMake(_ width: ASDimension, _ height: ASDimension)
</pre>
</div>
</div>
@ -99,6 +108,12 @@ ASDimension height = ASDimensionMake(@"50%");
layoutElement.style.preferredLayoutSize = ASLayoutSizeMake(width, height);
</pre>
<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>
</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);
</pre>
<pre lang="swift" class = "swiftCode hidden">
layoutElement.style.preferredSize = CGSize(width: 30, height: 60)
</pre>
</div>
</div>
@ -139,6 +155,13 @@ layoutElement.style.minHeight = ASDimensionMake(@"50%");
layoutElement.style.maxHeight = ASDimensionMake(@"50%");
</pre>
<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>
</div>
</div>
@ -159,6 +182,7 @@ layoutElement.style.maxHeight = ASDimensionMake(@"50%");
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize;
</pre>
<pre lang="swift" class = "swiftCode hidden">
func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec
</pre>
</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));
return [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY
sizingOptions:ASRelativeLayoutSpecSizingOptionDefault
sizingOptions:ASCenterLayoutSpecSizingOptionDefault
child:subnode]
}
</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">
<pre lang="objc" class="objcCode">
ASMapNode *mapNode = [[ASMapNode alloc] init];
mapNode.preferredFrameSize = CGSizeMake(300.0, 300.0);
mapNode.style.preferredSize = CGSizeMake(300.0, 300.0);
// San Francisco
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.7749, -122.4194);
@ -29,7 +29,7 @@ mapNode.region = MKCoordinateRegionMakeWithDistance(coord, 20000, 20000);
<pre lang="swift" class = "swiftCode hidden">
let mapNode = ASMapNode()
mapNode.preferredFrameSize = CGSize(width: 300.0, height: 300.0)
mapNode.style.preferredSize = CGSize(width: 300.0, height: 300.0)
// San Francisco
let coord = CLLocationCoordinate2DMake(37.7749, -122.4194)
@ -71,7 +71,7 @@ mapNode.options = options;
</pre>
<pre lang="swift" class = "swiftCode hidden">
let options = MKMapSnapshotOptions()
options.mapType = .Satellite
options.mapType = .satellite
options.region = MKCoordinateRegionMakeWithDistance(coord, 20000, 20000)
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]) {
imageURLs = urls
multiplexImageNode = ASMultiplexImageNode(cache: nil, downloader: ASBasicImageDownloader.sharedImageDownloader())
multiplexImageNode = ASMultiplexImageNode(cache: nil, downloader: ASBasicImageDownloader.shared())
multiplexImageNode.downloadsIntermediateImages = true
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 lang="swift" class = "swiftCode hidden">
func multiplexImageNode(imageNode: ASMultiplexImageNode, URLForImageIdentifier imageIdentifier: ASImageIdentifier) -> NSURL? {
func multiplexImageNode(_ imageNode: ASMultiplexImageNode, urlForImageIdentifier imageIdentifier: ASImageIdentifier) -> URL? {
return imageURLs[imageIdentifier]
}
</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 lang="swift" class = "swiftCode hidden">
func multiplexImageNode(imageNode: ASMultiplexImageNode,
didUpdateImage image: UIImage?,
withIdentifier imageIdentifier: ASImageIdentifier?,
fromImage previousImage: UIImage?,
withIdentifier previousImageIdentifier: ASImageIdentifier?) {
func multiplexImageNode(_ imageNode: ASMultiplexImageNode,
didUpdate image: UIImage?,
withIdentifier imageIdentifier: ASImageIdentifier?,
from previousImage: UIImage?,
withIdentifier previousImageIdentifier: ASImageIdentifier?) {
// this is optional, in case you want to react to the fact that a new image came in
}
</pre>

View File

@ -19,7 +19,7 @@ imageNode.URL = [NSURL URLWithString:@"https://someurl.com/image_uri"];
<pre lang="swift" class = "swiftCode hidden">
let imageNode = ASNetworkImageNode()
imageNode.URL = NSURL(string: "https://someurl.com/image_uri")
imageNode.url = URL(string: "https://someurl.com/image_uri")
</pre>
</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">
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constraint
{
imageNode.preferredFrameSize = CGSizeMake(100, 200);
imageNode.style.preferredSize = CGSizeMake(100, 200);
...
return finalLayoutSpec;
}
</pre>
<pre lang="swift" class = "swiftCode hidden">
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec {
imageNode.preferredFrameSize = CGSize(width: 100, height: 200)
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
imageNode.style.preferredSize = CGSize(width: 100, height: 200)
...
return finalLayoutSpec
}
@ -74,7 +74,7 @@ This is also a perfect place to use `ASRatioLayoutSpec`. Instead of assigning a
</pre>
<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 imageRatioSpec = ASRatioLayoutSpec(ratio:ratio, child:self.imageNode)
...

View File

@ -28,7 +28,7 @@ videoNode.asset = asset;
<pre lang="swift" class = "swiftCode hidden">
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
</pre>
</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;
</pre>
<pre lang="swift" class = "swiftCode hidden">
videoNode(videoNode:willChangePlayerState:toState:)
videoNode(_:willChange:to:)
</pre>
</div>
</div>