swiftui-cached-async-image icon indicating copy to clipboard operation
swiftui-cached-async-image copied to clipboard

how to show placeholder while the image url is replaced?

Open Mohsenkhodadadzadehthelist opened this issue 1 year ago • 1 comments

I am loading multiple images with CachedAsynImage, and the problem is when I replace the previous URL with a new one, the previous image is still shown and the component doesn't switch the view to the placeholder

I'm using this init:

CachedAsyncImage(url: , content: , placeholder:)

You can try to invalidate the CachedAsyncImage by settings its id to be the same as the url. In that way if the url is changed, it will invalidate the CachedAsyncImage and it will start loading from beginning.

CachedAsyncImage(url: URL(string: <url>)) { image in
    ...
} placeholder: {
    ...
}
.id(<url>)

plament avatar Feb 25 '25 10:02 plament