mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-19 07:54:05 +01:00
feat: update photo preview
This commit is contained in:
@@ -61,12 +61,11 @@ final class PenStroke: Stroke, @unchecked Sendable {
|
||||
|
||||
convenience init(object: StrokeObject) {
|
||||
let style = StrokeStyle(rawValue: object.style) ?? .marker
|
||||
#warning("TODO: revisit here and check if there is any crash")
|
||||
self.init(
|
||||
bounds: object.bounds,
|
||||
color: object.color,
|
||||
style: style,
|
||||
createdAt: object.createdAt ?? .now, // sometimes crash here
|
||||
createdAt: object.createdAt ?? .now,
|
||||
thickness: object.thickness
|
||||
)
|
||||
self.object = object
|
||||
|
||||
@@ -125,10 +125,10 @@ public class Tool: NSObject, ObservableObject {
|
||||
|
||||
func selectPhoto(_ image: UIImage, for canvasID: NSManagedObjectID) {
|
||||
guard let (resizedImage, dimension) = resizePhoto(of: image) else { return }
|
||||
let photoItem = bookmarkPhoto(of: resizedImage, in: dimension, with: canvasID)
|
||||
isLoadingPhoto = false
|
||||
let photoItem = bookmarkPhoto(of: resizedImage, and: image, in: dimension, with: canvasID)
|
||||
withAnimation {
|
||||
selectedPhotoItem = photoItem
|
||||
isLoadingPhoto = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class Tool: NSObject, ObservableObject {
|
||||
return (newImage, dimension)
|
||||
}
|
||||
|
||||
private func bookmarkPhoto(of image: UIImage, in dimension: CGSize, with canvasID: NSManagedObjectID) -> PhotoItem? {
|
||||
private func bookmarkPhoto(of image: UIImage, and previewImage: UIImage, in dimension: CGSize, with canvasID: NSManagedObjectID) -> PhotoItem? {
|
||||
guard let data = image.jpegData(compressionQuality: 1) else { return nil }
|
||||
let fileManager = FileManager.default
|
||||
guard let directory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
|
||||
@@ -180,7 +180,7 @@ public class Tool: NSObject, ObservableObject {
|
||||
var photoBookmark: PhotoItem?
|
||||
do {
|
||||
let bookmark = try file.bookmarkData(options: .minimalBookmark)
|
||||
photoBookmark = PhotoItem(id: file, image: image, dimension: dimension, bookmark: bookmark)
|
||||
photoBookmark = PhotoItem(id: file, image: image, previewImage: previewImage, dimension: dimension, bookmark: bookmark)
|
||||
} catch {
|
||||
NSLog("[Memola] - \(error.localizedDescription)")
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import Foundation
|
||||
struct PhotoItem: Identifiable, Equatable {
|
||||
var id: URL
|
||||
let image: UIImage
|
||||
let previewImage: UIImage
|
||||
let dimension: CGSize
|
||||
let bookmark: Data
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ struct PhotoPreview: View {
|
||||
@ObservedObject var tool: Tool
|
||||
|
||||
var body: some View {
|
||||
Image(uiImage: photoItem.image)
|
||||
Image(uiImage: photoItem.previewImage)
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(width: 100, height: 100)
|
||||
.scaledToFit()
|
||||
.frame(height: 100)
|
||||
.cornerRadius(5)
|
||||
.overlay {
|
||||
RoundedRectangle(cornerRadius: 5)
|
||||
|
||||
Reference in New Issue
Block a user