For populating ScrollView with a large amount of data, apple is suggesting using LazyVGrid inside the ScrollView: LazyVGrid - Apple
So this sample code that is loading 500 random photos works perfectly in case of memory management: (Almost 30MB).
I used KingFisher as image loader.
var body: some View {
ScrollView {
LazyVGrid(columns: [GridItem(.flexible())]) {
ForEach(1...500, id: \.self) { value in
KFImage(URL(string: "https://picsum.photos/800/800?\(value)"))
}
}
}
}
But I want to have a controll over the content of ScrollView, like offset.
So as soon as I added .content.offset(y: 5)
the memory goes up to 640MB !!
var body: some View {
ScrollView {
LazyVGrid(columns: [GridItem(.flexible())]) {
ForEach(1...500, id: \.self) { value in
KFImage(URL(string: "https://picsum.photos/800/800?\(value)"))
}
}
}
.content.offset(y: 5)
}
Is there any reason behind the .content
?!! How can I handle not having a large amount of memory?
I need to disable scroll and control content offset manually, not by using ScrollViewReader
.
Thanks