[ad_1]
I need to present totally different buttons based mostly on which subject is targeted, however the focus state is all the time one behind. Right here is the code:
struct ContentView: View {
enum FocusField {
case one
case two
}
@FocusState var centered: FocusField?
var physique: some View {
VStack {
TextField("One", textual content: .fixed(""))
.centered($centered, equals: .one)
TextField("Two", textual content: .fixed(""))
.centered($centered, equals: .two)
}
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
if centered == .one {
Textual content("One")
} else if centered == .two {
Textual content("Two")
} else {
Textual content("None")
}
Spacer()
Button("Carried out") { centered = nil }
}
}
}
}
[ad_2]
