From f25aee83de6099dda05ab2e19aa821a004a75016 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 19 Jun 2024 14:02:11 -0500 Subject: [PATCH] only toggle when enabled Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 2 + VDS/Components/Checkbox/CheckboxItem.swift | 2 + VDS/Components/Label/Label.swift | 9 ++- VDS/Components/RadioBox/RadioBoxItem.swift | 55 ++++++++++++------- VDS/Components/RadioButton/RadioButton.swift | 2 +- .../RadioButton/RadioButtonItem.swift | 2 +- 6 files changed, 47 insertions(+), 25 deletions(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index a999e74a..3369ebcb 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -63,6 +63,8 @@ open class Checkbox: SelectorBase { /// This will change the state of the Selector and execute the actionBlock if provided. open override func toggle() { + guard isEnabled else { return } + //removed error if showError && isSelected == false { showError.toggle() diff --git a/VDS/Components/Checkbox/CheckboxItem.swift b/VDS/Components/Checkbox/CheckboxItem.swift index aa5dea5a..21943636 100644 --- a/VDS/Components/Checkbox/CheckboxItem.swift +++ b/VDS/Components/Checkbox/CheckboxItem.swift @@ -38,6 +38,8 @@ open class CheckboxItem: SelectorItemBase { //-------------------------------------------------- /// This will change the state of the Selector and execute the actionBlock if provided. open override func toggle() { + guard isEnabled else { return } + //removed error if showError && isSelected == false { showError.toggle() diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 090215c2..1ec1de82 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -363,7 +363,12 @@ open class Label: UILabel, ViewProtocol, UserInfoable { // creat the action let labelAction = LabelAction(range: actionable.range, action: actionable.action) - customAccessibilityAction?.action = labelAction.performAction + // set the action of the accessibilityElement + customAccessibilityAction?.action = { [weak self] in + guard let self, isEnabled else { return } + labelAction.performAction() + } + //create a wrapper for the attributes range, block and actions.append(labelAction) isUserInteractionEnabled = true @@ -449,7 +454,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { return element } - public override func accessibilityActivate() -> Bool { + open override func accessibilityActivate() -> Bool { return false } diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index 8ca46b26..417df508 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -198,7 +198,6 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { isAccessibilityElement = false selectorView.isAccessibilityElement = true selectorView.accessibilityTraits = .button - addSubview(selectorView) selectorView.isUserInteractionEnabled = false @@ -252,6 +251,8 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { /// This will change the state of the Selector and execute the actionBlock if provided. open func toggle() { + guard isEnabled else { return } + //removed error isSelected.toggle() sendActions(for: .valueChanged) @@ -268,14 +269,14 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { /// Used to update any Accessibility properties. open override func updateAccessibility() { super.updateAccessibility() - accessibilityLabel = accessibilityLabelText + selectorView.accessibilityLabel = accessibilityLabelText if let accessibilityValueText { - accessibilityValue = strikethrough + selectorView.accessibilityValue = strikethrough ? "\(strikethroughAccessibilityText), \(accessibilityValueText)" : accessibilityValueText } else { - accessibilityValue = strikethrough + selectorView.accessibilityValue = strikethrough ? "\(strikethroughAccessibilityText)" : accessibilityValueText } @@ -286,29 +287,41 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { var items = [Any]() items.append(selectorView) - let elements = gatherAccessibilityElements(from: selectorView) - let views = elements.compactMap({ $0 as? UIView }) - - //update accessibilityLabel - selectorView.setAccessibilityLabel(for: views) - - //disabled - if !isEnabled { - if let label = selectorView.accessibilityLabel, !label.isEmpty { - selectorView.accessibilityLabel = "\(label), dimmed" - } else { - selectorView.accessibilityLabel = "dimmed" - } + if let text = text, !text.isEmpty { + items.append(textLabel) + } + + if let text = subText, !text.isEmpty { + items.append(subTextLabel) + } + + if let text = subTextRight, !text.isEmpty { + items.append(subTextRightLabel) } - - //append all children that are accessible - items.append(contentsOf: elements) - return items } set {} } + /// Overriden to take the hit if there is an onClickSubscriber and the view is not a UIControl + open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + guard isEnabled else { return super.hitTest(point, with: event) } + + let textPoint = convert(point, to: textLabel) + let subTextPoint = convert(point, to: subTextLabel) + let subTextRightPoint = convert(point, to: subTextRightLabel) + + if textLabel.isAction(for: textPoint) { + return textLabel + } else if subTextLabel.isAction(for: subTextPoint) { + return subTextLabel + } else if subTextRightLabel.isAction(for: subTextRightPoint) { + return subTextRightLabel + } else { + guard !UIAccessibility.isVoiceOverRunning else { return nil } + return super.hitTest(point, with: event) + } + } //-------------------------------------------------- // MARK: - Private Methods diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 36a2cedf..f19e7b2f 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -62,7 +62,7 @@ open class RadioButton: SelectorBase { /// This will change the state of the Selector and execute the actionBlock if provided. open override func toggle() { - guard !isSelected else { return } + guard !isSelected, isEnabled else { return } //removed error if showError && isSelected == false { diff --git a/VDS/Components/RadioButton/RadioButtonItem.swift b/VDS/Components/RadioButton/RadioButtonItem.swift index ebde90c8..bc15531d 100644 --- a/VDS/Components/RadioButton/RadioButtonItem.swift +++ b/VDS/Components/RadioButton/RadioButtonItem.swift @@ -34,7 +34,7 @@ open class RadioButtonItem: SelectorItemBase { //-------------------------------------------------- /// This will change the state of the Selector and execute the actionBlock if provided. open override func toggle() { - guard !isSelected else { return } + guard !isSelected, isEnabled else { return } //removed error if showError && isSelected == false {