SwiftUI : returnKeyType

What is the SwiftUI equivalent to returnKeyType? How do we implement it?

Accepted Reply

Then, you should get a return key at the bottom right. Do you get it ?


What I understand is that is not yet possible to change directly in SwiftUI,

"there's no official way to do so at the moment. Your best bet at the moment is to wrap UITextField"

From

https://stackoverflow.com/questions/56517515/how-to-set-keyboard-type-of-textfield-in-swiftui

Replies

Could you explain how you would need to use this "equivalent" ?

I would simply like a "Done" button on the keyboard.

It depends on the keyboard. Which keyboard type do you use (Decimal, ASCII, default…)


Found this thread to explain clearly how to set keyboard type (some include a done key) in SwiftUI.

https://stackoverflow.com/questions/56517515/how-to-set-keyboard-type-of-textfield-in-swiftui

It's default.


TextField("Leave a comment", text: $comment, onEditingChanged: { if $0 { self.kGuardian.showField = 0 } }) {
                commentText = self.comment
            }
               
                .padding()
                .background(GeometryGetter(rect: $kGuardian.rects[0]))
                .background(Color(red: 239.0/255.0, green: 243.0/255.0, blue: 244.0/255.0, opacity: 1.0), cornerRadius: 10.0)

Then, you should get a return key at the bottom right. Do you get it ?


What I understand is that is not yet possible to change directly in SwiftUI,

"there's no official way to do so at the moment. Your best bet at the moment is to wrap UITextField"

From

https://stackoverflow.com/questions/56517515/how-to-set-keyboard-type-of-textfield-in-swiftui

As of iOS 15, you can use .submitLabel(.done) to set the done button on the keyboard. Documentation is here: https://developer.apple.com/documentation/swiftui/view/submitlabel(_:)