refactored more on clickable

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-03-30 09:06:24 -05:00
parent 248caeb480
commit 334f9b798c
3 changed files with 4 additions and 8 deletions

View File

@ -43,7 +43,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
var isHighlightAnimating = false
open override var isHighlighted: Bool {
didSet {
if isHighlightAnimating == false && isClickable {
if isHighlightAnimating == false && touchUpInsideCount > 0 {
isHighlightAnimating = true
UIView.animate(withDuration: 0.1, animations: { [weak self] in
self?.updateView()

View File

@ -64,7 +64,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
open override var isHighlighted: Bool {
didSet {
if isHighlightAnimating == false && isClickable {
if isHighlightAnimating == false && touchUpInsideCount > 0 {
isHighlightAnimating = true
UIView.animate(withDuration: 0.1, animations: { [weak self] in
self?.updateView()

View File

@ -9,23 +9,19 @@ import Foundation
import UIKit
import Combine
public protocol Clickable where Self: UIControl {
public protocol Clickable: Handlerable where Self: UIControl {
var touchUpInsideCount: Int { get set }
var onClickSubscriber: AnyCancellable? { get set }
}
extension Clickable where Self: Handlerable {
extension Clickable {
public func addEvent(event: UIControl.Event, block: @escaping (Self)->()) {
publisher(for: event)
.sink(receiveValue: { c in
block(c)
}).store(in: &subscribers)
}
internal var isClickable: Bool { return touchUpInsideCount > 0 }
}
extension Clickable {
public var onClick: ((Self) -> ())? {
get { return nil }
set {