From 85f210abe8397b69585ffab06eb4be87ce3d0646 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 08:49:51 -0500 Subject: [PATCH] Accessibility fixes. --- MVMCoreUI/Atoms/Views/Label.swift | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 56a0c38b..30101710 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -91,6 +91,7 @@ public typealias ActionBlock = () -> () translatesAutoresizingMaskIntoConstraints = false clauses = [] accessibilityCustomActions = [] + accessibilityTraits = .staticText let tapGesture = UITapGestureRecognizer(target: self, action: #selector(textLinkTapped(_:))) tapGesture.numberOfTapsRequired = 1 @@ -522,6 +523,7 @@ public typealias ActionBlock = () -> () func appendActionableClause(range: NSRange, actionBlock: @escaping ActionBlock) { + accessibilityTraits = .button let accessibleAction = customAccessibilityAction(range: range) clauses.append(ActionableClause(range: range, actionBlock: actionBlock, accessibilityID: accessibleAction?.hash ?? -1)) } @@ -582,6 +584,7 @@ extension Label { styleB2(true) accessibilityCustomActions = [] clauses = [] + accessibilityTraits = .staticText } @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { @@ -721,7 +724,6 @@ extension UITapGestureRecognizer { if label.makeWholeViewClickable { return true } - guard let abstractContainer = label.abstractTextContainer() else { return false } let textContainer = abstractContainer.0 let layoutManager = abstractContainer.1 @@ -775,7 +777,7 @@ extension Label { } @objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) { - + for clause in clauses { if action.hash == clause.accessibilityID { clause.performAction() @@ -783,4 +785,19 @@ extension Label { } } } + + open override func accessibilityActivate() -> Bool { + + guard let accessibleActions = accessibilityCustomActions else { return false } + + for clause in clauses { + for action in accessibleActions { + if action.hash == clause.accessibilityID { + clause.performAction() + return true + } + } + } + return false + } }