Вы можете использовать onEditingChanged
вместе с привязкой для получения желаемого эффекта.
struct EditProfile : View {
@Binding var profile: Profile
@State var showDatePicker = false
@State var textfieldText: String = ""
var body: some View {
List {
HStack {
Text("Username").bold()
TextField($textfieldText, placeholder: Text("Date"), onEditingChanged: { (editting) in
self.showDatePicker = editting
}) {
}
if self.showDatePicker {
DatePicker(
$profile.goalDate,
minimumDate: Calendar.current.date(byAdding: .year, value: -1, to: profile.goalDate),
maximumDate: Calendar.current.date(byAdding: .year, value: 1, to: profile.goalDate),
displayedComponents: .date
)
}
}
}
.padding(.top)
}
}