Created
March 22, 2021 02:42
-
-
Save MatthewWaller/e028878b35f56a905c554663b16c468d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import PDFKit | |
import SwiftUI | |
struct ContentView: View { | |
@StateObject var manager = PDFManager() | |
@Binding var document: PDFTrapperDocument | |
@State var showScanner = false | |
@State var isEditing = false | |
var fileURL: URL? | |
private func save() { | |
document.setAsNotBlank() | |
document.saveTrigger.toggle() | |
} | |
var body: some View { | |
ZStack { | |
if let url = fileURL { | |
QuickLookController(startEditing: manager.startEditMode, url: url) { | |
if let refreshedPDF = PDFDocument(url: url) { | |
document.pdf = refreshedPDF | |
manager.saveReporter.send() | |
isEditing = false | |
} | |
} | |
} | |
if showScanner { | |
ScannerView { images in | |
manager.addPhotos(images, toPDFDocument: document) | |
withAnimation { | |
showScanner = false | |
} | |
} | |
} else { | |
if !isEditing { | |
VStack { | |
PDFDisplayView(pdf: document.pdf) | |
Button("Editing Canvas") { | |
isEditing = true | |
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { | |
manager.startEditMode.send() | |
} | |
} | |
} | |
.transition(AnyTransition.opacity.animation(.default)) | |
} | |
} | |
if isEditing { | |
ProgressView() | |
} | |
} | |
.onAppear { | |
if document.isBlank { | |
showScanner = true | |
} | |
} | |
.onReceive(manager.saveReporter, perform: save) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment