dmytro-anokhin / url-image

AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.
MIT License
1.1k stars 96 forks source link

inProgress View does not disappear after content is loaded while scrolling #142

Closed BlueMoose2 closed 3 years ago

BlueMoose2 commented 3 years ago

‼️ Please fill in as much information as possible ‼️

Summary and/or background I am currently experiencing a bug when using URLImages in a Scroll View. As the image is being loaded and displaying the inProgress view I noticed if you are actively touching/scrolling, the inProgress view will never update until the scrolling animation has completed. Is there a fix for this?

OS and what device you are using

Version of URLImage library The version of the library where the bug happens.

What you expected would happen I expect the image to load and replace the inProgress View even if I am scrolling or interacting with view.

What actually happens The InProgress View does not go away while scrolling is active.

Sample code

import SwiftUI
import URLImage

struct SwiftUIView: View {
    var body: some View {
        ScrollView {
            ForEach(0..<50) { item in
        URLImage(url: URL(string: "https://assets-global.website-files.com/6005fac27a49a9cd477afb63/60576840e7d265198541a372_bavassano_homepage_gp.jpg")!,
                 options: URLImageOptions(
                    cachePolicy: .returnCacheElseLoad(cacheDelay: nil, downloadDelay: 0.25)),
                 inProgress: { progress in  // Display progress
                    VStack{
                        Text("InProgress")
                    }
                 },
                 failure: { error, retry in         // Display error and retry button
                    VStack {
                        Text(error.localizedDescription)
                        Button("Retry", action: retry)
                    }
                 },
                 content: { image in
                    image
                        .renderingMode(.original)
                        .resizable()
                        .aspectRatio(contentMode: .fill)
                        .frame(width: 170, height: 150)
                        .clipped()
                        .cornerRadius(5)

                 })
            }
    }
    }
}

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView()
    }
}

Test data N/A

Additional information

Misc

user1u commented 3 years ago

Same issue here.

проблема еще в том что если скролишь, то есть медленно ведешь ленту вниз, проходя посты с фотографиями, то progressview так и остается крутиться, но стоит остановиться фото подгружаются как надо.

я попробовал load: .loadImmediately но результат тот же.

проблема номер два. Если использовать loadOnAppear, то проблема останется и к ней прибавится еще одна,

в том случае если в фиде первый пост идет с фотографией то она не загрузится, но загрузка произойдет тогда когда мы отмотаем чуток вниз, а потом вернемся на верх. То есть да, тут срабатывает onAppear, но он не срабатывает на открытии экрана.

конструкция

NavigationView ScrollView LazyVStack content() } } }

dmytro-anokhin commented 3 years ago

Hey, sorry for taking long to respond.

The bug is a bit tricky to reproduce, but I think I found the cause. Read from cache operation uses the main run loop to deliver updates. Scrolling cause the run loop to be busy handling user input and postpone others. Version 2.2.4 uses the main dispatch queue, that is FIFO. This seems to solve the problem in my tests. Please confirm if it works for your case.

Cheers.

user1u commented 3 years ago

Hey, sorry for taking long to respond.

The bug is a bit tricky to reproduce, but I think I found the cause. Read from cache operation uses the main run loop to deliver updates. Scrolling cause the run loop to be busy handling user input and postpone others. Version 2.2.4 uses the main dispatch queue, that is FIFO. This seems to solve the problem in my tests. Please confirm if it works for your case.

Cheers.

Спасибо! все работает!

BlueMoose2 commented 3 years ago

Hey, sorry for taking long to respond.

The bug is a bit tricky to reproduce, but I think I found the cause. Read from cache operation uses the main run loop to deliver updates. Scrolling cause the run loop to be busy handling user input and postpone others. Version 2.2.4 uses the main dispatch queue, that is FIFO. This seems to solve the problem in my tests. Please confirm if it works for your case.

Cheers.

This resolved the issue and I am seeing much better performance in my app!! Thanks so much for the timely fix. Much appreciated!! I am closing the issue now.