Files
omnivore/apple/OmnivoreKit/Sources/Views/Article/HighlightAnnotationSheet.swift
2023-04-10 15:59:40 +08:00

60 lines
1.5 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(LocalText.cancelGeneric, action: onCancel)
Spacer()
Text("Note").font(Font.system(size: 14, weight: .medium))
Spacer()
Button(LocalText.genericSave) {
onSave()
}
}
.foregroundColor(.appGrayTextContrast)
ScrollView {
TextEditor(text: $annotation)
.frame(height: 200)
#if os(iOS)
.introspectTextView {
$0.becomeFirstResponder()
}
#endif
}
Spacer()
}
.padding()
.alert(errorAlertMessage ?? LocalText.readerError, isPresented: $showErrorAlertMessage) {
Button(LocalText.genericOk, role: .cancel, action: {
errorAlertMessage = nil
showErrorAlertMessage = false
})
}
}
}