Skip to content

Commit

Permalink
use AnyFileView to view all images
Browse files Browse the repository at this point in the history
- this removes the need to check for GIF images
- this also has a nice add-on of using gestures for zoom
  • Loading branch information
plbstl committed May 10, 2024
1 parent 950d7ed commit 8069cbc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
4 changes: 0 additions & 4 deletions CodeEdit/Features/Documents/CodeFileDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ final class CodeFileDocument: NSDocument, ObservableObject {
if type.conforms(to: .text) {
return .text
}
// GIF conforms to image, so to differentiate, the GIF check has to come before the image check.
if type.conforms(to: .gif) {
return .gif
}
if type.conforms(to: .image) {
return .image
}
Expand Down
20 changes: 5 additions & 15 deletions CodeEdit/Features/Editor/Views/ImageFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,11 @@ struct ImageFileView: View {

GeometryReader { proxy in
ZStack {
if isGif {
AnyFileView(imageURL)
.frame(
maxWidth: min(pixelWidth, proxy.size.width, nsImage.size.width),
maxHeight: min(pixelHeight, proxy.size.height, nsImage.size.height)
)
} else {
Image(nsImage: nsImage)
.resizable()
.scaledToFit()
.frame(
maxWidth: min(pixelWidth, proxy.size.width, nsImage.size.width),
maxHeight: min(pixelHeight, proxy.size.height, nsImage.size.height)
)
}
AnyFileView(imageURL)
.frame(
maxWidth: min(pixelWidth, proxy.size.width, nsImage.size.width),
maxHeight: min(pixelHeight, proxy.size.height, nsImage.size.height)
)
}
.frame(width: proxy.size.width, height: proxy.size.height)
}
Expand Down
4 changes: 0 additions & 4 deletions CodeEdit/Features/Editor/Views/NonTextFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ struct NonTextFileView: View {
if let fileURL = fileDocument.fileURL {

switch fileDocument.utType {
case .some(.gif):
// GIF conforms to image, so to differentiate, the GIF check has to come before the image check.
ImageFileView(fileURL, isGif: true)

case .some(.image):
ImageFileView(fileURL)

Expand Down

0 comments on commit 8069cbc

Please sign in to comment.