Wednesday, March 22, 2023
HomeiOS Developmentios - How one can use .onSubmit() with vertical TextField in SwiftUI?

ios – How one can use .onSubmit() with vertical TextField in SwiftUI?

I am making an attempt to have a vertically rising TextField in SwiftUI but additionally have the software program keyboard have a customized submission technique.

This makes use of the brand new performance of iOS 16’s TextFields with the ability to take an axis as an argument for which manner it ought to develop.

This is a pattern ContentView exhibiting the setup.

struct ContentView: View {

    @State var message: String = ""
    var physique: some View {
        VStack {
            Textual content("Attempt to submit this utilizing the blue ship button on the software program keyboard")
            TextField("Placeholder", textual content: $message, axis: .vertical)
                .onSubmit {

Once you run this, you possibly can see the TextField correctly develop vertically, however even when you may have a customized submission label, urgent the blue “ship” button within the software program keyboard on iOS simply inserts a newline, reasonably than firing the .onSubmit

When utilizing a {hardware} keyboard, urgent the return does run the code in .onSubmit, so this seemingly only a limitation of the comfortable keyboard.




Please enter your comment!
Please enter your name here

1 × 4 =

Most Popular

Recent Comments