Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Accessibility VoiceOver Focus Issue

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.

like image 981
amey rane Avatar asked Nov 20 '25 06:11

amey rane


1 Answers

// 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
            }
        }
    }

ref: https://appt.org/en/docs/swiftui/samples/accessibility-focus#:~:text=Accessibility%20focus%20%2D%20SwiftUI,specific%20element%20in%20your%20app.

like image 169
MacDeveloper Avatar answered Nov 22 '25 23:11

MacDeveloper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!