iOS17 - Setting FocusState to false via Button is not working

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?

Same issue here

same problem for me....... beta3 and still no fix for this

Doesn't work in WatchOS either, tried everything I can think of. Plain project with nothing but a TextField and an .onAppear{} modifier with a .main.asyncAfter{} with 1 second delay changing the focus state does not do anything. Focus always prints nil/false... how does this even slip by QA, idk.

any news on this? this is still not working for me in beta5?

Tried changing focus between two views both listening to Digital Crown change on a tap of a button. Doesn't work. Button action doesn't allow to change @FocusState value programmatically. Tap on a view changes @FocusState without problems.

Its working on Xcode Version 15.0 (15A240d)

Tested on Xcode Version 15.0 (15A240d) and it is still not working...

Same issue. Programmatically changing @FocusState is not working on 15A240d / watchOS 10.

Does this solve the issue? It works on my app.

import SwiftUI

struct FieldView: View {

    enum Field: Hashable {
        case amountField
        case descriptionField
        case categoryField
    }
    
    @FocusState private var focusedField: Field?

    @State var description = ""

    var body: some View {
        TextField("Description" ,text: $description)
            .focused($focusedField, equals: .descriptionField)
            .keyboardType(.default)
            .onAppear() {
                focusedField = .descriptionField
            }
            .onSubmit {
                focusedField = .categoryField
            }
            .submitLabel(.next)
        }
    }
}
iOS17 - Setting FocusState to false via Button is not working
 
 
Q