Added a zoom view to see the images better!!

This commit is contained in:
breadone 2024-07-03 21:53:03 +12:00
parent c1f584b1e1
commit 062545b4ff
No known key found for this signature in database

View File

@ -10,6 +10,8 @@ import SwiftUI
struct ScanItemView: View {
@Environment(\.modelContext) var ctx
@State private var isZoomed = false
let scan: Scan
private let translucentColour = Color(red: 0.6, green: 0.8, blue: 1, opacity: 0.4)
@ -18,53 +20,81 @@ struct ScanItemView: View {
}
var body: some View {
HStack {
Image(uiImage: scan.uiImages.first ?? UIImage(systemName: "questionmark")!)
.resizable()
.scaledToFit()
.frame(maxWidth: 70, maxHeight: 70)
.padding(4)
.background(translucentColour)
.clipShape(RoundedRectangle(cornerRadius: 12))
VStack(alignment: .leading) {
Text("\(scan.uiImages.count) \(scan.uiImages.count == 1 ? "Page" : "Pages")")
.font(.title3)
Text("\(scan.timestamp.formatted())")
.font(.footnote)
}
.foregroundStyle(.white)
Spacer()
if scan.images.count == 1 {
Button { scan.copyImages() } label: {
Image(systemName: "doc.on.doc.fill").tint(.white)
VStack {
HStack {
if !isZoomed {
Image(uiImage: scan.uiImages.first ?? UIImage(systemName: "questionmark")!)
.resizable()
.scaledToFit()
.frame(maxWidth: 70, maxHeight: 70)
.padding(4)
.background(translucentColour)
.clipShape(RoundedRectangle(cornerRadius: 12))
.onTapGesture {
withAnimation(.linear) {
isZoomed = true
}
}
}
VStack(alignment: .leading) {
Text("\(scan.uiImages.count) \(scan.uiImages.count == 1 ? "Page" : "Pages")")
.font(.title3)
Text("\(scan.timestamp.formatted())")
.font(.footnote)
}
.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())
}
}
ShareLink(items: scan.suiImages, preview: { _ in SharePreview("Scan", image: scan.suiImages.first!)} ) {
Image(systemName: "square.and.arrow.up").tint(.white)
.padding(8)
.background(translucentColour)
.offset(y: -2)
.clipShape(Circle())
}
Button { delete() } label: {
Image(systemName: "xmark").bold().tint(.red)
.padding(8)
.background(translucentColour)
.clipShape(Circle())
}
.contextMenu(menuItems: {
Button("Delete All Scans", role: .destructive) {
deleteAll()
}
})
}
ShareLink(items: scan.suiImages, preview: { _ in SharePreview("Scan", image: scan.suiImages.first!)} ) {
Image(systemName: "square.and.arrow.up").tint(.white)
.padding(8)
.background(translucentColour)
.offset(y: -2)
.clipShape(Circle())
}
Button { delete() } label: {
Image(systemName: "trash.fill").tint(.red)
.padding(8)
.background(translucentColour)
.clipShape(Circle())
}
.contextMenu(menuItems: {
Button("Delete All Scans", role: .destructive) {
deleteAll()
if isZoomed {
TabView {
ForEach(scan.uiImages, id: \.self) { img in
Image(uiImage: img)
.resizable()
.scaledToFit()
.frame(maxHeight: 400)
.onTapGesture {
withAnimation(.linear) {
isZoomed = false
}
}
}
}
})
.frame(height: 400)
.tabViewStyle(PageTabViewStyle())
}
}
.padding()
.background(Color(red: 0.4, green: 0.6, blue: 0.9, opacity: 0.8))