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