0

I try to create stacklayout inside cellnode, but nothing shows on screen

class Node: ASCellNode {

    let blackNode = ASDisplayNode()
    let blueNode = ASDisplayNode()

    override init() {
        super.init()
        self.addSubnode(blueNode)
        self.addSubnode(blackNode)
    }

    override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
        blackNode.backgroundColor = .black
        blueNode.backgroundColor = .blue


        let contentStackSpec = ASStackLayoutSpec(direction: .horizontal,
                                                spacing: 40,
                                                justifyContent: .start,
                                                alignItems: .center,
                                                children: [blackNode, blueNode])

        contentStackSpec.style.minWidth = ASDimensionMakeWithPoints(60.0);
        contentStackSpec.style.maxHeight = ASDimensionMakeWithPoints(40.0);

        return ASRelativeLayoutSpec(horizontalPosition: .center, verticalPosition: .center, sizingOption: .init(rawValue: 0), child: contentStackSpec)
    }
}

What am I doing wrong ?

Alexey K
  • 6,537
  • 18
  • 60
  • 118

1 Answers1

0

I think you should use ASInsetLayoutSpec for displaying ASStackLayoutSpec instead of ASRelativeLayoutSpec.

Below is the implementation of your given code using ASInsetLayoutSpec for displaying ASStackLayoutSpec:

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
        blackNode.backgroundColor = .black
        blueNode.backgroundColor = .blue


        let contentStackSpec = ASStackLayoutSpec(direction: .horizontal,
                                                spacing: 40,
                                                justifyContent: .start,
                                                alignItems: .center,
                                                children: [blackNode, blueNode])

        contentStackSpec.style.minWidth = ASDimensionMakeWithPoints(60.0);
        contentStackSpec.style.maxHeight = ASDimensionMakeWithPoints(40.0);

        let cardInsetSpec : ASInsetLayoutSpec = ASInsetLayoutSpec(insets: UIEdgeInsetsMake(5, 5, 5, 5), child: contentStackSpec)  

        return cardInsetSpec

    }
swetansh kumar
  • 475
  • 7
  • 17