Voxley / app / Sources / Voxley / RecorderTranscript.swift
| 1 | import SwiftUI |
| 2 | |
| 3 | struct RecorderTranscript: View { |
| 4 | let text: String |
| 5 | let status: String |
| 6 | |
| 7 | var body: some View { |
| 8 | let hasTranscript = !text.isEmpty |
| 9 | let font = Font.system(size: 13, weight: hasTranscript ? .medium : .regular) |
| 10 | |
| 11 | // Measure three lines using the same font as the transcript. |
| 12 | Text("Ag\nAg\nAg") |
| 13 | .font(font) |
| 14 | .hidden() |
| 15 | .frame(maxWidth: .infinity, alignment: .leading) |
| 16 | .overlay { |
| 17 | ScrollView(.vertical) { |
| 18 | Text(verbatim: hasTranscript ? text : status) |
| 19 | .font(font) |
| 20 | .foregroundStyle(hasTranscript ? .primary : .secondary) |
| 21 | .fixedSize(horizontal: false, vertical: true) |
| 22 | .frame(maxWidth: .infinity, alignment: .leading) |
| 23 | } |
| 24 | .defaultScrollAnchor(.bottom) |
| 25 | .defaultScrollAnchor(.top, for: .alignment) |
| 26 | .scrollIndicators(.hidden) |
| 27 | .allowsHitTesting(false) |
| 28 | } |
| 29 | .accessibilityElement(children: .ignore) |
| 30 | .accessibilityLabel(hasTranscript ? "Live transcript: \(text)" : status) |
| 31 | } |
| 32 | } |