From 0eb23d51fc25433d55c88c7ab4ae2523f7c25ed3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 31 Aug 2022 10:38:21 -0500 Subject: [PATCH] moved touchup inside logic into control isTappable bool defaultAction() override --- VDS/Classes/Control.swift | 23 +++++++++++++++++++- VDS/Components/Checkbox/Checkbox.swift | 20 ++--------------- VDS/Components/RadioBox/RadioBox.swift | 20 ++--------------- VDS/Components/RadioButton/RadioButton.swift | 17 +-------------- VDS/Components/RadioSwatch/RadioSwatch.swift | 19 +--------------- 5 files changed, 28 insertions(+), 71 deletions(-) diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index e3adfb56..735db1cb 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -23,7 +23,12 @@ open class Control: UIControl, ModelHandlerable, ViewProto // MARK: - Properties //-------------------------------------------------- private var initialSetupPerformed = false - + + //if set to true this will call the + //defaultAction() in the class + public var executeDefaultAction = true + public var isTappable = true + @Proxy(\.model.surface) open var surface: Surface @@ -79,6 +84,7 @@ open class Control: UIControl, ModelHandlerable, ViewProto initialSetupPerformed = true setupUpdateView() setup() + if isTappable { addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap))) } } } @@ -89,7 +95,22 @@ open class Control: UIControl, ModelHandlerable, ViewProto return true } + //-------------------------------------------------- + // MARK: - Actions + //-------------------------------------------------- + open override func sendActions(for controlEvents: UIControl.Event) { + super.sendActions(for: controlEvents) + if controlEvents.contains(.touchUpInside) && executeDefaultAction{ + defaultAction() + } + } + @objc func tap() { + sendActions(for: .touchUpInside) + } + + open func defaultAction() { } + //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index d1651adf..7949ecc1 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -127,7 +127,6 @@ open class CheckboxBase: Control, Changable open override func setup() { super.setup() - addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap))) isAccessibilityElement = true accessibilityTraits = .button @@ -204,24 +203,9 @@ open class CheckboxBase: Control, Changable setAccessibilityLabel() onChange = nil } - - //-------------------------------------------------- - // MARK: - Actions - //-------------------------------------------------- - open override func sendActions(for controlEvents: UIControl.Event) { - super.sendActions(for: controlEvents) - if controlEvents.contains(.touchUpInside) { - toggle() - } - } - - @objc func tap() { - sendActions(for: .touchUpInside) - - } - + /// This will checkbox the state of the Selector and execute the actionBlock if provided. - open func toggle() { + open override func defaultAction() { //removed error if hasError && isSelected == false { hasError.toggle() diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 300cc770..c71728a3 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -128,8 +128,7 @@ open class RadioBoxBase: Control, Changable open override func setup() { super.setup() - addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap))) - + isAccessibilityElement = true accessibilityTraits = .button addSubview(selectorView) @@ -204,23 +203,8 @@ open class RadioBoxBase: Control, Changable onChange = nil } - //-------------------------------------------------- - // MARK: - Actions - //-------------------------------------------------- - open override func sendActions(for controlEvents: UIControl.Event) { - super.sendActions(for: controlEvents) - if controlEvents.contains(.touchUpInside) { - toggle() - } - } - - @objc func tap() { - sendActions(for: .touchUpInside) - - } - /// This will radioBox the state of the Selector and execute the actionBlock if provided. - open func toggle() { + open override func defaultAction() { //removed error if hasError && isSelected == false { hasError.toggle() diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 6a80f240..46eabdee 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -126,7 +126,6 @@ open class RadioButtonBase: Control, Cha open override func setup() { super.setup() - addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap))) isAccessibilityElement = true accessibilityTraits = .button @@ -204,23 +203,9 @@ open class RadioButtonBase: Control, Cha onChange = nil } - //-------------------------------------------------- - // MARK: - Actions - //-------------------------------------------------- - open override func sendActions(for controlEvents: UIControl.Event) { - super.sendActions(for: controlEvents) - if controlEvents.contains(.touchUpInside) { - toggle() - } - } - - @objc func tap() { - sendActions(for: .touchUpInside) - - } /// This will checkbox the state of the Selector and execute the actionBlock if provided. - open func toggle() { + open override func defaultAction() { guard !isSelected else { return } //removed error diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index cbd783c6..72bc6ace 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -88,7 +88,6 @@ open class RadioSwatchBase: Control, Cha open override func setup() { super.setup() - addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap))) isAccessibilityElement = true accessibilityTraits = .button @@ -122,23 +121,7 @@ open class RadioSwatchBase: Control, Cha onChange = nil } - //-------------------------------------------------- - // MARK: - Actions - //-------------------------------------------------- - open override func sendActions(for controlEvents: UIControl.Event) { - super.sendActions(for: controlEvents) - if controlEvents.contains(.touchUpInside) { - toggle() - } - } - - @objc func tap() { - sendActions(for: .touchUpInside) - - } - - /// This will radioBox the state of the Selector and execute the actionBlock if provided. - open func toggle() { + open override func defaultAction() { isSelected.toggle() sendActions(for: .valueChanged) onChange?()