How can I achieve such a scenario.
- Using the AsyncImage I load the url.
- Progress view turns around as placeholder
- After 2 seconds we don't get an error
- Our ProgressView changes to an image
This is a code:
AsyncImage(url: exampleURL) { phase in
if let image = phase.image {
image
.imageModifier()
} else if phase.error != nil {
Image("example_image")
.imageModifier()
} else {
ProgressView()
.font(.largeTitle)
}
}
There is any short and clean solution of I need to using custom implementation async image and using for example taskgroups? Thanks for any ideas.
You could try this approach, using a
TimerwithonReceive, works well for me. Set an appropriatetimeRemaining. After that time has elapsed, theAsyncImagewill present the chosen image ("timer"), if the image is downloaded before that time, that image will be displayed.