Skip to content

Instantly share code, notes, and snippets.

View GeekTree0101's full-sized avatar
💰

David Ha (小河) GeekTree0101

💰
View GitHub Profile
@GeekTree0101
GeekTree0101 / MessageBalloonNode1.swift
Created May 1, 2018 15:30
MessageBalloonNode property
lazy var profileNode: ASNetworkImageNode = {
let node = ASNetworkImageNode()
...
return node
}()
lazy var usernameNode: ASTextNode = {
let node = ASTextNode()
...
return node
@GeekTree0101
GeekTree0101 / MessageBalloonNode2.swift
Created May 1, 2018 15:37
Message BalloonNode Profile Area
func profileAreaLayoutSpec() -> ASLayoutSpec {
let profileRelativeLayout = ASRelativeLayoutSpec(horizontalPosition: .start,
verticalPosition: .start,
sizingOption: [],
child: profileNode)
return profileRelativeLayout
}
@GeekTree0101
GeekTree0101 / MessageBalloonNode3.swift
Created May 1, 2018 15:40
Message Balloon Node Engage Example
func engageNodeLayoutSpec() -> ASLayoutSpec {
return ASRelativeLayoutSpec(horizontalPosition: .start,
verticalPosition: .end,
sizingOption: [],
child: engageNode)
}
@GeekTree0101
GeekTree0101 / MessageBalloonNode3.swift
Created May 1, 2018 15:40
Message Balloon Node Engage Example
func engageNodeLayoutSpec() -> ASLayoutSpec {
return ASRelativeLayoutSpec(horizontalPosition: .start,
verticalPosition: .end,
sizingOption: [],
child: engageNode)
}
@GeekTree0101
GeekTree0101 / MessageBalloonNode4.swift
Created May 1, 2018 15:45
Message Balloon Node Content Area Spec Example
private func talkBalloonContentLayoutSpec(_ constrainedSize: ASSizeRange,
isLeft: Bool) -> ASLayoutSpec {
let talkTailLayout = ASAbsoluteLayoutSpec(sizing: .sizeToFit,
children: [self.talkTailNode])
let stackElements: [ASLayoutElement] = [self.contentAreaNode,
talkTailLayout]
let stackLayout = ASStackLayoutSpec(direction: .horizontal,
spacing: 0.0,
@GeekTree0101
GeekTree0101 / MessageBalloonNode5.swift
Created May 1, 2018 15:49
Message Balloon Node Talk Tail Example
lazy var talkTailNode: ASImageNode = {
let node = ASImageNode()
node.style.preferredSize = Const.talkTailSize
node.style.layoutPosition = Const.talkTailPosition
switch self.location {
case .left:
node.image = #imageLiteral(resourceName: "imgReplyLeftpoint")
case .right, .write:
node.image = #imageLiteral(resourceName: "imgReplyRightpoint")
case .admin:
@GeekTree0101
GeekTree0101 / sana_info_cellnode.swift
Last active May 12, 2018 04:53
Sana Info CellNode Example1
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let stackLayout =
ASStackLayoutSpec(direction: .horizontal,
spacing: 10.0,
justifyContent: .start,
alignItems: .center,
children: [profileImageNode,
descriptionNode])
let stackLayout2 =
@GeekTree0101
GeekTree0101 / sana_info_cellnode2.swift
Last active May 12, 2018 04:54
Sana Info CellNode Example 2
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let stackLayout =
ASStackLayoutSpec(direction: .horizontal,
spacing: 10.0,
justifyContent: .start,
alignItems: .center,
children: [profileImageNode,
descriptionNode])
stackLayout.style.flexShrink = 1.0
@GeekTree0101
GeekTree0101 / sana_info_cellnode3.swift
Last active May 12, 2018 04:54
Sana Info CellNode Example 3
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let stackLayout =
ASStackLayoutSpec(direction: .horizontal,
spacing: 10.0,
justifyContent: .start,
alignItems: .center,
children: [profileImageNode,
descriptionNode])
stackLayout.style.flexShrink = 1.0
@GeekTree0101
GeekTree0101 / CatFeedViewController.swift
Created May 12, 2018 06:15
UIViewController + Texture Example
class CatFeedViewController: UIViewController {
let backgroundNode = ASDisplayNode()
let feedNode = ASTableNode()
init() {
super.init(nibName: nil, bundle: nil)
self.view.addSubnode(backgroundNode)
backgroundNode.automaticallyManagesSubnodes = true
backgroundNode.layoutSpecBlock = { [weak self] (node, constraintSize) -> ASLayoutSpec in