This is a great solution, however the tappable area of the dismiss button (no matter if you use the .close or the default) is way too small. You can only tap on the very right edge of the word done. Any solution to this?
Post
Replies
Boosts
Views
Activity
I've been looking at those 3rd party services, but since we only need to do this in order to verify a phone number added to a user's account, I haven't found any that don't have monthly minimum charges, and really good rates. Any chance you could recommend a few to look at?
Also, perhaps instead of looking at it as I am now, there is a better solution for verifying a phone number (i.e. user enters a phone number and we send them an OTP verification code)?
Already solved it. You don't need an enum for this scenario. You simply call the AccessibilityFocusState directly to the array and you're good.
If anyone is interested, the answer is AccessibilityFocusState, but you need to use it in a very specific way.
Create an enum with the various focus choices on your page
Create @AccessibilityFocusState private var accessFocus: EnumName?
Use .accessibilityFocused($accessFocus, equals: .yourEnumCase) as a modifier to a view to which you wish to focus
Your actions can now change the value of accessFocus to the field in which you want voiceover to focus by:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
accessFocus = .yourEnumCase
}
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")
}
}
}
}
}
}