Initiales HabitTracker-Projekt: SwiftUI + SwiftData Gewohnheiten-Tracker
Natives iOS-App-Gerüst (Xcode 26, synchronisierte Ordner, iOS 18+). Features: - Gewohnheiten anlegen (Name, SF-Symbol, Farbe), heute abhaken, Streaks, Löschen - Detailansicht mit Monatskalender (Tage nachtragbar) und Statistiken - Tägliche Erinnerungen via lokale Notifications - Home-Screen-Widget (klein/mittel) mit App-Group-Datenaustausch
This commit is contained in:
commit
22b8f5d806
24 changed files with 1448 additions and 0 deletions
38
HabitTracker/Views/ReminderEditor.swift
Normal file
38
HabitTracker/Views/ReminderEditor.swift
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import SwiftUI
|
||||
|
||||
/// Toggle + time picker that drives an optional reminder time. Designed to sit
|
||||
/// inside a Form Section or a VStack. Requests notification permission when the
|
||||
/// user first switches the reminder on. Scheduling is the caller's job.
|
||||
struct ReminderEditor: View {
|
||||
@Binding var reminderTime: Date?
|
||||
|
||||
@State private var enabled: Bool
|
||||
@State private var time: Date
|
||||
|
||||
init(reminderTime: Binding<Date?>) {
|
||||
_reminderTime = reminderTime
|
||||
_enabled = State(initialValue: reminderTime.wrappedValue != nil)
|
||||
_time = State(initialValue: reminderTime.wrappedValue ?? NotificationManager.defaultTime)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
Toggle(isOn: $enabled) {
|
||||
Label("Tägliche Erinnerung", systemImage: "bell.fill")
|
||||
}
|
||||
.onChange(of: enabled) { _, isOn in
|
||||
reminderTime = isOn ? time : nil
|
||||
if isOn {
|
||||
Task { await NotificationManager.requestAuthorization() }
|
||||
}
|
||||
}
|
||||
|
||||
if enabled {
|
||||
DatePicker("Uhrzeit", selection: $time, displayedComponents: .hourAndMinute)
|
||||
.onChange(of: time) { _, newValue in
|
||||
reminderTime = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue