moved touchup inside logic into control
isTappable bool defaultAction() override
This commit is contained in:
parent
a9a3aeee18
commit
0eb23d51fc
@ -23,7 +23,12 @@ open class Control<ModelType: Modelable>: 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<ModelType: Modelable>: UIControl, ModelHandlerable, ViewProto
|
||||
initialSetupPerformed = true
|
||||
setupUpdateView()
|
||||
setup()
|
||||
if isTappable { addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap))) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +95,22 @@ open class Control<ModelType: Modelable>: 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
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -127,7 +127,6 @@ open class CheckboxBase<ModelType: CheckboxModel>: Control<ModelType>, 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<ModelType: CheckboxModel>: Control<ModelType>, 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()
|
||||
|
||||
@ -128,8 +128,7 @@ open class RadioBoxBase<ModelType: RadioBoxModel>: Control<ModelType>, 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<ModelType: RadioBoxModel>: Control<ModelType>, 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()
|
||||
|
||||
@ -126,7 +126,6 @@ open class RadioButtonBase<ModelType: RadioButtonModel>: Control<ModelType>, 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<ModelType: RadioButtonModel>: Control<ModelType>, 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
|
||||
|
||||
@ -88,7 +88,6 @@ open class RadioSwatchBase<ModelType: RadioSwatchModel>: Control<ModelType>, 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<ModelType: RadioSwatchModel>: Control<ModelType>, 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?()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user