Skip to content

Commit

Permalink
Hide images from accessibility if it does not have an a11y label (#2706)
Browse files Browse the repository at this point in the history
* Hide images from accessibility if it does not have an a11y label

* Fix

* Fix compat check
  • Loading branch information
rlepinski authored Mar 24, 2023
1 parent e58229b commit 3b8b839
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Airship/AirshipCore/Source/Media.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Media : View {
.background(self.model.backgroundColor)
.border(self.model.border)
.common(self.model)
.accessible(self.model)
.accessible(self.model, hideIfNotSet: true)
case .video, .youtube:
#if !os(tvOS) && !os(watchOS)
MediaWebView(url: model.url,
Expand Down
13 changes: 11 additions & 2 deletions Airship/AirshipCore/Source/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ extension View {
}

@ViewBuilder
func accessible(_ accessible: Accessible?) -> some View {
func accessibleHiddenCompat(hidden: Bool) -> some View {
if #available(iOS 14.0, tvOS 14.0, *) {
self.accessibilityHidden(hidden)
} else {
self.accessibility(hidden: hidden)
}
}

@ViewBuilder
func accessible(_ accessible: Accessible?, hideIfNotSet: Bool = false) -> some View {
if let label = accessible?.contentDescription {
self.accessibility(label: Text(label))
} else {
self
self.accessibleHiddenCompat(hidden: hideIfNotSet)
}
}

Expand Down

0 comments on commit 3b8b839

Please sign in to comment.