When I run the following code:
struct ContentView: View {
let mdText = LocalizedStringKey("some text [link](https://apple.com) more text")
let text = "some text link more text"
var body: some View {
VStack {
Text(mdText)
// .accessibilityRotor(.links, textRanges: [String.Index(utf16Offset: 10, in: text)..<String.Index(utf16Offset: 14, in: text)])
// .accessibilityIdentifier("identifier")
}
}
}
It works as expected. Specifically in voiceOver I'm able to use the rotor, select "Links" and select the link described in the markdown text.
However if I uncomment the .accessibilityIdentifier modifier, "Links" is no longer present in the Rotor.
To work around this, I would like to add an accessibilityRotor modifier to restore the Links Rotor item. When I uncomment the rotor modifier in the above code, Links is present in the Rotor, however there are no items in the list (ie swiping down just generates a 'klunk' noise)
I think I have two separate questions:
- Is there any way to restore Links to the VO Rotor for a Text() using text Ranges?
- Is there some way to add an accessibilityIdentifier that doesn't clobber the Links setting in the VO rotor?
thanks in advance :-)
Problem solved.
Adding the children: contain modifier before the identifier seems to prevent the identifier modifier from clobbering the Links Rotor.
struct ContentView: View {
let mdText = LocalizedStringKey("some text [link](https://apple.com) more text")
let text = "some text link more text"
var body: some View {
VStack {
Text(mdText)
.accessibilityElement(children: .contain)
.accessibilityIdentifier("identifier")
}
}
}