Skip to content

Commit

Permalink
Load remote images.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagavcindriqim committed Sep 23, 2024
1 parent 4d50139 commit 764778f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreviewItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct PhotoPreviewItemView: View {
typealias VoidHandler = () -> Swift.Void
typealias DragHandler = (CGFloat) -> Swift.Void

@StateObject var imageLoader = PhotoPreviewImageLoader()
@Binding var dragEnabled: Bool
@Binding var currentIndex: Int
@Binding var verticalOffset: CGFloat
Expand Down Expand Up @@ -85,7 +86,29 @@ extension PhotoPreviewItemView {
}
.scaledToFit()
#else
URLImageView(from: item.url, placeholder: item.placeholder)
Group {
switch imageLoader.state {
case .loading:
ProgressView()
.progressViewStyle(.circular)
.frame(width: 50, height: 50)
.task {
await imageLoader.loadImage(from: item.url)
}
case .loaded(let image):
Image(uiImage: image)
.resizable()
.scaledToFit()
case .failed:
if let placeholder = item.placeholder {
placeholder
.resizable()
.scaledToFit()
} else {
Color.clear
}
}
}
#endif
}
}
Expand Down

0 comments on commit 764778f

Please sign in to comment.