Can I change return key function in keyboard? I have already search to change return key function in keyboard but I haven't found the answer.In TextField, when I click return key, keyboard auto dismiss.
Asked
Active
Viewed 371 times
1
-
1https://stackoverflow.com/questions/60008549/is-it-possible-to-change-return-key-to-done-on-keyboard-in-2020-with-swiftui – jnpdx Jan 13 '21 at 05:49
-
Guess you want to trigger something when return key entered ? – YodagamaHeshan Jan 13 '21 at 10:59
-
Does this answer your question? [Is it possible to change "return" key to "done" on keyboard in 2020 with SwiftUI?](https://stackoverflow.com/questions/60008549/is-it-possible-to-change-return-key-to-done-on-keyboard-in-2020-with-swiftui) – katalin_2003 Jan 13 '21 at 15:39
1 Answers
-1
You are finding something related to below code which is in UIKIt
with UITextFieldDelegate
in SwiftUI
In UIKit
(with UITextFieldDelegate
)
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
//do something when user press return button
return true
}
In SwiftUI
struct ContentView: View {
@State var text = ""
var body: some View {
TextField("Placeholder", text: $text) {(_) in} onCommit: {
print("return key pressed") //<= here
//do something when user press return button
}
}
}
Note: References to any of view will not be kept in a variable in SwiftUI
like we did in UIKit

YodagamaHeshan
- 4,996
- 2
- 26
- 36