Added customActions to checkBoxLabel
This commit is contained in:
parent
3eaf765655
commit
1b10c21100
@ -15,6 +15,7 @@
|
|||||||
public let checkbox = Checkbox()
|
public let checkbox = Checkbox()
|
||||||
public let label = Label(fontStyle: .RegularBodySmall)
|
public let label = Label(fontStyle: .RegularBodySmall)
|
||||||
private var observation: NSKeyValueObservation? = nil
|
private var observation: NSKeyValueObservation? = nil
|
||||||
|
public var clauses: [Label.ActionableClause] = []
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
@ -43,7 +44,7 @@
|
|||||||
addSubview(label)
|
addSubview(label)
|
||||||
|
|
||||||
label.text = ""
|
label.text = ""
|
||||||
|
accessibilityCustomActions = []
|
||||||
checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
||||||
|
|
||||||
checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor)
|
checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor)
|
||||||
@ -139,6 +140,26 @@
|
|||||||
|
|
||||||
open func updateAccessibilityLabel() {
|
open func updateAccessibilityLabel() {
|
||||||
checkbox.updateAccessibilityLabel()
|
checkbox.updateAccessibilityLabel()
|
||||||
|
isAccessibilityElement = true
|
||||||
|
if !label.clauses.isEmpty {
|
||||||
|
accessibilityHint?.append(", \(String(format: (MVMCoreUIUtility.hardcodedString(withKey: "swipe_to_select_with_action_hint")) ?? "") )")
|
||||||
|
|
||||||
|
for clause in label.clauses {
|
||||||
|
let actionText = NSString(string: label.text ?? "").substring(with: clause.range)
|
||||||
|
let accessibleAction = UIAccessibilityCustomAction(name: actionText, target: self, selector: #selector(accessibilityCustomAction(_:)))
|
||||||
|
self.clauses.append(Label.ActionableClause.init(range: clause.range, actionBlock: clause.actionBlock, accessibilityID: accessibleAction.hash))
|
||||||
|
accessibilityCustomActions?.append(accessibleAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
accessibilityLabel = [checkbox.accessibilityLabel, label.text].compactMap { $0 }.joined(separator: ",")
|
accessibilityLabel = [checkbox.accessibilityLabel, label.text].compactMap { $0 }.joined(separator: ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) {
|
||||||
|
for clause in self.clauses {
|
||||||
|
if action.hash == clause.accessibilityID {
|
||||||
|
clause.performAction()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user