Reputation: 315
I have one button on a screen and on tap of that button i am opening one modal (view). But after closing that view accessibility VoiceOver focus goes to top left element on the screen. I want that focus to stay on the same button after closing that view.
Upvotes: 4
Views: 1164
Reputation: 1443
// State variable to control loading state
@State var isLoading: Bool = false
// Accessibility focus state variable to manage focus
@AccessibilityFocusState var isLoadingIndicatorFocused: Bool
var body: some View {
VStack {
Button("Search Appt website") {
// Set loading state to true
isLoading = true
// Move focus to the loading indicator
isLoadingIndicatorFocused = true
}
if isLoading {
ProgressView()
.accessibilityFocused($isLoadingIndicatorFocused) // Bind the focus state
.accessibilityLabel("Loading") // Provide an accessible label
}
}
}
Upvotes: 1