From 4aa6d9597b5ac750acff075cfe631d158d05e138 Mon Sep 17 00:00:00 2001 From: Scarriffle Date: Mon, 27 Jul 2026 18:26:41 +0200 Subject: [PATCH] iOS: Einzelstueck-Daten einheitlich als dd.MM.yyyy Die nativen compact-DatePicker zeigten das Jahr mal zwei-, mal vierstellig (Gekauft am vs. Garantie bis). Neue DateRow: fester Formatierer dd.MM.yyyy, Antippen klappt einen grafischen Kalender inline auf - konsistent und ohne iOS-16.4-Abhaengigkeit. Co-Authored-By: Claude Opus 4.8 --- ios/Sources/ItemViews.swift | 44 +++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/ios/Sources/ItemViews.swift b/ios/Sources/ItemViews.swift index 211f407..577401d 100644 --- a/ios/Sources/ItemViews.swift +++ b/ios/Sources/ItemViews.swift @@ -33,6 +33,42 @@ private func stringToDate(_ s: String) -> Date? { let f = DateFormatter(); f.dateFormat = "yyyy-MM-dd"; return f.date(from: s) } +/// Datumszeile mit einheitlichem Format (dd.MM.yyyy). Die native compact-DatePicker +/// zeigt das Jahr je nach Feld mal zwei-, mal vierstellig – deshalb hier ein fester +/// Formatierer und ein grafischer Picker im Popover. +struct DateRow: View { + let label: String + @Binding var date: Date + @State private var open = false + + private static let fmt: DateFormatter = { + let f = DateFormatter() + f.locale = Locale(identifier: "de_DE") + f.dateFormat = "dd.MM.yyyy" + return f + }() + + var body: some View { + Group { + Button { withAnimation(.easeInOut(duration: 0.15)) { open.toggle() } } label: { + HStack { + Text(label).foregroundStyle(.primary) + Spacer() + Text(Self.fmt.string(from: date)) + .foregroundStyle(open ? Color.accentColor : .secondary) + } + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + if open { + DatePicker(label, selection: $date, displayedComponents: .date) + .datePickerStyle(.graphical) + .labelsHidden() + } + } + } +} + // MARK: - Liste (in der Produkt-Detailansicht) /// Einzelstücke eines Gegenstands: Liste mit Anlegen; jedes Stück öffnet die @@ -146,9 +182,9 @@ struct ItemEditView: View { ForEach(shops) { s in Text(s.name).tag(Int?.some(s.id)) } } Toggle("Kaufdatum", isOn: $hasAcquired) - if hasAcquired { DatePicker("Gekauft am", selection: $acquired, displayedComponents: .date) } + if hasAcquired { DateRow(label: "Gekauft am", date: $acquired) } Toggle("Garantie", isOn: $hasWarranty) - if hasWarranty { DatePicker("Garantie bis", selection: $warranty, displayedComponents: .date) } + if hasWarranty { DateRow(label: "Garantie bis", date: $warranty) } LabeledField(label: "Notiz", text: $note) } @@ -438,9 +474,9 @@ struct ItemAddSheet: View { ForEach(shops) { s in Text(s.name).tag(Int?.some(s.id)) } } Toggle("Kaufdatum", isOn: $hasAcquired) - if hasAcquired { DatePicker("Gekauft am", selection: $acquired, displayedComponents: .date) } + if hasAcquired { DateRow(label: "Gekauft am", date: $acquired) } Toggle("Garantie", isOn: $hasWarranty) - if hasWarranty { DatePicker("Garantie bis", selection: $warranty, displayedComponents: .date) } + if hasWarranty { DateRow(label: "Garantie bis", date: $warranty) } LabeledField(label: "Notiz", text: $note) } footer: { Text("Gemeinsame Startwerte – danach je Stück änderbar. Jedes Stück bekommt eine eigene UID + QR.")