designed accessitbility
This commit is contained in:
parent
acab145af7
commit
e312e629e7
@ -67,14 +67,17 @@ import Foundation
|
|||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
addMolecule(containingStack)
|
addMolecule(containingStack)
|
||||||
|
|
||||||
for molecule in containingStack.stackItems {
|
for molecule in containingStack.stackItems {
|
||||||
((molecule as? StackItem)?.view as? Stack<StackModel>)?.restack()
|
((molecule as? StackItem)?.view as? Stack<StackModel>)?.restack()
|
||||||
}
|
}
|
||||||
containingStack.restack()
|
containingStack.restack()
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -96,6 +99,7 @@ import Foundation
|
|||||||
rightHeadline3.set(with: model.rightHeadline3, delegateObject, additionalData)
|
rightHeadline3.set(with: model.rightHeadline3, delegateObject, additionalData)
|
||||||
rightBody.set(with: model.rightBody, delegateObject, additionalData)
|
rightBody.set(with: model.rightBody, delegateObject, additionalData)
|
||||||
rightLink.set(with: model.rightLink, delegateObject, additionalData)
|
rightLink.set(with: model.rightLink, delegateObject, additionalData)
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
@ -113,4 +117,104 @@ import Foundation
|
|||||||
public override class func estimatedHeight(with molecule: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
public override class func estimatedHeight(with molecule: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||||
return 121
|
return 121
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Accessibility
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
func updateAccessibilityLabel() {
|
||||||
|
|
||||||
|
let leftHeadline1 = Label.createLabelBoldBodySmall(true)
|
||||||
|
let leftHeadline2 = Label.createLabelBoldBodySmall(true)
|
||||||
|
let leftHeadline3 = Label.createLabelBoldBodySmall(true)
|
||||||
|
let leftBody = Label.createLabelRegularBodySmall(true)
|
||||||
|
let leftLink = Link()
|
||||||
|
|
||||||
|
let rightHeadline1 = Label.createLabelBoldBodySmall(true)
|
||||||
|
let rightHeadline2 = Label.createLabelBoldBodySmall(true)
|
||||||
|
let rightHeadline3 = Label.createLabelBoldBodySmall(true)
|
||||||
|
let rightBody = Label.createLabelRegularBodySmall(true)
|
||||||
|
let rightLink = Link()
|
||||||
|
|
||||||
|
var message = ""
|
||||||
|
|
||||||
|
if let eyebrowText = eyebrow.text, !eyebrowText.isEmpty {
|
||||||
|
message += eyebrowText + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
if let headlineText = headline.text, !headlineText.isEmpty {
|
||||||
|
message += headlineText + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
if let bodyText = body.text, !bodyText.isEmpty {
|
||||||
|
message += bodyText + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
if let body2Text = body2.text, !body2Text.isEmpty {
|
||||||
|
message += body2Text + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
if let rightImageLabel = rightImage.accessibilityLabel {
|
||||||
|
message += rightImageLabel
|
||||||
|
}
|
||||||
|
|
||||||
|
let leftLinkIsDisplayed = !twoLinkView.leftLink.isHidden
|
||||||
|
let rightLinkIsDisplayed = !twoLinkView.rightLink.isHidden
|
||||||
|
|
||||||
|
// Both links are displayed
|
||||||
|
if leftLinkIsDisplayed && rightLinkIsDisplayed {
|
||||||
|
isAccessibilityElement = false
|
||||||
|
var views = [UIView]()
|
||||||
|
|
||||||
|
if let eyebrowText = eyebrow.text, !eyebrowText.isEmpty {
|
||||||
|
views.append(eyebrow)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let headlineText = headline.text, !headlineText.isEmpty {
|
||||||
|
views.append(headline)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let bodyText = body.text, !bodyText.isEmpty {
|
||||||
|
views.append(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let body2Text = body2.text, !body2Text.isEmpty {
|
||||||
|
views.append(body2)
|
||||||
|
}
|
||||||
|
|
||||||
|
views.append(twoLinkView.leftLink)
|
||||||
|
views.append(twoLinkView.rightLink)
|
||||||
|
|
||||||
|
accessibilityElements = views
|
||||||
|
return
|
||||||
|
|
||||||
|
} else if leftLinkIsDisplayed {
|
||||||
|
accessibilityHint = twoLinkView.leftLink.accessibilityHint
|
||||||
|
accessibilityTraits = twoLinkView.leftLink.accessibilityTraits
|
||||||
|
message += twoLinkView.leftLink.accessibilityLabel ?? ""
|
||||||
|
|
||||||
|
} else if rightLinkIsDisplayed {
|
||||||
|
accessibilityHint = twoLinkView.rightLink.accessibilityHint
|
||||||
|
accessibilityTraits = twoLinkView.rightLink.accessibilityTraits
|
||||||
|
message += twoLinkView.rightLink.accessibilityLabel ?? ""
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
isAccessibilityElement = true
|
||||||
|
accessibilityLabel = message
|
||||||
|
}
|
||||||
|
|
||||||
|
open override func accessibilityActivate() -> Bool {
|
||||||
|
|
||||||
|
if isAccessibilityElement {
|
||||||
|
if !twoLinkView.leftLink.isHidden {
|
||||||
|
return twoLinkView.leftLink.accessibilityActivate()
|
||||||
|
} else if !twoLinkView.rightLink.isHidden {
|
||||||
|
return twoLinkView.rightLink.accessibilityActivate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,6 +68,9 @@ import Foundation
|
|||||||
leftHeadline.numberOfLines = 1
|
leftHeadline.numberOfLines = 1
|
||||||
rightLabel.numberOfLines = 1
|
rightLabel.numberOfLines = 1
|
||||||
rightSubLabel.numberOfLines = 1
|
rightSubLabel.numberOfLines = 1
|
||||||
|
|
||||||
|
isAccessibilityElement = true
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
@ -83,6 +86,7 @@ import Foundation
|
|||||||
leftBody.set(with: model.leftBody, delegateObject, additionalData)
|
leftBody.set(with: model.leftBody, delegateObject, additionalData)
|
||||||
rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
|
rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
|
||||||
rightSubLabel.set(with: model.rightSubLabel, delegateObject, additionalData)
|
rightSubLabel.set(with: model.rightSubLabel, delegateObject, additionalData)
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override class func estimatedHeight(with molecule: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
open override class func estimatedHeight(with molecule: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
@ -98,4 +102,31 @@ import Foundation
|
|||||||
rightLabel.styleRegularBodySmall(true)
|
rightLabel.styleRegularBodySmall(true)
|
||||||
rightSubLabel.styleRegularBodySmall(true)
|
rightSubLabel.styleRegularBodySmall(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------
|
||||||
|
// MARK: - Accessibility
|
||||||
|
//----------------------------------------------------
|
||||||
|
|
||||||
|
func updateAccessibilityLabel() {
|
||||||
|
|
||||||
|
var message = ""
|
||||||
|
|
||||||
|
if let leftHeadline = leftHeadline.text, !leftHeadline.isEmpty {
|
||||||
|
message += leftHeadline + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
if let leftBody = leftBody.text, !leftBody.isEmpty {
|
||||||
|
message += leftBody + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
if let rightLabel = rightLabel.text, !rightLabel.isEmpty {
|
||||||
|
message += rightLabel + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
if let rightSubLabel = rightSubLabel.text, !rightSubLabel.isEmpty {
|
||||||
|
message += rightSubLabel
|
||||||
|
}
|
||||||
|
|
||||||
|
accessibilityLabel = message
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,8 @@ import UIKit
|
|||||||
containerHelper.constrainView(view)
|
containerHelper.constrainView(view)
|
||||||
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
||||||
rightLabel.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
rightLabel.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||||
|
isAccessibilityElement = true
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
@ -50,6 +52,7 @@ import UIKit
|
|||||||
|
|
||||||
leftLabel.set(with: model.leftLabel, delegateObject, additionalData)
|
leftLabel.set(with: model.leftLabel, delegateObject, additionalData)
|
||||||
rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
|
rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
@ -63,4 +66,23 @@ import UIKit
|
|||||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||||
return 15
|
return 15
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------
|
||||||
|
// MARK: - Accessibility
|
||||||
|
//----------------------------------------------------
|
||||||
|
|
||||||
|
func updateAccessibilityLabel() {
|
||||||
|
|
||||||
|
var message = ""
|
||||||
|
|
||||||
|
if let leftLabel = leftLabel.text, !leftLabel.isEmpty {
|
||||||
|
message += leftLabel + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
if let rightLabel = rightLabel.text, !rightLabel.isEmpty {
|
||||||
|
message += rightLabel
|
||||||
|
}
|
||||||
|
|
||||||
|
accessibilityLabel = message
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user