From 77e7ef9319200510da9b39e2034a35808fac392c Mon Sep 17 00:00:00 2001 From: breadone Date: Thu, 4 Jul 2024 00:07:21 +1200 Subject: [PATCH] YEEEAH massively improved performance and actually made it usable lets GO basically just stopped using uiimages unless i absolutely had to lol --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 6 +++ JustScanIt/Model/Scan.swift | 27 +++++++++--- JustScanIt/View/ScanItemView.swift | 43 +++++++++++-------- 3 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 JustScanIt.xcodeproj/xcuserdata/pradyun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist diff --git a/JustScanIt.xcodeproj/xcuserdata/pradyun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/JustScanIt.xcodeproj/xcuserdata/pradyun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..962f8e1 --- /dev/null +++ b/JustScanIt.xcodeproj/xcuserdata/pradyun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + + diff --git a/JustScanIt/Model/Scan.swift b/JustScanIt/Model/Scan.swift index 7fc2297..9ecd999 100644 --- a/JustScanIt/Model/Scan.swift +++ b/JustScanIt/Model/Scan.swift @@ -15,31 +15,44 @@ final class Scan { let timestamp: Date var images: [Data] - var uiImages: [UIImage] { - self.images.map { UIImage(data: $0) ?? UIImage(systemName: "exclamationmark.questionmark")! } - } + var imageCount: Int - var suiImages: [Image] { - self.images.map { Image(uiImage: UIImage(data: $0) ?? UIImage(systemName: "exclamationmark.questionmark")!) } - } +// var uiImages: [UIImage] { +// self.images.map { UIImage(data: $0) ?? UIImage(systemName: "exclamationmark.questionmark")! } +// } + +// var suiImages: [Image] { +// self.images.map { Image(uiImage: UIImage(data: $0) ?? UIImage(systemName: "exclamationmark.questionmark")!) } +// } init() { self.timestamp = Date() self.images = [] + self.imageCount = 0 } init(images: [Data]) { self.timestamp = Date() self.images = images + self.imageCount = images.count } init(images: [UIImage]) { self.timestamp = Date() self.images = images.map{ $0.pngData() ?? Data() } + self.imageCount = images.count + } + + public func toSwiftUIImages() -> [Image] { + self.images.map { Image(uiImage: UIImage(data: $0) ?? UIImage(systemName: "exclamationmark.questionmark")!) } + } + + public func toUIImages() -> [UIImage] { + self.images.map { UIImage(data: $0) ?? UIImage(systemName: "exclamationmark.questionmark")! } } public func copyImages() { - UIPasteboard.general.images = self.uiImages + UIPasteboard.general.images = self.toUIImages() } } diff --git a/JustScanIt/View/ScanItemView.swift b/JustScanIt/View/ScanItemView.swift index dacea19..4a2f0a4 100644 --- a/JustScanIt/View/ScanItemView.swift +++ b/JustScanIt/View/ScanItemView.swift @@ -14,33 +14,38 @@ struct ScanItemView: View { @State private var isZoomed = false let scan: Scan + let images: [Image] + let uiImages: [UIImage] + private let translucentColour = Color(red: 0.6, green: 0.8, blue: 1, opacity: 0.4) init(_ scan: Scan) { self.scan = scan + self.images = scan.toSwiftUIImages() + self.uiImages = scan.toUIImages() } var body: some View { - VStack { + LazyVStack { HStack { if !isZoomed { - Image(uiImage: scan.uiImages.first ?? UIImage(systemName: "questionmark")!) + self.images.first! .resizable() .scaledToFit() .matchedGeometryEffect(id: "images", in: animation) .frame(maxWidth: 70, maxHeight: 70) .padding(4) - .background(translucentColour) - .clipShape(RoundedRectangle(cornerRadius: 12)) +// .background(translucentColour) +// .clipShape(RoundedRectangle(cornerRadius: 12)) .onTapGesture { - withAnimation(.spring) { + withAnimation(.easeInOut(duration: 0.3)) { isZoomed = true } } } VStack(alignment: .leading) { - Text("\(scan.uiImages.count) \(scan.uiImages.count == 1 ? "Page" : "Pages")") + Text("\(scan.imageCount) \(scan.imageCount == 1 ? "Page" : "Pages")") .font(.title3) Text("\(scan.timestamp.formatted())") .font(.footnote) @@ -48,16 +53,16 @@ struct ScanItemView: View { .foregroundStyle(.white) Spacer() - if scan.images.count == 1 { - Button { scan.copyImages() } label: { - Image(systemName: "doc.on.doc.fill").tint(.white) - .padding(8) - .background(translucentColour) - .clipShape(Circle()) - } - } +// if scan.images.count == 1 { +// Button { scan.copyImages() } label: { +// Image(systemName: "doc.on.doc.fill").tint(.white) +// .padding(8) +// .background(translucentColour) +// .clipShape(Circle()) +// } +// } - ShareLink(items: scan.suiImages, preview: { _ in SharePreview("Scan", image: scan.suiImages.first!)} ) { + ShareLink(items: self.images, preview: { _ in SharePreview("Scan", image: self.images.first!)} ) { Image(systemName: "square.and.arrow.up").tint(.white) .padding(8) .background(translucentColour) @@ -76,18 +81,18 @@ struct ScanItemView: View { deleteAll() } }) - +// } if isZoomed { TabView { - ForEach(scan.uiImages, id: \.self) { img in + ForEach(self.uiImages, id: \.self) { img in Image(uiImage: img) .resizable() .scaledToFit() .frame(maxHeight: 400) .onTapGesture { - withAnimation(.spring) { + withAnimation(.easeInOut(duration: 0.3)) { isZoomed = false } } @@ -95,7 +100,7 @@ struct ScanItemView: View { } .matchedGeometryEffect(id: "images", in: animation) .frame(height: 400) - .tabViewStyle(PageTabViewStyle()) + .tabViewStyle(.page(indexDisplayMode: .never)) } }