Updated logic
Updated access to children instead of parent
This commit is contained in:
parent
5f15d630e1
commit
d99a7ee546
@ -15,7 +15,6 @@
|
||||
public let checkbox = Checkbox()
|
||||
public let label = Label(fontStyle: .RegularBodySmall)
|
||||
private var observation: NSKeyValueObservation? = nil
|
||||
public var clauses: [Label.ActionableClause] = []
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
@ -44,7 +43,6 @@
|
||||
addSubview(label)
|
||||
|
||||
label.text = ""
|
||||
accessibilityCustomActions = []
|
||||
checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
||||
|
||||
checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor)
|
||||
@ -65,9 +63,8 @@
|
||||
bottomLabelConstraint.isActive = true
|
||||
|
||||
alignCheckbox(.center)
|
||||
isAccessibilityElement = true
|
||||
accessibilityHint = checkbox.accessibilityHint
|
||||
accessibilityTraits = checkbox.accessibilityTraits
|
||||
isAccessibilityElement = false
|
||||
accessibilityElements = [checkbox, label]
|
||||
observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in
|
||||
self?.updateAccessibilityLabel()
|
||||
}
|
||||
@ -140,26 +137,9 @@
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if let text = label.text {
|
||||
checkbox.accessibilityLabel?.append(", \(text)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user