Using nested ASStackLayoutSpec
with AsyncDisplayKit I am trying to achieve this
So I am creating a vertical ASStackLayoutSpec
with avatar and another horizontal ASStackLayoutSpec
with the user name and timestamp and text
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
// HEADER with username and timestamp
let spacer = ASLayoutSpec()
spacer.style.flexGrow = 1
let headerStackSpec = ASStackLayoutSpec.horizontal()
headerStackSpec.spacing = 2
headerStackSpec.alignItems = .baselineFirst
headerStackSpec.children = [userNode, spacer, timestampNode]
// CONTENT - HEADER and text
let contentStackSpec = ASStackLayoutSpec.vertical()
contentStackSpec.spacing = 2
contentStackSpec.children = [headerStackSpec, messageNode]
// MAIN - avatar and CONTENT
let mainStackSpec = ASStackLayoutSpec.horizontal()
mainStackSpec.spacing = 9
mainStackSpec.children = [avatarNode, contentStackSpec]
return ASInsetLayoutSpec(insets: UIEdgeInsets(top: 2, left: 10, bottom: 2, right: 10), child: mainStackSpec)
}
But the result is not what I expected
It looks like the text goes to infinity, not properly wraping. The timestamp is also probably somewhere far away on the right out of bounds.
I tried different combinations of .alignItems
and .justifyContent
but I cannot get it to work.
try these properties:
contentStackSpec.style.flexShrink = 1
messageNode.style.flexShrink = 1
contentStackSpec.children = [headerStackSpec, messageNode]