while building my app i encountered an issue that when i embed a DatePicker inside VStack and implement a onTapGesture on VStack then the DatePicker won’t open calendar to pick dates on click.
struct Test: View {
@State private var pickDate = Date()
@State private var done = false
var body: some View {
VStack {
DatePicker("From", selection: $pickDate ,displayedComponents: .date)
}
.onTapGesture {
done.toggle()
}
}
}
the code above does not work but if i remove the onTapGesture it works fine.
import SwiftUI
struct Test: View {
@State private var pickDate = Date()
@State private var done = false
var body: some View {
VStack {
DatePicker("From", selection: $pickDate ,displayedComponents: .date)
}
}
}
#Preview {
Test()
}
although the first code works in and youtube video of building same functionality for a clone app.