mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-18 23:17:02 +01:00
52 lines
976 B
Swift
52 lines
976 B
Swift
//
|
|
// Demo
|
|
// Copyright © 2020 John Rommel Estropia, Inc. All rights reserved.
|
|
|
|
import Combine
|
|
import SwiftUI
|
|
|
|
// MARK: - NetworkImageView
|
|
|
|
struct NetworkImageView: View {
|
|
|
|
// MARK: Internal
|
|
|
|
init(url: URL?) {
|
|
|
|
self.imageDownloader = .init(url: url)
|
|
}
|
|
|
|
|
|
// MARK: View
|
|
|
|
var body: some View {
|
|
|
|
if let image = self.imageDownloader.image {
|
|
|
|
return AnyView(
|
|
Image(uiImage: image)
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fit)
|
|
)
|
|
}
|
|
else {
|
|
|
|
return AnyView(
|
|
Circle()
|
|
.colorMultiply(Color(UIColor.placeholderText))
|
|
.onAppear {
|
|
|
|
self.imageDownloader.fetchImage()
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
// MARK: Private
|
|
|
|
@ObservedObject
|
|
private var imageDownloader: ImageDownloader
|
|
}
|
|
|