Last active
March 12, 2024 02:07
-
-
Save mrhanlon/7f577c02de07ecc0ebf6b62c3e218a16 to your computer and use it in GitHub Desktop.
Regarding [this module](https://www.hackingwithswift.com/books/ios-swiftui/hiding-and-grouping-accessibility-data) from 100 Days of Swift UI, it appears that when using `Image(decorative: "foo")` VoiceOver is disabled for the component even if accessibility label/traits are added.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
let pictures = [ | |
"ales-krivec-15949", | |
"galina-n-189483", | |
"kevin-horstmann-141705", | |
"nicolas-tissot-335096" | |
] | |
let labels = [ | |
"Tulips", | |
"Frozen tree buds", | |
"Sunflowers", | |
"Fireworks", | |
] | |
@State private var selectedPicture = Int.random(in: 0...3) | |
var body: some View { | |
VStack { | |
Image(pictures[selectedPicture]) | |
.resizable() | |
.scaledToFit() | |
.accessibilityLabel(labels[selectedPicture]) | |
.padding(.vertical) | |
// won't work | |
Image(decorative: "galina-n-189483") | |
.resizable() | |
.frame(width: 200, height: 100) | |
.clipShape(.capsule) | |
.padding() | |
.onTapGesture { | |
selectedPicture = Int.random(in: 0...3) | |
} | |
.accessibilityLabel("Change image") | |
.accessibilityAddTraits(.isButton) | |
.accessibilityRemoveTraits(.isImage) | |
// works | |
Image("ales-krivec-15949") | |
.resizable() | |
.frame(width: 200, height: 100) | |
.clipShape(.capsule) | |
.padding() | |
.onTapGesture { | |
selectedPicture = Int.random(in: 0...3) | |
} | |
.accessibilityLabel("Change image") | |
.accessibilityAddTraits(.isButton) | |
.accessibilityRemoveTraits(.isImage) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment