YEEEAH massively improved performance and actually made it usable lets GO

basically just stopped using uiimages unless i absolutely had to lol
This commit is contained in:
breadone 2024-07-04 00:07:21 +12:00
parent fc005d8183
commit 77e7ef9319
No known key found for this signature in database
3 changed files with 50 additions and 26 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "262CD1B0-1BB9-4498-9D1F-FE78C6A609F3"
type = "1"
version = "2.0">
</Bucket>

View File

@ -15,31 +15,44 @@ final class Scan {
let timestamp: Date let timestamp: Date
var images: [Data] var images: [Data]
var uiImages: [UIImage] { var imageCount: Int
self.images.map { UIImage(data: $0) ?? UIImage(systemName: "exclamationmark.questionmark")! }
}
var suiImages: [Image] { // var uiImages: [UIImage] {
self.images.map { Image(uiImage: UIImage(data: $0) ?? UIImage(systemName: "exclamationmark.questionmark")!) } // 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() { init() {
self.timestamp = Date() self.timestamp = Date()
self.images = [] self.images = []
self.imageCount = 0
} }
init(images: [Data]) { init(images: [Data]) {
self.timestamp = Date() self.timestamp = Date()
self.images = images self.images = images
self.imageCount = images.count
} }
init(images: [UIImage]) { init(images: [UIImage]) {
self.timestamp = Date() self.timestamp = Date()
self.images = images.map{ $0.pngData() ?? Data() } 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() { public func copyImages() {
UIPasteboard.general.images = self.uiImages UIPasteboard.general.images = self.toUIImages()
} }
} }

View File

@ -14,33 +14,38 @@ struct ScanItemView: View {
@State private var isZoomed = false @State private var isZoomed = false
let scan: Scan let scan: Scan
let images: [Image]
let uiImages: [UIImage]
private let translucentColour = Color(red: 0.6, green: 0.8, blue: 1, opacity: 0.4) private let translucentColour = Color(red: 0.6, green: 0.8, blue: 1, opacity: 0.4)
init(_ scan: Scan) { init(_ scan: Scan) {
self.scan = scan self.scan = scan
self.images = scan.toSwiftUIImages()
self.uiImages = scan.toUIImages()
} }
var body: some View { var body: some View {
VStack { LazyVStack {
HStack { HStack {
if !isZoomed { if !isZoomed {
Image(uiImage: scan.uiImages.first ?? UIImage(systemName: "questionmark")!) self.images.first!
.resizable() .resizable()
.scaledToFit() .scaledToFit()
.matchedGeometryEffect(id: "images", in: animation) .matchedGeometryEffect(id: "images", in: animation)
.frame(maxWidth: 70, maxHeight: 70) .frame(maxWidth: 70, maxHeight: 70)
.padding(4) .padding(4)
.background(translucentColour) // .background(translucentColour)
.clipShape(RoundedRectangle(cornerRadius: 12)) // .clipShape(RoundedRectangle(cornerRadius: 12))
.onTapGesture { .onTapGesture {
withAnimation(.spring) { withAnimation(.easeInOut(duration: 0.3)) {
isZoomed = true isZoomed = true
} }
} }
} }
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text("\(scan.uiImages.count) \(scan.uiImages.count == 1 ? "Page" : "Pages")") Text("\(scan.imageCount) \(scan.imageCount == 1 ? "Page" : "Pages")")
.font(.title3) .font(.title3)
Text("\(scan.timestamp.formatted())") Text("\(scan.timestamp.formatted())")
.font(.footnote) .font(.footnote)
@ -48,16 +53,16 @@ struct ScanItemView: View {
.foregroundStyle(.white) .foregroundStyle(.white)
Spacer() Spacer()
if scan.images.count == 1 { // if scan.images.count == 1 {
Button { scan.copyImages() } label: { // Button { scan.copyImages() } label: {
Image(systemName: "doc.on.doc.fill").tint(.white) // Image(systemName: "doc.on.doc.fill").tint(.white)
.padding(8) // .padding(8)
.background(translucentColour) // .background(translucentColour)
.clipShape(Circle()) // .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) Image(systemName: "square.and.arrow.up").tint(.white)
.padding(8) .padding(8)
.background(translucentColour) .background(translucentColour)
@ -76,18 +81,18 @@ struct ScanItemView: View {
deleteAll() deleteAll()
} }
}) })
//
} }
if isZoomed { if isZoomed {
TabView { TabView {
ForEach(scan.uiImages, id: \.self) { img in ForEach(self.uiImages, id: \.self) { img in
Image(uiImage: img) Image(uiImage: img)
.resizable() .resizable()
.scaledToFit() .scaledToFit()
.frame(maxHeight: 400) .frame(maxHeight: 400)
.onTapGesture { .onTapGesture {
withAnimation(.spring) { withAnimation(.easeInOut(duration: 0.3)) {
isZoomed = false isZoomed = false
} }
} }
@ -95,7 +100,7 @@ struct ScanItemView: View {
} }
.matchedGeometryEffect(id: "images", in: animation) .matchedGeometryEffect(id: "images", in: animation)
.frame(height: 400) .frame(height: 400)
.tabViewStyle(PageTabViewStyle()) .tabViewStyle(.page(indexDisplayMode: .never))
} }
} }