The result of tapping the "unscheduled" button is not to set the date to .now, but to allow the user to schedule the activity, presumably sometime in the future
But that would involve more than one tap anyway, wouldn't it?
My example of .now was just an example so that the DatePicker would be displayed with a valid date, and not the year 4000 as you required. You could choose to craft a date for one week today at noon instead.
If you want a cleaner UI then you should maybe do as I suggested and have the DatePicker disabled if it's unscheduled, and have a toggle that enables the picker?
import SwiftUI
struct ContentView: View {
@State private var scheduled: Bool = false
@State private var date: Date = .now.advanced(by: 24 * 7 * 60 * 60)
var body: some View {
VStack {
Toggle("Scheduled", isOn: $scheduled)
.padding(.horizontal)
Group {
HStack {
DatePicker("Date", selection: $date)
.disabled(!scheduled)
.opacity(scheduled ? 1 : 0.4)
}
.padding()
}
.border(.black.opacity(scheduled ? 1 : 0.2), width: 2)
.padding(.horizontal)
}
}
}
#Preview {
ContentView()
}
Unscheduled:
Scheduled:
Or the HStack in the middle (lines 13-15) could be changed to this so you only ever see a date when the toggle is on:
if(scheduled) {
DatePicker("Date", selection: $date)
.disabled(!scheduled)
.opacity(scheduled ? 1 : 0.4)
} else {
Text("Toggle switch to schedule")
.frame(maxWidth: .infinity)
.opacity(scheduled ? 1 : 0.4)
}