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
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()
}
}

View File

@ -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))
}
}