Not sure what @FocusState has to do with the question, but just in case I tried it anyway. I am not trying to move focus between two text fields. I am trying to change the voiceover focus to the error msg/continue button when it appears after dismissing the keyboard and setting a variable's value.
My guess is that @AccessibilityFocusState is the right way to do this, but even manually setting that variable to true when tapping the keyboard dismiss button will not actually set the variable to true.
struct TestView: View {
@AccessibilityFocusState var accessFocus: Bool
@FocusState var isFocused: Bool
@State private var testVar = ""
var body: some View {
VStack {
Text("Welcome")
VStack {
TextField("", text: $testVar)
.focused($isFocused)
}
VStack {
Text("Error Message")
}
.accessibilityFocused($accessFocus)
}
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
HStack {
Spacer()
Button {
isFocused = false
accessFocus = true
} label: {
Image(systemName: "keyboard.chevron.compact.down")
}
}
}
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: