Two main changes here: - Wait for JS highlight methods to complete, if an error occurs post that error back to Swift. - When creating a highlight with a note, post a message back to Swift to signify success. We wait for that message instead of closing immediately, so that a user doesn't lose their note if creating the highlight failed.
60 lines
1.4 KiB
Swift
60 lines
1.4 KiB
Swift
import Introspect
|
|
import SwiftUI
|
|
|
|
public struct HighlightAnnotationSheet: View {
|
|
@Binding var annotation: String
|
|
@Binding var errorAlertMessage: String?
|
|
@Binding var showErrorAlertMessage: Bool
|
|
|
|
let onSave: () -> Void
|
|
let onCancel: () -> Void
|
|
|
|
public init(
|
|
annotation: Binding<String>,
|
|
onSave: @escaping () -> Void,
|
|
onCancel: @escaping () -> Void,
|
|
errorAlertMessage: Binding<String?>,
|
|
showErrorAlertMessage: Binding<Bool>
|
|
) {
|
|
self._annotation = annotation
|
|
self.onSave = onSave
|
|
self.onCancel = onCancel
|
|
self._errorAlertMessage = errorAlertMessage
|
|
self._showErrorAlertMessage = showErrorAlertMessage
|
|
}
|
|
|
|
public var body: some View {
|
|
VStack {
|
|
HStack {
|
|
Button("Cancel", action: onCancel)
|
|
Spacer()
|
|
Label("Note", systemImage: "note.text")
|
|
Spacer()
|
|
Button("Save") {
|
|
onSave()
|
|
}
|
|
}
|
|
.foregroundColor(.appGrayTextContrast)
|
|
|
|
ScrollView {
|
|
TextEditor(text: $annotation)
|
|
.frame(height: 200)
|
|
#if os(iOS)
|
|
.introspectTextView {
|
|
$0.becomeFirstResponder()
|
|
}
|
|
#endif
|
|
}
|
|
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
.alert(errorAlertMessage ?? "An error occurred", isPresented: $showErrorAlertMessage) {
|
|
Button("Ok", role: .cancel, action: {
|
|
errorAlertMessage = nil
|
|
showErrorAlertMessage = false
|
|
})
|
|
}
|
|
}
|
|
}
|