Skip to content

Async Image Loading #5140

Answered by vonnieda
arihant2math asked this question in Q&A
Discussion options

You must be logged in to vote

I recently spent a lot of time getting lazy image loading working well in my app. Here is roughly how I do it.

Here is an example of my "artist list" page, which is a grid view with thousands of images. I added a few comments to note the image handling:

pub fn artist_list(app: &App) {
    let librarian = app.librarian.clone();
    let ui = app.ui.clone();
    let images = app.images.clone();
    // Do the initial database query and sort in a thread to avoid blocking UI.
    std::thread::spawn(move || {
        let mut artists: Vec<Artist> = librarian
            .list(&Artist::default().into(), None)
            .unwrap()
            .map(Into::into)
            .collect();
        artist…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by arihant2math
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants