TextEditor become first responder

So I see that there's a new TextEditor for multilane editing in iOS 14. Great!

Is there a way to make a TextEditor (or even a TextField) become a first responder (i.e. activate the keyboard) when a view loads?

I already have a a UIViewRepresentable rigged up for this since iOS13 and I'm hoping to retire it.

Replies

since iOS 15 you can use @FocusState example

however, if you need iOS 14 support, I recommend using SwiftUI-Introspect

TextEditor(text: $message)
           .introspectTextView { textEditor in
                  textEditor.becomeFirstResponder()
          }

do not forget to call introspect after all styles at the very end