I'm having a very weird issue using LazyVGrid that I've been banging my head over now for weeks. I have a loop that runs over a filtered list of locations and prints out the image with the location name below which is drawn from CategoryItem.
let columns = [GridItem(.adaptive(minimum: 150), alignment: .top)]
ScrollView {
LazyVGrid(columns: columns, spacing: 10) {
ForEach(categoryFilter) { landmark in
let _ = print("catFilter= \(landmark)")
NavigationLink {
DetailView(landmark: landmark)
} label: {
CategoryItem(landmark: landmark)
}
.frame(height: 185)
}
}
}
I kept getting a blank screen and could see no way around it so I put a print inside the loop and noticed that it was just continually printing the content from categoryFilter in an endless loop. If I commented out just the LazyVGrid loop (leaving just the bare ForEach loop) it works.
And if I comment out just the remote fetching of the image which in my case is "KFImage(URL(string: imageURLString))" (which is inside CategoryItem) then it all works too. I have tried AsyncImage, Nuke etc and it's all the same. The only way I can solve it displaying an image is to use a local image.
If I use LazyHStack everything works without an issue.
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(alignment: .top, spacing: 30) {
HStack(alignment: .top, spacing: 20) {
ForEach(categoryFilter) { landmark in
let _ = print("catFilter= \(landmark)")
NavigationLink {
DetailView(landmark: landmark)
} label: {
CategoryItem(landmark: landmark)
}
.frame(height: 185)
}
}
}
}
Any help would be much appreciated.