changes after discuss with Ryan

This commit is contained in:
Pfeil, Scott Robert 2020-05-28 20:42:02 -04:00
parent b35fb69e18
commit 6068d5b1c5
4 changed files with 64 additions and 31 deletions

View File

@ -125,9 +125,9 @@ import UIKit
/// Adjust accessibility label based on state of RadioButton. /// Adjust accessibility label based on state of RadioButton.
func updateAccessibilityLabel() { func updateAccessibilityLabel() {
if let message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button"),
if let state = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") { let selectedState = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") {
accessibilityLabel = state accessibilityLabel = message + selectedState
} }
} }

View File

@ -22,8 +22,8 @@ import Foundation
//----------------------------------------------------- //-----------------------------------------------------
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
stack = Stack<StackModel>.createStack(with: [(view: radioButton, model: StackItemModel(horizontalAlignment: .fill)), stack = Stack<StackModel>.createStack(with: [(view: radioButton, model: StackItemModel(horizontalAlignment: .fill)),
(view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading))], (view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading))],
axis: .horizontal) axis: .horizontal)
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
} }
@ -38,13 +38,11 @@ import Foundation
super.setupView() super.setupView()
addMolecule(stack) addMolecule(stack)
stack.restack() stack.restack()
radioButton.isAccessibilityElement = false
isAccessibilityElement = true
updateAccessibilityLabel()
accessibilityTraits = .button
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint")
updateAccessibilityLabel()
accessibilityTraits = radioButton.accessibilityTraits
accessibilityHint = radioButton.accessibilityHint
// Update accessibility label on radio button state change.
observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in
self?.updateAccessibilityLabel() self?.updateAccessibilityLabel()
} }
@ -70,8 +68,7 @@ import Foundation
} }
func updateAccessibilityLabel() { func updateAccessibilityLabel() {
var message = ""
var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? ""
radioButton.updateAccessibilityLabel() radioButton.updateAccessibilityLabel()
if let radioButtonLabel = radioButton.accessibilityLabel { if let radioButtonLabel = radioButton.accessibilityLabel {
message += radioButtonLabel + ", " message += radioButtonLabel + ", "
@ -85,6 +82,27 @@ import Foundation
if let bodyLabel = eyebrowHeadlineBodyLink.body.text { if let bodyLabel = eyebrowHeadlineBodyLink.body.text {
message += bodyLabel message += bodyLabel
} }
accessibilityLabel = message
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
isAccessibilityElement = !linkShowing
radioButton.isAccessibilityElement = linkShowing
eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing
if !linkShowing {
// Make whole cell focusable if no link.
accessibilityLabel = message
} else {
// Allow only radio button and link to be focused on.
radioButton.accessibilityLabel = message
var elements: [UIView] = []
if message.count > 0 {
elements.append(radioButton)
}
if eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 {
elements.append(eyebrowHeadlineBodyLink.link)
}
accessibilityElements = elements
}
} }
} }

View File

@ -48,13 +48,11 @@ import UIKit
stack.restack() stack.restack()
eyebrowHeadlineBodyLink.body.textColor = .mvmOrangeAA eyebrowHeadlineBodyLink.body.textColor = .mvmOrangeAA
eyebrowHeadlineBodyLink.headline.styleBoldBodySmall(true) eyebrowHeadlineBodyLink.headline.styleBoldBodySmall(true)
radioButton.isAccessibilityElement = false
isAccessibilityElement = true accessibilityTraits = radioButton.accessibilityTraits
updateAccessibilityLabel() accessibilityHint = radioButton.accessibilityHint
accessibilityTraits = .button
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint")
updateAccessibilityLabel()
// Update accessibility label on radio button state change.
observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in
self?.updateAccessibilityLabel() self?.updateAccessibilityLabel()
} }
@ -88,30 +86,44 @@ import UIKit
} }
func updateAccessibilityLabel() { func updateAccessibilityLabel() {
var message = ""
var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? ""
radioButton.updateAccessibilityLabel() radioButton.updateAccessibilityLabel()
if let radioButtonLabel = radioButton.accessibilityLabel { if let radioButtonLabel = radioButton.accessibilityLabel {
message += radioButtonLabel + ", " message += radioButtonLabel + ", "
} }
if let leftImageLabel = leftImage.accessibilityLabel { if let leftImageLabel = leftImage.accessibilityLabel {
message += leftImageLabel + ", " message += leftImageLabel + ", "
} }
if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text {
message += eyebrowLabel + ", " message += eyebrowLabel + ", "
} }
if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { if let headlineLabel = eyebrowHeadlineBodyLink.headline.text {
message += headlineLabel + ", " message += headlineLabel + ", "
} }
if let bodyLabel = eyebrowHeadlineBodyLink.body.text { if let bodyLabel = eyebrowHeadlineBodyLink.body.text {
message += bodyLabel message += bodyLabel
} }
accessibilityLabel = message let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
isAccessibilityElement = !linkShowing
radioButton.isAccessibilityElement = linkShowing
eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing
if !linkShowing {
// Make whole cell focusable if no link.
accessibilityLabel = message
} else {
// Allow only radio button and link to be focused on.
radioButton.accessibilityLabel = message
var elements: [UIView] = []
if message.count > 0 {
elements.append(radioButton)
}
if eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 {
elements.append(eyebrowHeadlineBodyLink.link)
}
accessibilityElements = elements
}
} }
} }

View File

@ -44,12 +44,15 @@ open class ListLeftVariableRadioButtonBodyText: TableViewCell {
addMolecule(stack) addMolecule(stack)
stack.restack() stack.restack()
// Make the whole cell focusable.
isAccessibilityElement = true isAccessibilityElement = true
radioButton.isAccessibilityElement = false radioButton.isAccessibilityElement = false
accessibilityTraits = .button accessibilityTraits = radioButton.accessibilityTraits
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint") accessibilityHint = radioButton.accessibilityHint
updateAccessibilityLabel() updateAccessibilityLabel()
// Update accessibility label on radio button state change.
observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in
self?.updateAccessibilityLabel() self?.updateAccessibilityLabel()
} }
@ -79,7 +82,7 @@ open class ListLeftVariableRadioButtonBodyText: TableViewCell {
func updateAccessibilityLabel() { func updateAccessibilityLabel() {
var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? "" var message = ""
radioButton.updateAccessibilityLabel() radioButton.updateAccessibilityLabel()
if let radioButtonLabel = radioButton.accessibilityLabel { if let radioButtonLabel = radioButton.accessibilityLabel {