AttributedTextView
AttributedTextView copied to clipboard
Laggy scrolling with AttributedTextView inside tableViewCell
Hi there,
Seems like AttributedTextView.attributer.setter takes too much time while blocking main thread.
![screen shot 2018-03-31 at 12 49 29 pm](https://user-images.githubusercontent.com/13380740/38160572-032ad1be-34e2-11e8-94ea-5efd19b2a587.png)
Is there anything we can do to make it faster? Seems like right now, it requires main thread, so I can't simply put in a background thread :(
let userName = "daurenmuratov"
let comment = "\(userName):"
.font(UIFont.systemFont(ofSize: 14, weight: .bold))
.match(userName)
.color(.black)
.makeInteract({ (userLogin) in
print("Login pressed: \(userLogin)")
})
+ (" \(text)")
.font(UIFont.systemFont(ofSize: 14))
.color(.gray)
.matchHashtags.color(.red)
.makeInteract({ (hashtag) in
print("Hashtag pressed: \(hashtag)")
})
.matchMentions
.makeInteract({ (mention) in
print("Mention pressed: \(mention)")
})
.matchLinks
.makeInteract({ (link) in
print("Link pressed \(link)")
})
.setLinkColor(.blue)
textView.attributer = comment
Hi,
Yes, you ar right, It now assumes you are doing everything on the main. I think that for now you could use a workaround like this:
DispatchQueue.global().async {
let at: NSMutableAttributedString = "red".red.attributedText
DispatchQueue.main.async {
self.myLabel.attributedText = at
}
}
I will think about how to embed functionality like this into the library.
A bit late to the party, but don't perform this inside your cell on a background thread unless you are also willing to handle canceling the background task when the cell is dequeued and reused. The better solution would be to have this work done in the UITableViewDatasource so you can process it and then set it on the cell at the proper indexPath if that cell is still being viewed.
@jameshays Good point. I was already hesitating implementing it the way I suggested.