summaryrefslogtreecommitdiff
path: root/Juick/Views/LoadableImageView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/Views/LoadableImageView.swift')
-rw-r--r--Juick/Views/LoadableImageView.swift35
1 files changed, 35 insertions, 0 deletions
diff --git a/Juick/Views/LoadableImageView.swift b/Juick/Views/LoadableImageView.swift
new file mode 100644
index 0000000..e639602
--- /dev/null
+++ b/Juick/Views/LoadableImageView.swift
@@ -0,0 +1,35 @@
+//
+// LoadableImageView.swift
+// tst
+//
+// Created by Vitaly Takmazov on 10.12.2019.
+// Copyright © 2019 com.juick. All rights reserved.
+//
+
+import SwiftUI
+
+struct LoadableImageView: View {
+ @ObservedObject var imageFetcher: ImageFetcher
+
+ init(with urlString: String) {
+ imageFetcher = ImageFetcher(url: urlString)
+ }
+
+ var body: some View {
+ if let image = UIImage(data: imageFetcher.data) {
+ return AnyView(
+ Image(uiImage: image).resizable()
+ )
+ } else {
+ return AnyView(
+ ActivityIndicator(style: .medium)
+ )
+ }
+ }
+}
+
+struct LoadableImageView_Previews: PreviewProvider {
+ static var previews: some View {
+ LoadableImageView(with: "https://i.juick.com/a/1.png")
+ }
+}