[ASTextNode] support insets
Unlike textview / label, textnode does not have insets/margins. It would be great to support this feature.
#2000! Yay!
Until it gets added to the master branch, you can use this (just create a new file in your project):
// ASCustomTextNode
// Workaround for ASTextNode with padding (as in CSS)
//
// -------------
// | --------- <-- UIEdgeInsets
// | |titleNode| |
// | --------- | <-- ASControlNode
// -------------
import AsyncDisplayKit
class ASCustomTextNode: ASControlNode {
var titleNode: ASTextNode!
var insets: UIEdgeInsets!
init(titleNode: ASTextNode, insets: UIEdgeInsets) {
log.debug("ASCustomTextNode init")
log.debug("titleNode = \(titleNode)")
self.titleNode = titleNode
titleNode.layerBacked = true
self.insets = insets
super.init()
addSubnode(titleNode)
}
override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec {
return ASStackLayoutSpec(
direction: .Horizontal,
spacing: 0,
justifyContent: .Center,
alignItems: .Center,
children: [
ASInsetLayoutSpec(
insets: insets,
child: titleNode
)
]
)
}
}
It works perfectly!
I'm not sure if you need a stack layout spec for that at all. Just wrap it in a inset spec or @benjaminhorner any reason you use a stack layout spec in this case?
@maicki: you are totally right. I am actually using it in a larger file. I just extracted that bit. However, as you point out, returning an inset spec is a better solution.
this issue is related to #1999, since it requires more complex fix, having insets may give a short-term solution. Sorry @maichi and @benjaminhorner , extending it with UIEdgeInsets won't fix that particular bug.
I spoke with @Yue-Wang-Google and understand the core issue here - let's try to fix the italics bug first, but adding this as a +Beta API as a workaround could be reasonable too!
Thanks @garrettmoon for adding this to ASTextNode!
@Yue-Wang-Google try this out and let us know if this doesn't work for you. The fix is currently in master (2.0 beta), which contains a few minor breaking API changes. I'll try to get this into 1.9.91 as well so that you can test it when we bump the pod in a day or two.