Let's say I have a SwiftUI view that's a compose experience, like composing a new email in Mail, an iMessage in Messages, or a Tweet in Twitter.
When the view is loaded, I want the soft keyboard to appear automatically so that the user can type immediately without needing to manually put focus in the
TextEditor by tapping on it.
With the new
@FocusState feature in iOS 15, I can programmatically put focus on different
TextFields when the user interacts elsewhere in the UI (like pressing a button), but I can't seem to set a default focus.
I tried initializing focus in the SwiftUI view's
init method as well as the
onAppear method attached to other parts of the view, but this didn't seem to have any effect.
How can I put default focus on a
TextEditor when a view is loaded?