I want to show a sheet, and immediately put the text field inside in focus when the sheet is shown, so the user can immediately start typing without tapping on the sheet separately.
I have tried the solutions in this thread: https://developer.apple.com/forums/thread/681962
But none of them are working. Here's my current code:
struct MySheet: View {
@State var text: String
@FocusState var focusedField: FocusField?
var body: some View {
VStack {
TextField("", text: $text)
.focused($focusedField, equals: .field)
.padding()
.task {
self.focusedField = .field
}
}
}
}
It seems like this should be very simple and a common use-case. How can I achieve this?