Skip to content

Instantly share code, notes, and snippets.

@kean
Last active November 13, 2020 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kean/c40df0a9fef31c377757882ac30296dc to your computer and use it in GitHub Desktop.
Save kean/c40df0a9fef31c377757882ac30296dc to your computer and use it in GitHub Desktop.
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