Added customActions to checkBoxLabel

This commit is contained in:
Keerthy 2024-02-26 23:48:28 +05:30
parent 3eaf765655
commit 1b10c21100

View File

@ -15,6 +15,7 @@
public let checkbox = Checkbox()
public let label = Label(fontStyle: .RegularBodySmall)
private var observation: NSKeyValueObservation? = nil
public var clauses: [Label.ActionableClause] = []
//--------------------------------------------------
// MARK: - Properties
@ -43,7 +44,7 @@
addSubview(label)
label.text = ""
accessibilityCustomActions = []
checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor)
@ -139,6 +140,26 @@
open func 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: ",")
}
@objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) {
for clause in self.clauses {
if action.hash == clause.accessibilityID {
clause.performAction()
return
}
}
}
}