Reputation: 325
.onTapGesture {
// do something
}
Doesn't work because TextFields can be tapped without beginning editing mode.
Upvotes: 2
Views: 4265
Reputation: 1499
You Should try with it ,
onEditingChanged: { (isBegin) in
if isBegin {
print("Begins editing")
} else {
print("Finishes editing")
}
},
Upvotes: -1
Reputation: 325
The answer is to initialize TextField with the onEditingChanged parameter.
We can then execute a closure conditionally depending upon whether the text field was edited or changes were committed:
TextField("", text: $email, onEditingChanged: { changed in
if changed {
// User began editing the text field
}
else {
// User tapped the return key
}
})
Upvotes: 9
Reputation: 24
Have you tried with onEditingChanged
.onEditingChanged {
//do something cool
}
Upvotes: -1