So trying my app in iOS17 destroyed FocusStates in my app, it has no issues in iOS16.
The situation is:
I have a "Create New Item" view, where the user can fill in the following information of an Item: Title, Amount, Note
I have these properties in the view:
@FocusState private var titleIsFocused: Bool
@FocusState private var amountIsFocused: Bool
@FocusState private var noteIsFocused: Bool
And using these Textfields:
TextField("title", text: $title)
.focused($titleIsFocused)
TextField("amount", text: $amount)
.focused($amountIsFocused)
.keyboardType(.decimalPad)
TextField("note", text: $note)
.focused($noteIsFocused)
When the view appears: I have a onAppear that sets:
titleIsFocused = true
I have the following ToolbarItemGroup in my toolbar:
ToolbarItemGroup(placement: .keyboard) {
Button {
if titleIsFocused {
amountIsFocused = true
}
if amountIsFocused {
noteIsFocused = true
}
if noteIsFocused {
noteIsFocused = false
}
} label: {
Text(noteIsFocused ? "Done" : "Next")
}
}
The issue is:
In iOS16: the focus goes correctly from title to amount, from amount to note, and from note to closing the keyboard via the keyboard toolbar buttons.
In iOS17: nothing happens when I press the keyboard toolbar buttons. Also this does not work via normal buttons.
Weird thing is, this works:
Setting a .onSubmit{} on the TextField..
TextField("title", text: $title)
.focused($titleIsFocused)
.onSubmit { amountIsFocused = true }
However, a textfield with a '.keyboardType(.decimalPad)' has no Return/Submit button, and since the Textfield for amount is a decimalPad, it will not work nicely In my situation.
Question
Is something drastically changed from iOS16 to iOS17 how this should work, or is this just a bug in Beta1?