left variable accessibility clean
This commit is contained in:
parent
17a14e0634
commit
061e9e6bd9
@ -53,7 +53,7 @@ import Foundation
|
|||||||
checkbox.isAccessibilityElement = false
|
checkbox.isAccessibilityElement = false
|
||||||
accessibilityTraits = checkbox.accessibilityTraits
|
accessibilityTraits = checkbox.accessibilityTraits
|
||||||
accessibilityHint = checkbox.accessibilityHint
|
accessibilityHint = checkbox.accessibilityHint
|
||||||
// Update accessibility label on radio button state change.
|
// Update accessibility label on checkbox state change.
|
||||||
observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in
|
observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in
|
||||||
self?.updateAccessibilityLabel()
|
self?.updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
@ -92,16 +92,8 @@ import Foundation
|
|||||||
message += checkboxLabel + ", "
|
message += checkboxLabel + ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text, !eyebrowLabel.isEmpty {
|
if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() {
|
||||||
message += eyebrowLabel + ", "
|
message += label
|
||||||
}
|
|
||||||
|
|
||||||
if let headlineLabel = eyebrowHeadlineBodyLink.headline.text, !headlineLabel.isEmpty {
|
|
||||||
message += headlineLabel + ", "
|
|
||||||
}
|
|
||||||
|
|
||||||
if let bodyLabel = eyebrowHeadlineBodyLink.body.text, !bodyLabel.isEmpty {
|
|
||||||
message += bodyLabel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
||||||
@ -114,19 +106,9 @@ import Foundation
|
|||||||
// Make whole cell focusable if no link.
|
// Make whole cell focusable if no link.
|
||||||
accessibilityLabel = message
|
accessibilityLabel = message
|
||||||
} else {
|
} else {
|
||||||
// Allow only radio button and link to be focused on.
|
// Allow only checkbox and link to be focused on.
|
||||||
checkbox.accessibilityLabel = message
|
checkbox.accessibilityLabel = message
|
||||||
var elements: [UIView] = []
|
accessibilityElements = [checkbox, eyebrowHeadlineBodyLink.link]
|
||||||
|
|
||||||
if message.count > 0 {
|
|
||||||
elements.append(checkbox)
|
|
||||||
}
|
|
||||||
|
|
||||||
if linkShowing {
|
|
||||||
elements.append(eyebrowHeadlineBodyLink.link)
|
|
||||||
}
|
|
||||||
|
|
||||||
accessibilityElements = elements
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ import Foundation
|
|||||||
checkbox.isAccessibilityElement = false
|
checkbox.isAccessibilityElement = false
|
||||||
accessibilityTraits = checkbox.accessibilityTraits
|
accessibilityTraits = checkbox.accessibilityTraits
|
||||||
accessibilityHint = checkbox.accessibilityHint
|
accessibilityHint = checkbox.accessibilityHint
|
||||||
// Update accessibility label on radio button state change.
|
// Update accessibility label on checkbox state change.
|
||||||
observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in
|
observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in
|
||||||
self?.updateAccessibilityLabel()
|
self?.updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,6 @@ import Foundation
|
|||||||
leftImage.imageView.contentMode = .scaleAspectFit
|
leftImage.imageView.contentMode = .scaleAspectFit
|
||||||
addMolecule(stack)
|
addMolecule(stack)
|
||||||
stack.restack()
|
stack.restack()
|
||||||
updateAccessibilityLabel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -63,57 +62,40 @@ import Foundation
|
|||||||
return 140
|
return 140
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAccessibilityMessage() -> String? {
|
||||||
|
guard let leftImageLabel = leftImage.accessibilityLabel else {
|
||||||
|
return eyebrowHeadlineBodyLink.getAccessibilityMessage()
|
||||||
|
}
|
||||||
|
guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else {
|
||||||
|
return leftImageLabel
|
||||||
|
}
|
||||||
|
return leftImageLabel + ", " + label
|
||||||
|
}
|
||||||
|
|
||||||
func updateAccessibilityLabel() {
|
func updateAccessibilityLabel() {
|
||||||
|
|
||||||
var message = ""
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
||||||
isAccessibilityElement = !linkShowing
|
isAccessibilityElement = !linkShowing
|
||||||
|
accessibilityTraits = (isAccessibilityElement && accessoryView != nil) ? .button : .none
|
||||||
eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing
|
eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing
|
||||||
|
|
||||||
if !linkShowing {
|
if !linkShowing {
|
||||||
// Make whole cell focusable if no link.
|
// Make whole cell focusable if no link.
|
||||||
accessibilityLabel = message
|
accessibilityLabel = getAccessibilityMessage()
|
||||||
|
accessibilityElements = nil
|
||||||
|
} else if let accessoryView = accessoryView {
|
||||||
|
// Both caret and link. Read all content on caret.
|
||||||
|
accessoryView.accessibilityLabel = getAccessibilityMessage()
|
||||||
|
accessibilityElements = [accessoryView, eyebrowHeadlineBodyLink.link]
|
||||||
} else {
|
} else {
|
||||||
// Allow only radio button and link to be focused on.
|
// Only link. Manually add accessibility elements to ensure they are read in the right order.
|
||||||
var elements: [UIView] = []
|
var elements: [Any] = []
|
||||||
|
|
||||||
if let leftImageLabel = leftImage.accessibilityLabel, !leftImageLabel.isEmpty {
|
if let leftImageLabel = leftImage.accessibilityLabel, !leftImageLabel.isEmpty {
|
||||||
elements.append(leftImage)
|
elements.append(leftImage)
|
||||||
}
|
}
|
||||||
|
if let otherElements = eyebrowHeadlineBodyLink.getAccessibilityElements() {
|
||||||
if let eyeBrowText = eyebrowHeadlineBodyLink.eyebrow.text, !eyeBrowText.isEmpty {
|
elements.append(otherElements)
|
||||||
elements.append(eyebrowHeadlineBodyLink.eyebrow)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let headlineText = eyebrowHeadlineBodyLink.headline.text, !headlineText.isEmpty {
|
|
||||||
elements.append(eyebrowHeadlineBodyLink.headline)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let bodyText = eyebrowHeadlineBodyLink.body.text, !bodyText.isEmpty {
|
|
||||||
elements.append(eyebrowHeadlineBodyLink.body)
|
|
||||||
}
|
|
||||||
|
|
||||||
if linkShowing {
|
|
||||||
elements.append(eyebrowHeadlineBodyLink.link)
|
|
||||||
}
|
|
||||||
|
|
||||||
accessibilityElements = elements
|
accessibilityElements = elements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,8 +48,6 @@ import UIKit
|
|||||||
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
||||||
addMolecule(stack)
|
addMolecule(stack)
|
||||||
stack.restack()
|
stack.restack()
|
||||||
isAccessibilityElement = true
|
|
||||||
updateAccessibilityLabel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -78,7 +76,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateAccessibilityLabel() {
|
func updateAccessibilityLabel() {
|
||||||
|
isAccessibilityElement = true
|
||||||
var message = ""
|
var message = ""
|
||||||
|
|
||||||
if let leftImageLabel = leftImage.accessibilityLabel {
|
if let leftImageLabel = leftImage.accessibilityLabel {
|
||||||
@ -94,5 +92,6 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
accessibilityLabel = message
|
accessibilityLabel = message
|
||||||
|
accessibilityTraits = (accessoryView != nil) ? .button : .none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,10 +58,8 @@ import Foundation
|
|||||||
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
||||||
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
||||||
rightLabel.numberOfLines = 1
|
rightLabel.numberOfLines = 1
|
||||||
isAccessibilityElement = true
|
|
||||||
addMolecule(stack)
|
addMolecule(stack)
|
||||||
stack.restack()
|
stack.restack()
|
||||||
updateAccessibilityLabel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -93,7 +91,7 @@ import Foundation
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
func updateAccessibilityLabel() {
|
func updateAccessibilityLabel() {
|
||||||
|
isAccessibilityElement = true
|
||||||
var message = ""
|
var message = ""
|
||||||
|
|
||||||
if let leftImageLabel = leftImage.accessibilityLabel {
|
if let leftImageLabel = leftImage.accessibilityLabel {
|
||||||
@ -113,5 +111,6 @@ import Foundation
|
|||||||
}
|
}
|
||||||
|
|
||||||
accessibilityLabel = message
|
accessibilityLabel = message
|
||||||
|
accessibilityTraits = (accessoryView != nil) ? .button : .none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,11 +75,14 @@ import Foundation
|
|||||||
// MARK: - Accessibility
|
// MARK: - Accessibility
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
func getAccessibilityMessage() -> String {
|
func getAccessibilityMessage() -> String? {
|
||||||
guard let leftLabel = leftLabel.text else {
|
guard let leftLabel = leftLabel.text else {
|
||||||
return eyebrowHeadlineBodyLink.getAccessibilityMessage()
|
return eyebrowHeadlineBodyLink.getAccessibilityMessage()
|
||||||
}
|
}
|
||||||
return leftLabel + ", " + eyebrowHeadlineBodyLink.getAccessibilityMessage()
|
guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else {
|
||||||
|
return leftLabel
|
||||||
|
}
|
||||||
|
return leftLabel + ", " + label
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateAccessibilityLabel() {
|
func updateAccessibilityLabel() {
|
||||||
|
|||||||
@ -89,16 +89,8 @@ import Foundation
|
|||||||
message += radioButtonLabel + ", "
|
message += radioButtonLabel + ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text {
|
if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() {
|
||||||
message += eyebrowLabel + ", "
|
message += label
|
||||||
}
|
|
||||||
|
|
||||||
if let headlineLabel = eyebrowHeadlineBodyLink.headline.text {
|
|
||||||
message += headlineLabel + ", "
|
|
||||||
}
|
|
||||||
|
|
||||||
if let bodyLabel = eyebrowHeadlineBodyLink.body.text {
|
|
||||||
message += bodyLabel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
||||||
@ -112,18 +104,7 @@ import Foundation
|
|||||||
} else {
|
} else {
|
||||||
// Allow only radio button and link to be focused on.
|
// Allow only radio button and link to be focused on.
|
||||||
radioButton.accessibilityLabel = message
|
radioButton.accessibilityLabel = message
|
||||||
|
accessibilityElements = [radioButton, eyebrowHeadlineBodyLink.link]
|
||||||
var elements: [UIView] = []
|
|
||||||
|
|
||||||
if !message.isEmpty {
|
|
||||||
elements.append(radioButton)
|
|
||||||
}
|
|
||||||
|
|
||||||
if linkShowing {
|
|
||||||
elements.append(eyebrowHeadlineBodyLink.link)
|
|
||||||
}
|
|
||||||
|
|
||||||
accessibilityElements = elements
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,16 +107,8 @@ import UIKit
|
|||||||
message += leftImageLabel + ", "
|
message += leftImageLabel + ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text {
|
if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() {
|
||||||
message += eyebrowLabel + ", "
|
message += label
|
||||||
}
|
|
||||||
|
|
||||||
if let headlineLabel = eyebrowHeadlineBodyLink.headline.text {
|
|
||||||
message += headlineLabel + ", "
|
|
||||||
}
|
|
||||||
|
|
||||||
if let bodyLabel = eyebrowHeadlineBodyLink.body.text {
|
|
||||||
message += bodyLabel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0
|
||||||
@ -130,17 +122,7 @@ import UIKit
|
|||||||
} else {
|
} else {
|
||||||
// Allow only radio button and link to be focused on.
|
// Allow only radio button and link to be focused on.
|
||||||
radioButton.accessibilityLabel = message
|
radioButton.accessibilityLabel = message
|
||||||
var elements: [UIView] = []
|
accessibilityElements = [radioButton, eyebrowHeadlineBodyLink.link]
|
||||||
|
|
||||||
if !message.isEmpty {
|
|
||||||
elements.append(radioButton)
|
|
||||||
}
|
|
||||||
|
|
||||||
if linkShowing {
|
|
||||||
elements.append(eyebrowHeadlineBodyLink.link)
|
|
||||||
}
|
|
||||||
|
|
||||||
accessibilityElements = elements
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ import UIKit
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Returns the labels text in one message.
|
/// Returns the labels text in one message.
|
||||||
func getAccessibilityMessage() -> String {
|
func getAccessibilityMessage() -> String? {
|
||||||
var message = ""
|
var message = ""
|
||||||
|
|
||||||
if let eyebrowLabel = eyebrow.text {
|
if let eyebrowLabel = eyebrow.text {
|
||||||
@ -89,7 +89,7 @@ import UIKit
|
|||||||
if let bodyLabel = body.text {
|
if let bodyLabel = body.text {
|
||||||
message += bodyLabel
|
message += bodyLabel
|
||||||
}
|
}
|
||||||
return message
|
return message.count > 0 ? message : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an array of the appropriate accessibility elements.
|
/// Returns an array of the appropriate accessibility elements.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user