Skip to content

Commit

Permalink
Merge pull request #21773 from wordpress-mobile/feature/reader-detail…
Browse files Browse the repository at this point in the history
…-a11y

Reader: Minor improvements to detail header accessibility
  • Loading branch information
dvdchr authored Oct 14, 2023
2 parents ff47f18 + 63591f6 commit c284461
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class ReaderDetailHeaderViewModel: ObservableObject {

// hide the author name if it exactly matches the site name.
// context: https://github.com/wordpress-mobile/WordPress-iOS/pull/21674#issuecomment-1747202728
self.showsAuthorName = self.authorName != self.siteName
self.showsAuthorName = self.authorName != self.siteName && !self.authorName.isEmpty

self.postTitle = post.titleForDisplay() ?? nil
self.tags = post.tagsForDisplay() ?? []
Expand Down Expand Up @@ -258,6 +258,9 @@ struct ReaderDetailNewHeaderView: View {
authorAndTimestampView
}
}
.accessibilityElement(children: .combine)
.accessibilityAddTraits([.isButton])
.accessibilityHint(Constants.authorStackAccessibilityHint)
.onTapGesture {
viewModel.didTapAuthorSection()
}
Expand Down Expand Up @@ -316,7 +319,7 @@ struct ReaderDetailNewHeaderView: View {

var authorAndTimestampView: some View {
HStack(spacing: 0) {
if viewModel.showsAuthorName, !viewModel.authorName.isEmpty {
if viewModel.showsAuthorName {
Text(viewModel.authorName)
.font(.footnote)
.foregroundColor(Color(.text))
Expand All @@ -335,6 +338,8 @@ struct ReaderDetailNewHeaderView: View {

Spacer()
}
.accessibilityElement()
.accessibilityLabel(authorAccessibilityLabel)
}

var timestampText: Text {
Expand All @@ -351,8 +356,23 @@ fileprivate extension ReaderDetailNewHeaderView {
struct Constants {
static let siteIconLength: CGFloat = 40.0
static let authorImageLength: CGFloat = 20.0

static let authorStackAccessibilityHint = NSLocalizedString(
"reader.detail.header.authorInfo.a11y.hint",
value: "Views posts from the site",
comment: "Accessibility hint to inform that the author section can be tapped to see posts from the site."
)
}

var authorAccessibilityLabel: String {
var labels = [viewModel.relativePostTime]

if viewModel.showsAuthorName {
labels.insert(viewModel.authorName, at: .zero)
}

return labels.joined(separator: ", ")
}
}

// MARK: - TopicCollectionView UIViewRepresentable Wrapper
Expand Down

0 comments on commit c284461

Please sign in to comment.