Skip to content

Instantly share code, notes, and snippets.

@kean
Last active Nov 13, 2020
Embed
What would you like to do?
FetchedImage
public struct ImageView: View {
@ObservedObject var image: FetchImage
public var body: some View {
ZStack {
Rectangle().fill(Color.gray)
image.view?
.resizable()
.aspectRatio(contentMode: .fill)
}
// (Optional) Animate image appearance
.animation(.default)
// (Optional) Cancel and restart requests during scrollings
.onAppear(perform: image.fetch)
.onDisappear(perform: image.cancel)
}
}
struct ImageView_Previews: PreviewProvider {
static var previews: some View {
ImageView(image: FetchImage(url: demoPhotosURLs[0]))
.frame(width: 80, height: 80)
.clipped()
}
}
Moved to https://github.com/kean/FetchImage
@kean
Copy link
Author

kean commented Mar 19, 2020

I moved the implementation to a separate repo https://github.com/kean/FetchImage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment