7
7
8
8
import SwiftUI
9
9
10
- /// A view for previewing an image, while respecting its image dimensions.
10
+ /// A view for previewing an image, while respecting its dimensions.
11
11
///
12
12
/// It receives a URL to an image file and attempts to preview it.
13
13
///
@@ -18,20 +18,13 @@ import SwiftUI
18
18
/// the size of the image view area.
19
19
///
20
20
/// If the preview image cannot be created, it shows a *"Cannot preview image"* text.
21
- ///
22
- /// - Note: This view wraps around SwiftUI Image. Since SwiftUI Image view do not play GIFs, you should indicate
23
- /// when passing in a GIF file, so this view can handle the GIF file correctly.
24
21
struct ImageFileView : View {
25
22
26
23
/// URL of the image you want to preview.
27
24
private let imageURL : URL
28
25
29
- /// Indicates whether the image is a GIF.
30
- private let isGif : Bool
31
-
32
- init ( _ imageURL: URL , isGif: Bool = false ) {
26
+ init ( _ imageURL: URL ) {
33
27
self . imageURL = imageURL
34
- self . isGif = isGif
35
28
}
36
29
37
30
var body : some View {
@@ -43,21 +36,11 @@ struct ImageFileView: View {
43
36
44
37
GeometryReader { proxy in
45
38
ZStack {
46
- if isGif {
47
- AnyFileView ( imageURL)
48
- . frame (
49
- maxWidth: min ( pixelWidth, proxy. size. width, nsImage. size. width) ,
50
- maxHeight: min ( pixelHeight, proxy. size. height, nsImage. size. height)
51
- )
52
- } else {
53
- Image ( nsImage: nsImage)
54
- . resizable ( )
55
- . scaledToFit ( )
56
- . frame (
57
- maxWidth: min ( pixelWidth, proxy. size. width, nsImage. size. width) ,
58
- maxHeight: min ( pixelHeight, proxy. size. height, nsImage. size. height)
59
- )
60
- }
39
+ AnyFileView ( imageURL)
40
+ . frame (
41
+ maxWidth: min ( pixelWidth, proxy. size. width, nsImage. size. width) ,
42
+ maxHeight: min ( pixelHeight, proxy. size. height, nsImage. size. height)
43
+ )
61
44
}
62
45
. frame ( width: proxy. size. width, height: proxy. size. height)
63
46
}
0 commit comments