dmytro-anokhin/url-image

inProgress View does not disappear after content is loaded while scrolling

BlueMoose2 opened this issue · 4 comments

‼️ 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

  • OS: iOS 14.4.2
  • Device or simulator iPhone 11 Pro and iPhone 12 Pro Simulator
  • Are you building a widget or an extension? (No)

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

  • [ X] The bug is reproducible in the latest version.

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

  • Screenshots or video demonstrating a bug;
  • Crash log;

Misc

  • [X ] I read the documentation and it didn't help;
  • [X ] I searched for similar issues.

Same issue here.

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

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

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

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

конструкция

NavigationView
ScrollView
LazyVStack
content()
}
}
}

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.

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.

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

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.