Files
sst/Sources/Sst/ListSupport.swift
T

51 lines
1.6 KiB
Swift

import SstUI
import SwiftUI
/// Debug snapshots (`Sst --snapshot`) are drawn by `ImageRenderer`, which cannot draw scroll views or text fields.
/// While rendering one, the views below fall back to plain stacks and text.
@MainActor
enum SnapshotMode {
static var isActive = false
}
/// A scrolling, lazily built list (a plain stack while a snapshot is rendered).
struct ScrollList<Content: View>: View {
@ViewBuilder var content: Content
var body: some View {
if SnapshotMode.isActive {
VStack(alignment: .leading, spacing: 0) { content }
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
} else {
ScrollView {
LazyVStack(alignment: .leading, spacing: 0, pinnedViews: .sectionHeaders) { content }
}
}
}
}
/// The recessed "ZOEK" field.
struct SearchField: View {
@Binding var text: String
var focused: FocusState<Bool>.Binding
var body: some View {
HStack(spacing: Space.s4) {
SilkLabel(Strings.search)
Group {
if SnapshotMode.isActive {
Text(text).frame(maxWidth: .infinity, alignment: .leading)
} else {
TextField("", text: $text)
.textFieldStyle(.plain)
.focused(focused)
}
}
.textStyle(Typography.body)
.foregroundStyle(Palette.inkPrimary)
.padding(Space.s3)
.background(WellBackground())
}
}
}