-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Markdown
: Add zoomable image previews (#101)
* Add image preview struct and environment key * Make preview zoomable
- Loading branch information
Showing
2 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// ZoomableImagePreview.swift | ||
// ArtemisCore | ||
// | ||
// Created by Anian Schleyer on 14.11.24. | ||
// | ||
|
||
import PDFKit | ||
import SwiftUI | ||
|
||
// Adapted from https://stackoverflow.com/a/67577296 | ||
struct ZoomableImagePreview: UIViewRepresentable { | ||
let image: UIImage | ||
|
||
func makeUIView(context: Context) -> PDFView { | ||
let view = PDFView() | ||
view.document = PDFDocument() | ||
guard let page = PDFPage(image: image) else { return view } | ||
view.document?.insert(page, at: 0) | ||
view.autoScales = true | ||
DispatchQueue.main.async { | ||
view.minScaleFactor = max(view.scaleFactorForSizeToFit * 0.8, 0) | ||
view.maxScaleFactor = view.minScaleFactor + 5 | ||
} | ||
return view | ||
} | ||
|
||
func updateUIView(_ uiView: PDFView, context: Context) {} | ||
} |