Repository Public
1// SP Notes iOS2// File: Features/Drawing/HandwritingSheet.swift3// Description: What was read in the framed handwriting, with its average confidence and the standing caveat. The text goes into4// the note only when the user asks: below the drawing, or in place of the strokes that were read.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SPNotesDesign9import SwiftUI10import UIKit1112struct HandwritingSheet: View {13 let proposal: HandwritingProposal14 /// False in a read-only note: copy only.15 var canInsert = true16 var onInsert: () -> Void17 var onReplace: () -> Void18 var onClose: () -> Void1920 var body: some View {21 NavigationStack {22 Group {23 if proposal.result.isEmpty {24 NVEmptyState(systemImage: "text.viewfinder", title: String(localized: "Aucun texte reconnu"),25 message: String(localized: "Encadre de plus près une écriture lisible, ou écris plus gros. La reconnaissance se fait sur l’appareil."))26 } else {27 content28 }29 }30 .background(NVColor.bg)31 .navigationTitle(Text("Écriture reconnue"))32 .navigationBarTitleDisplayMode(.inline)33 .toolbar {34 ToolbarItem(placement: .cancellationAction) {35 Button(action: onClose) { Text("Fermer") }.accessibilityIdentifier("handwriting-close")36 }37 }38 }39 .pencilSheetDetents()40 }4142 private var content: some View {43 ScrollView {44 VStack(alignment: .leading, spacing: NVSpace.lg) {45 Text(verbatim: proposal.result.text)46 .nvFont(.reading)47 .foregroundStyle(NVColor.fg)48 .textSelection(.enabled)49 .frame(maxWidth: .infinity, alignment: .leading)50 .padding(NVSpace.lg)51 .nvCard()52 .accessibilityIdentifier("handwriting-text")53 HStack(alignment: .firstTextBaseline, spacing: NVSpace.sm) {54 Image(systemName: "exclamationmark.triangle").foregroundStyle(NVColor.warning).accessibilityHidden(true)55 VStack(alignment: .leading, spacing: NVSpace.xxs) {56 Text("Reconnaissance sur l’appareil — à relire").nvFont(.uiStrong).foregroundStyle(NVColor.fg)57 Text("Confiance moyenne : \(proposal.result.confidencePercent) %").nvFont(.ui).foregroundStyle(NVColor.fgMuted)58 .accessibilityIdentifier("handwriting-confidence")59 }60 }61 .accessibilityElement(children: .combine)62 VStack(spacing: NVSpace.sm) {63 if canInsert {64 Button(action: onInsert) { Label("Insérer sous le dessin", systemImage: "text.insert") }65 .buttonStyle(PrimaryButtonStyle())66 .accessibilityIdentifier("handwriting-insert")67 Button(action: onReplace) { Label("Remplacer le dessin sélectionné", systemImage: "arrow.triangle.swap").frame(maxWidth: .infinity, minHeight: 44) }68 .buttonStyle(.bordered)69 .accessibilityIdentifier("handwriting-replace")70 }71 Button {72 UIPasteboard.general.string = proposal.result.text73 Haptics.success()74 onClose()75 } label: { Label("Copier", systemImage: "doc.on.doc").frame(maxWidth: .infinity, minHeight: 44) }76 .buttonStyle(.bordered)77 .accessibilityIdentifier("handwriting-copy")78 }79 if canInsert {80 Text("Le texte est ajouté à la note quand tu enregistres le dessin avec « Terminé ».")81 .nvFont(.micro).foregroundStyle(NVColor.fgMuted)82 }83 }84 .padding(NVSpace.lg)85 .frame(maxWidth: NVSpace.readingMeasure)86 .frame(maxWidth: .infinity)87 }88 }89}90