Files
OpenAppLock/Severed/Views/Rules/NewRuleSheet.swift
Brendan Chen 2d609043f3 refactor: re-skin UI with native iOS components
Replace the Opal-style custom presentation with the bare iOS design
language, keeping the backend, flows, and accessibility identifiers:

- Home: NavigationStack + List; rules now presented as list rows with
  kind icon, block summary, and trailing live status; '+' in the toolbar
- New Rule: plain list of rule types and presets; editor still pushed
  via navigationDestination
- Editor: native Form (DatePicker rows, day circles with summary in the
  section header, toggle rows with footers, stepper rows); create
  commits with a prominent 'Add Rule' button replacing Hold to Commit;
  edit uses toolbar Done plus red Disable/Delete rows
- Detail: sheet with inline title + status caption, LabeledContent
  rows; Edit Rule pushes the editor natively
- Default color scheme: drop forced dark mode and custom tint; system
  appearance and accent throughout
- Delete Theme, HoldToCommitButton, RuleCardView and custom chrome
- Use concrete Color.primary/secondary in button row labels (the
  hierarchical styles resolve against the button tint)
- Tests: 93 passing; only delta is holdToCommitButton press →
  commitRuleButton tap in 5 call sites
- Spec: add §6 mapping the original presentation to the native one
2026-06-12 15:14:01 -04:00

112 lines
3.8 KiB
Swift

//
// NewRuleSheet.swift
// Severed
//
import SwiftData
import SwiftUI
/// "New Rule" as a plain list: a Rule Type section, then the preset sections.
/// Picking either pushes the editor; committing saves and closes the sheet.
struct NewRuleSheet: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.modelContext) private var modelContext
@State private var pendingDraft: RuleDraft?
var body: some View {
NavigationStack {
List {
Section {
ForEach(RuleKind.allCases, id: \.self) { kind in
kindRow(kind)
}
} header: {
Text("Rule Type").textCase(nil)
}
ForEach(RulePresetSection.all) { section in
Section {
ForEach(section.presets) { preset in
presetRow(preset)
}
} header: {
VStack(alignment: .leading, spacing: 2) {
Text(section.title)
Text(section.subtitle)
.font(.caption)
.foregroundStyle(.secondary)
}
.textCase(nil)
}
}
}
.navigationTitle("New Rule")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button("Close", systemImage: "xmark") {
dismiss()
}
.accessibilityIdentifier("closeNewRuleButton")
}
}
.navigationDestination(item: $pendingDraft) { draft in
RuleEditorView(
mode: .create,
draft: draft,
onCommit: { committed in
modelContext.insert(committed.makeRule())
dismiss()
}
)
}
}
}
private func kindRow(_ kind: RuleKind) -> some View {
Button {
pendingDraft = RuleDraft(kind: kind)
} label: {
HStack {
Image(systemName: kind.symbolName)
.foregroundStyle(.tint)
.frame(width: 28)
VStack(alignment: .leading, spacing: 2) {
Text(kind.displayName)
.foregroundStyle(Color.primary)
Text(kind.exampleText)
.font(.caption)
.foregroundStyle(Color.secondary)
}
Spacer()
Image(systemName: "chevron.right")
.font(.caption.weight(.semibold))
.foregroundStyle(.tertiary)
}
}
.accessibilityIdentifier("ruleKind-\(kind.rawValue)")
}
private func presetRow(_ preset: RulePreset) -> some View {
Button {
pendingDraft = RuleDraft(preset: preset)
} label: {
HStack {
Image(systemName: preset.symbolName)
.foregroundStyle(.tint)
.frame(width: 28)
VStack(alignment: .leading, spacing: 2) {
Text(preset.name)
.foregroundStyle(Color.primary)
Text("\(preset.schedule.timeRangeLabel) · \(preset.days.summary)")
.font(.caption)
.foregroundStyle(Color.secondary)
}
Spacer()
Image(systemName: "plus.circle.fill")
.foregroundStyle(.tint)
}
}
.accessibilityIdentifier("preset-\(preset.id)")
}
}