Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions Modules/Sources/AsyncImageKit/Views/CachedAsyncImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ public struct CachedAsyncImage<Content>: View where Content: View {
@ViewBuilder content: @escaping (AsyncImagePhase) -> Content
) {
if let url {
let request = ImageRequest(url: url, host: host, options: ImageRequestOptions(
mutability: mutability
))
let request = ImageRequest(
url: url,
host: host,
options: ImageRequestOptions(
mutability: mutability
)
)

self.init(
request: request,
Expand All @@ -63,9 +67,13 @@ public struct CachedAsyncImage<Content>: View where Content: View {
@ViewBuilder placeholder: @escaping () -> P
) where Content == _ConditionalContent<I, P>, I: View, P: View {
if let url {
let request = ImageRequest(url: url, host: host, options: ImageRequestOptions(
mutability: mutability
))
let request = ImageRequest(
url: url,
host: host,
options: ImageRequestOptions(
mutability: mutability
)
)

self.init(
request: request,
Expand All @@ -89,9 +97,13 @@ public struct CachedAsyncImage<Content>: View where Content: View {
@ViewBuilder placeholder: @escaping () -> P
) where Content == _ConditionalContent<I, P>, I: View, P: View {
self.init(
request: ImageRequest(videoUrl: videoUrl, host: host, options: ImageRequestOptions(
mutability: mutability
)),
request: ImageRequest(
videoUrl: videoUrl,
host: host,
options: ImageRequestOptions(
mutability: mutability
)
),
imageDownloader: imageDownloader,
content: content,
placeholder: placeholder
Expand Down Expand Up @@ -139,9 +151,12 @@ public struct CachedAsyncImage<Content>: View where Content: View {
} else {
phase = .empty
let image = try await imageDownloader.image(for: request)

try Task.checkCancellation()
phase = .success(Image(uiImage: image))
}
} catch {
guard !Task.isCancelled else { return }
phase = .failure(error)
}
}
Expand All @@ -150,7 +165,9 @@ public struct CachedAsyncImage<Content>: View where Content: View {
fileprivate let testURL = URL(string: "https://i0.wp.com/themes.svn.wordpress.org/twentytwentyfive/1.3/screenshot.png")!

// This video is the preview because it's not just black for the first frame, and right now video previews only fetch the first frame
fileprivate let videoURL = URL(string: "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4")!
fileprivate let videoURL = URL(
string: "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
)!

#Preview("Basic Image") {
CachedAsyncImage(url: testURL)
Expand Down
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [*] Reader: Fix an issues with Reader failing to clear cached comments if all the comments are deleted [#25482]
* [*] Reader: Fix an issue with the article view removing autoplay without showing controls [#25468]
* [*] Menus: Fix an issue with footer view in Menu Editing not resizing [#25481]
* [*] Notifications: Attempt to fix incorrect avatars in the notifications [#25501]

26.8
-----
Expand Down