修改ASTextNode的AttributedText导致父ASTableNode闪烁问题咨询
Hey there! This is a super common issue folks run into when working with Texture (formerly AsyncDisplayKit), so let’s break down what’s going on and how to fix it.
First: Yes, this is almost certainly a thread issue
Texture’s node properties (like attributedString on ASTextNode) must be modified on the main thread. Notification callbacks can sometimes fire on background threads depending on how the notification is posted—if you’re updating the text node off the main thread, it causes inconsistent rendering, which leads to that annoying flicker you’re seeing.
The Quick Fix
Wrap your text update code in a main thread dispatch to ensure it’s executed correctly:
DispatchQueue.main.async { self.likes.countLabel.attributedString = NSMutableAttributedString(string: "\(newCount)", attributes: self.likes.font) }
In most cases, this alone will eliminate the flicker. Texture handles layout invalidation automatically when you modify node properties on the main thread, so you shouldn’t need to manually call setNeedsLayout() or setNeedsDisplay()—but if you’re dealing with a custom node setup, adding those calls inside the main thread block might help in edge cases.
Have Others Seen This?
Absolutely! This comes up frequently in the Texture community. The root cause is almost always off-main-thread modifications to UI-related node properties. Texture’s async rendering pipeline relies on consistent state from the main thread, so any changes made elsewhere throw off the rendering cycle.
Bonus Checks
If the flicker still happens after fixing the thread issue, double-check:
- That
countLabelis properly added as a child node to its parent (no accidental duplicate nodes or layout conflicts) - That you’re not accidentally reinitializing the text node instead of updating its attributed string
- That your parent node’s layout spec is stable (no unexpected layout recalculations triggered by the text update)
内容的提问来源于stack exchange,提问作者sushibrain

