Repository navigation
Show a failed CachedAsyncImage download as a failure - #17
Merged
Merged
Conversation
When a download returned no data or data that is not an image, the completion handler returned early and isLoading stayed true, so the progress view spun forever. The state after a download is now decided by a small pure function that ends loading in both cases.
After a failed download the view was back in its initial state, which looks exactly like a load that never started. The loading now lives in a small loader object with explicit idle, loading, loaded and failed phases: a failure shows a neutral placeholder and is not retried automatically, only when the view appears again or the URL changes (.task(id:), which also cancels the download when the view disappears). The tests run the loader itself with stubbed downloads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
CachedAsyncImagereturned early on a failed download (no data, or data that is not an image), so the progress view spun forever. It also kept showing the old image when the URL changed, and never cancelled a download.Loading now lives in an internal
Loaderwith the phasesidle,loading,loadedandfailed. A failure shows a neutralphotoplaceholder and is retried only when the view appears again or the URL changes. The view loads with.task(id: url), which also cancels the download when the view disappears and replaces theonChange(of:perform:)that warned on visionOS.Split out of #7. The placeholder
#warningstays; a custom placeholder will be its own PR.How this was verified
CachedAsyncImageTestsrun the realLoaderwith stubbed downloads: a thrown error and non-image data both end in.failed, and a successful load ends in.loadedand is served from the cache on the next load (one download for two loads).mainhas noLoader, so the tests cannot compile against it. For the red run, the one line that sets the failed phase was removed, which ismain's behavior (stay loading):Green, this branch: