Skip to content

Instantly share code, notes, and snippets.

@wendyliga
Created September 25, 2019 07:51
Show Gist options
  • Save wendyliga/4ab690cee1361b82ff1bca366ae82992 to your computer and use it in GitHub Desktop.
Save wendyliga/4ab690cee1361b82ff1bca366ae82992 to your computer and use it in GitHub Desktop.
TextureGram Action Node
import AsyncDisplayKit
class ActionNode: ASDisplayNode {
// MARK: - Nodes
private let loveButton: ASImageNode
private let commentButton: ASImageNode
private let shareButton: ASImageNode
override init() {
self.loveButton = ASImageNode()
loveButton.image = imageLiteral(resourceName: "love")
loveButton.style.preferredSize = CGSize(width: 16, height: 16)
self.commentButton = ASImageNode()
commentButton.image = imageLiteral(resourceName: "comment")
commentButton.style.preferredSize = CGSize(width: 16, height: 16)
self.shareButton = ASImageNode()
shareButton.image = imageLiteral(resourceName: "share")
shareButton.style.preferredSize = CGSize(width: 16, height: 16)
super.init()
self.automaticallyManagesSubnodes = true
}
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let mainStack = ASStackLayoutSpec(direction: .horizontal,
spacing: 16,
justifyContent: .start,
alignItems: .start,
children: [loveButton,commentButton, shareButton])
let padding = ASInsetLayoutSpec(insets: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8), child: mainStack)
return padding
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment