0

I have a ScrollView composed by views whose content is loaded asynchronously. The elements can be ideally infinite so I decided to wrap them in LazyVStack. The problem is that the async content takes some times to load so when scrolled it appears after some time. I would like to start their loading a little before. Exist a way to make LazyVStack thinks the displayed view is a little larger?

ScrollView {
    LazyVStack {
        ForEach(modelURLs) { modelURL in
            AsyncModel(url: modelURL)
        }
    }
}
2
  • What do you meant by a little larger? ... by comparing to what/which? Doesn't some padding work for this?
    – Asperi
    Dec 14, 2020 at 13:13
  • @Asperi what he means, you know lazystack doesn't reload until you scroll to that part. He wants to trick the screen to make it think that you already scrolled by that the data will be reloaded before you scroll. I'm wondering if you can do such thing.
    – Cod3rMax
    Dec 14, 2020 at 14:19

1 Answer 1

1

I found a solution that worked in my specific case, I hope in a better one:

struct ModelList: View {
    
    let models: [ModelURLs]
    
    private let preloadingPadding: CGFloat = 300  // !!!
    
    var body: some View {
        ScrollView {
            LazyVStack {
                ForEach(modelURLs) { modelURL in
                    AsyncModel(url: modelURL)
                }
            }.padding(preloadingPadding) // !!!
        }.padding(-preloadingPadding) // !!!
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.