Hi,
I am trying to generate an image of a specific size (from a map in this case using MKMapSnapshotter). The image generation code is fine.
my view is like this
@ObservedObject public var viewModel: ViewModel
var body: some View {
GeometryReader { geometry in
Image(uiImage: viewModel.mapImage)
.frame(width: geometry.size.width, height: 50)
.cornerRadius(5)
.task(priority: .userInitiated) {
await viewModel.loadImage(size: CGSize(width: geometry.size.width, height: 50)
}
}
}
}
This is used from another view that uses a @SectionedFetchRequest
inside a nav stack list and foreach.
the mapImage property of the view model is @Published
.
This sort of works and the first few rows show an image. However, as you scroll some views do not get the image update.
I added some logging and I can see that the view model is getting released so the loadImage() method does not get called.
The weird thing is if I drag a row that has no image, it is immediately generated.
Any ideas as to how I could get this to work for all rows?
Thants