11

I need to move the accessibility focus to certain element on the screen. In UIKit, we can simply do UIAccessibility.post(.screenChanged, element)

However, when I do that with a SwiftUI View, the app crashes with the following message in console

This class '__SwiftValue' is not a known serializable element and returning it as an accessibility element may lead to crashes

Any idea how we can move focus to certain elements on the screen in SwiftUI?

user1366265
  • 1,306
  • 1
  • 17
  • 28

1 Answers1

1

A workaround would be: Post a notification when the UIView appears:

    .onAppear(perform: {
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
            UIAccessibility.post(notification: .screenChanged, argument: "New Screen")
        }
    })

As argument it would make sense to put in the text of the accessibility label of the desired view. The impaired user would just not know where the screenReader is focusing if the user could recognize the white surrounding of the screenReader focus.

To make things smooth the delay of 0.1 should be adapted while testing with different languages.

FrugalResolution
  • 568
  • 4
  • 18