Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laggy scrolling with AttributedTextView inside tableViewCell #16

Open
daurenm opened this issue Mar 31, 2018 · 3 comments
Open

Laggy scrolling with AttributedTextView inside tableViewCell #16

daurenm opened this issue Mar 31, 2018 · 3 comments

Comments

@daurenm
Copy link

daurenm commented Mar 31, 2018

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

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
@evermeer
Copy link
Owner

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.

@jameshays
Copy link
Contributor

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.

@evermeer
Copy link
Owner

@jameshays Good point. I was already hesitating implementing it the way I suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants