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
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var initialSetupPerformed = false
|
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)
|
@Proxy(\.model.surface)
|
||||||
open var surface: Surface
|
open var surface: Surface
|
||||||
|
|
||||||
@ -79,6 +84,7 @@ open class Control<ModelType: Modelable>: UIControl, ModelHandlerable, ViewProto
|
|||||||
initialSetupPerformed = true
|
initialSetupPerformed = true
|
||||||
setupUpdateView()
|
setupUpdateView()
|
||||||
setup()
|
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
|
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
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -127,7 +127,6 @@ open class CheckboxBase<ModelType: CheckboxModel>: Control<ModelType>, Changable
|
|||||||
|
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap)))
|
|
||||||
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
@ -204,24 +203,9 @@ open class CheckboxBase<ModelType: CheckboxModel>: Control<ModelType>, Changable
|
|||||||
setAccessibilityLabel()
|
setAccessibilityLabel()
|
||||||
onChange = nil
|
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.
|
/// This will checkbox the state of the Selector and execute the actionBlock if provided.
|
||||||
open func toggle() {
|
open override func defaultAction() {
|
||||||
//removed error
|
//removed error
|
||||||
if hasError && isSelected == false {
|
if hasError && isSelected == false {
|
||||||
hasError.toggle()
|
hasError.toggle()
|
||||||
|
|||||||
@ -128,8 +128,7 @@ open class RadioBoxBase<ModelType: RadioBoxModel>: Control<ModelType>, Changable
|
|||||||
|
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap)))
|
|
||||||
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
addSubview(selectorView)
|
addSubview(selectorView)
|
||||||
@ -204,23 +203,8 @@ open class RadioBoxBase<ModelType: RadioBoxModel>: Control<ModelType>, Changable
|
|||||||
onChange = nil
|
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.
|
/// This will radioBox the state of the Selector and execute the actionBlock if provided.
|
||||||
open func toggle() {
|
open override func defaultAction() {
|
||||||
//removed error
|
//removed error
|
||||||
if hasError && isSelected == false {
|
if hasError && isSelected == false {
|
||||||
hasError.toggle()
|
hasError.toggle()
|
||||||
|
|||||||
@ -126,7 +126,6 @@ open class RadioButtonBase<ModelType: RadioButtonModel>: Control<ModelType>, Cha
|
|||||||
|
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap)))
|
|
||||||
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
@ -204,23 +203,9 @@ open class RadioButtonBase<ModelType: RadioButtonModel>: Control<ModelType>, Cha
|
|||||||
onChange = nil
|
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.
|
/// 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 }
|
guard !isSelected else { return }
|
||||||
|
|
||||||
//removed error
|
//removed error
|
||||||
|
|||||||
@ -88,7 +88,6 @@ open class RadioSwatchBase<ModelType: RadioSwatchModel>: Control<ModelType>, Cha
|
|||||||
|
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(Self.tap)))
|
|
||||||
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
@ -122,23 +121,7 @@ open class RadioSwatchBase<ModelType: RadioSwatchModel>: Control<ModelType>, Cha
|
|||||||
onChange = nil
|
onChange = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
open override func defaultAction() {
|
||||||
// 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() {
|
|
||||||
isSelected.toggle()
|
isSelected.toggle()
|
||||||
sendActions(for: .valueChanged)
|
sendActions(for: .valueChanged)
|
||||||
onChange?()
|
onChange?()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user