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 var isHighlightAnimating = false
open override var isHighlighted: Bool { open override var isHighlighted: Bool {
didSet { didSet {
if isHighlightAnimating == false && isClickable { if isHighlightAnimating == false && touchUpInsideCount > 0 {
isHighlightAnimating = true isHighlightAnimating = true
UIView.animate(withDuration: 0.1, animations: { [weak self] in UIView.animate(withDuration: 0.1, animations: { [weak self] in
self?.updateView() self?.updateView()

View File

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

View File

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