File tree Expand file tree Collapse file tree
DevLog/UI/Common/Componeent Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,7 +57,12 @@ struct CacheableImage<Content: View>: View {
5757
5858 @MainActor
5959 private func loadImageWithCache( ) async {
60- guard self . url != nil else { return }
60+ guard let url = self . url else { return }
61+
62+ if url. isFileURL {
63+ await loadLocalImage ( from: url)
64+ return
65+ }
6166
6267 if let cachedResponse = URLCache . imageCached. cachedResponse ( for: request) {
6368 if let uiImage = UIImage ( data: cachedResponse. data) {
@@ -81,6 +86,23 @@ struct CacheableImage<Content: View>: View {
8186 isInvalid = true
8287 }
8388 }
89+
90+ @MainActor
91+ private func loadLocalImage( from url: URL ) async {
92+ do {
93+ let data = try await Task . detached {
94+ try Data ( contentsOf: url)
95+ } . value
96+
97+ if let uiImage = UIImage ( data: data) {
98+ self . loadedUIImage = uiImage
99+ } else {
100+ isInvalid = true
101+ }
102+ } catch {
103+ isInvalid = true
104+ }
105+ }
84106}
85107
86108extension URLCache {
You can’t perform that action at this time.
0 commit comments