Skip to content

Commit dda4d34

Browse files
committed
use AnyFileView to view all images
- this removes the need to check for GIF images - this also has a nice add-on of using gestures for zoom
1 parent 950d7ed commit dda4d34

File tree

3 files changed

+7
-32
lines changed

3 files changed

+7
-32
lines changed

CodeEdit/Features/Documents/CodeFileDocument.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ final class CodeFileDocument: NSDocument, ObservableObject {
6060
if type.conforms(to: .text) {
6161
return .text
6262
}
63-
// GIF conforms to image, so to differentiate, the GIF check has to come before the image check.
64-
if type.conforms(to: .gif) {
65-
return .gif
66-
}
6763
if type.conforms(to: .image) {
6864
return .image
6965
}

CodeEdit/Features/Editor/Views/ImageFileView.swift

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import 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.
2421
struct 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
}

CodeEdit/Features/Editor/Views/NonTextFileView.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ struct NonTextFileView: View {
2222
if let fileURL = fileDocument.fileURL {
2323

2424
switch fileDocument.utType {
25-
case .some(.gif):
26-
// GIF conforms to image, so to differentiate, the GIF check has to come before the image check.
27-
ImageFileView(fileURL, isGif: true)
28-
2925
case .some(.image):
3026
ImageFileView(fileURL)
3127

0 commit comments

Comments
 (0)