@@ -44,6 +44,12 @@ final class TopBannerView: UIView {
4444 return stackView
4545 } ( )
4646
47+ private let titleStackView : UIStackView = {
48+ let stackView = UIStackView ( )
49+ stackView. axis = . horizontal
50+ return stackView
51+ } ( )
52+
4753 // StackView to hold the action buttons. Needed to change the axis on larger accessibility traits
4854 private let buttonsStackView = UIStackView ( )
4955
@@ -126,6 +132,7 @@ private extension TopBannerView {
126132 dismissButton. setImage ( UIImage . gridicon ( . cross, size: CGSize ( width: 24 , height: 24 ) ) , for: . normal)
127133 dismissButton. tintColor = . textSubtle
128134 dismissButton. addTarget ( self , action: #selector( onDismissButtonTapped) , for: . touchUpInside)
135+ titleStackView. accessibilityHint = Localization . dismissHint
129136
130137 case . none:
131138 break
@@ -162,9 +169,12 @@ private extension TopBannerView {
162169
163170 func createInformationStackView( with viewModel: TopBannerViewModel ) -> UIStackView {
164171 let topActionButton = topButton ( for: viewModel. topButton)
165- let titleStackView = UIStackView ( arrangedSubviews: [ titleLabel, topActionButton] . compactMap { $0 } )
166- titleStackView. axis = . horizontal
172+ titleStackView. addArrangedSubviews ( [ titleLabel, topActionButton] . compactMap { $0 } )
167173 titleStackView. spacing = 16
174+ titleStackView. isAccessibilityElement = true
175+ titleStackView. accessibilityTraits = . button
176+ titleStackView. accessibilityLabel = viewModel. title
177+ titleStackView. accessibilityIdentifier = topActionButton? . accessibilityIdentifier
168178
169179 // titleStackView will hidden if there is no title
170180 titleStackView. isHidden = viewModel. title == nil || viewModel. title? . isEmpty == true
@@ -287,8 +297,22 @@ private extension TopBannerView {
287297 if isActionEnabled {
288298 actionStackView. isHidden = !isExpanded
289299 }
300+ titleStackView. accessibilityHint = isExpanded ? Localization . collapseHint : Localization . expandHint
301+ titleStackView. accessibilityValue = isExpanded ? Localization . expanded : Localization . collapsed
290302
291303 let accessibleView = isExpanded ? infoLabel : nil
292304 UIAccessibility . post ( notification: . layoutChanged, argument: accessibleView)
293305 }
294306}
307+
308+ // MARK: Constants
309+ //
310+ private extension TopBannerView {
311+ enum Localization {
312+ static let expanded = NSLocalizedString ( " Expanded " , comment: " Accessibility value when a banner is expanded " )
313+ static let collapsed = NSLocalizedString ( " Collapsed " , comment: " Accessibility value when a banner is collapsed " )
314+ static let expandHint = NSLocalizedString ( " Double-tap for more information " , comment: " Accessibility hint to expand a banner " )
315+ static let collapseHint = NSLocalizedString ( " Double-tap to collapse " , comment: " Accessibility hint to collapse a banner " )
316+ static let dismissHint = NSLocalizedString ( " Double-tap to dismiss " , comment: " Accessibility hint to dismiss a banner " )
317+ }
318+ }
0 commit comments