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.
func updateAccessibilityLabel() {
if let state = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") {
accessibilityLabel = state
if let message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button"),
let selectedState = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") {
accessibilityLabel = message + selectedState
}
}

View File

@ -22,8 +22,8 @@ import Foundation
//-----------------------------------------------------
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
stack = Stack<StackModel>.createStack(with: [(view: radioButton, model: StackItemModel(horizontalAlignment: .fill)),
(view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading))],
axis: .horizontal)
(view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading))],
axis: .horizontal)
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
@ -38,13 +38,11 @@ import Foundation
super.setupView()
addMolecule(stack)
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
self?.updateAccessibilityLabel()
}
@ -70,8 +68,7 @@ import Foundation
}
func updateAccessibilityLabel() {
var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? ""
var message = ""
radioButton.updateAccessibilityLabel()
if let radioButtonLabel = radioButton.accessibilityLabel {
message += radioButtonLabel + ", "
@ -85,6 +82,27 @@ import Foundation
if let bodyLabel = eyebrowHeadlineBodyLink.body.text {
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()
eyebrowHeadlineBodyLink.body.textColor = .mvmOrangeAA
eyebrowHeadlineBodyLink.headline.styleBoldBodySmall(true)
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
self?.updateAccessibilityLabel()
}
@ -88,30 +86,44 @@ import UIKit
}
func updateAccessibilityLabel() {
var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? ""
var message = ""
radioButton.updateAccessibilityLabel()
if let radioButtonLabel = radioButton.accessibilityLabel {
message += radioButtonLabel + ", "
}
if let leftImageLabel = leftImage.accessibilityLabel {
message += leftImageLabel + ", "
}
if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text {
message += eyebrowLabel + ", "
}
if let headlineLabel = eyebrowHeadlineBodyLink.headline.text {
message += headlineLabel + ", "
}
if let bodyLabel = eyebrowHeadlineBodyLink.body.text {
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)
stack.restack()
// Make the whole cell focusable.
isAccessibilityElement = true
radioButton.isAccessibilityElement = false
accessibilityTraits = .button
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint")
accessibilityTraits = radioButton.accessibilityTraits
accessibilityHint = radioButton.accessibilityHint
updateAccessibilityLabel()
// Update accessibility label on radio button state change.
observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in
self?.updateAccessibilityLabel()
}
@ -79,7 +82,7 @@ open class ListLeftVariableRadioButtonBodyText: TableViewCell {
func updateAccessibilityLabel() {
var message = MVMCoreUIUtility.hardcodedString(withKey: "radio_button") ?? ""
var message = ""
radioButton.updateAccessibilityLabel()
if let radioButtonLabel = radioButton.accessibilityLabel {