forked from schmidyy/SwiftUI-ListFetching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViews.swift
41 lines (34 loc) · 1.04 KB
/
Views.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// Views.swift
// Products
//
// Created by Mat Schmid on 2019-06-10.
// Copyright © 2019 Shopify. All rights reserved.
//
import SwiftUI
struct ActivityIndicator: UIViewRepresentable {
let style: UIActivityIndicatorView.Style
func makeUIView(context: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {
return UIActivityIndicatorView(style: style)
}
func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<ActivityIndicator>) {
uiView.startAnimating()
}
}
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)
)
}
}
}