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 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
|
||||||
@ -44,7 +43,6 @@
|
|||||||
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)
|
||||||
@ -65,9 +63,8 @@
|
|||||||
bottomLabelConstraint.isActive = true
|
bottomLabelConstraint.isActive = true
|
||||||
|
|
||||||
alignCheckbox(.center)
|
alignCheckbox(.center)
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = false
|
||||||
accessibilityHint = checkbox.accessibilityHint
|
accessibilityElements = [checkbox, label]
|
||||||
accessibilityTraits = checkbox.accessibilityTraits
|
|
||||||
observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in
|
observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in
|
||||||
self?.updateAccessibilityLabel()
|
self?.updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
@ -140,26 +137,9 @@
|
|||||||
|
|
||||||
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 {
|
if let text = label.text {
|
||||||
let actionText = NSString(string: label.text ?? "").substring(with: clause.range)
|
checkbox.accessibilityLabel?.append(", \(text)")
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user