77
88import SwiftUI
99
10- /// A view for previewing an image, while respecting its image dimensions.
10+ /// A view for previewing an image, while respecting its dimensions.
1111///
1212/// It receives a URL to an image file and attempts to preview it.
1313///
@@ -18,20 +18,13 @@ import SwiftUI
1818/// the size of the image view area.
1919///
2020/// 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.
2421struct ImageFileView : View {
2522
2623 /// URL of the image you want to preview.
2724 private let imageURL : URL
2825
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 ) {
3327 self . imageURL = imageURL
34- self . isGif = isGif
3528 }
3629
3730 var body : some View {
@@ -43,21 +36,11 @@ struct ImageFileView: View {
4336
4437 GeometryReader { proxy in
4538 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+ )
6144 }
6245 . frame ( width: proxy. size. width, height: proxy. size. height)
6346 }
0 commit comments