Files
voice-cat/clients/apple/iOS/VoiceCatiOS/Views/ActivityLogView.swift

50 lines
1.7 KiB
Swift
Raw Normal View History

import SwiftUI
struct ActivityLogView: View {
@Bindable var session: SessionState
private static let timeFormatter: DateFormatter = {
let fmt = DateFormatter()
fmt.dateStyle = .none
fmt.timeStyle = .medium
return fmt
}()
var body: some View {
ScrollViewReader { proxy in
List(session.activityLog) { entry in
HStack(alignment: .top, spacing: 8) {
Text(Self.timeFormatter.string(from: entry.timestamp))
.font(.caption2)
.foregroundStyle(.secondary)
.monospacedDigit()
.frame(width: 64, alignment: .leading)
Text(entry.text)
.font(.caption)
}
.id(entry.id)
.listRowSeparator(.hidden)
.accessibilityElement(children: .combine)
.accessibilityLabel("\(Self.timeFormatter.string(from: entry.timestamp)): \(entry.text)")
}
.listStyle(.plain)
.onChange(of: session.activityLog.count) { _, _ in
if let last = session.activityLog.last {
proxy.scrollTo(last.id, anchor: .bottom)
}
}
}
.navigationTitle("Activity")
.navigationBarTitleDisplayMode(.inline)
.overlay {
if session.activityLog.isEmpty {
ContentUnavailableView(
"No Activity",
systemImage: "bell.slash",
description: Text("Events will appear here as they happen.")
)
}
}
}
}