Last active
November 13, 2020 20:48
-
-
Save kean/c40df0a9fef31c377757882ac30296dc to your computer and use it in GitHub Desktop.
FetchedImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Moved to https://github.com/kean/FetchImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I moved the implementation to a separate repo https://github.com/kean/FetchImage