summaryrefslogtreecommitdiff
path: root/Juick/Views/LoadableImageView.swift
blob: e639602b1a900f94ce1dd626b85a8f068fc6db89 (plain) (blame)
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
//
//  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")
    }
}