ASInsetLayoutSpec inside Horizontal stack layout breaks line break of text nodes #874
Description
It took me a while to nail down what was going on with this issue but I'll try to cover all the behaviors. I have seen this with a few components I have created but I will cover the simplest case.
This node is designed as a Horizontal stack layout with an ASDisplayNode and an ASTextNode in the horizontal stack. The layout spec looks like this:
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec! {
textNode.flexShrink = true
let insetSpec = ASInsetLayoutSpec(insets: BlockquoteInsets, child: textNode)
sidebarNode.flexBasis = ASRelativeDimensionMakeWithPoints(2.0)
return ASStackLayoutSpec(direction: .Horizontal,
spacing: 0.0,
justifyContent: .Center,
alignItems: .Stretch,
children: [sidebarNode, insetSpec])
}
That produces this behavior:
Notice the lack of line breaking. It is like flexShrink isn't occurring. Looking at it in Reveal the container node that holds the textNode and owns the layout spec is sized fine but the text node itself is way oversized beyond the node bounds.
A few things to note about this:
- This issue ALSO occurs with ASButtonNode which has a similar layout spec.
- This is also occurs if you replace the ASTextNode with a wrapped UILabel ASDisplayNode.
Now here's what happens when I remove the inset. Here's the new layout spec:
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec! {
textNode.spacingBefore = BlockquoteInsets.left
textNode.spacingAfter = BlockquoteInsets.right
textNode.flexShrink = true
sidebarNode.flexBasis = ASRelativeDimensionMakeWithPoints(2.0)
return ASStackLayoutSpec(direction: .Horizontal,
spacing: 0.0,
justifyContent: .Center,
alignItems: .Stretch,
children: [sidebarNode, textNode])
}
Here's what that looks like:
You should be able to easily replicate this as it seems that any Horizontal stack spec that includes an inset spec as one of its children is going to have this problem.