// // Clickable.swift // VDS // // Created by Matt Bruce on 3/29/23. // import Foundation import UIKit public protocol Clickable where Self: UIControl { var onClick: ((Self) -> ())? { get set } func setupOnClick() } extension Clickable where Self: Handlerable { public func addEvent(event: UIControl.Event, block: @escaping (Self)->()) { publisher(for: event) .sink(receiveValue: { c in block(c) }).store(in: &subscribers) } } extension Clickable where Self: Control { public func setupOnClick() { if let onClick { onClickSubscriber = publisher(for: .touchUpInside) .sink(receiveValue: { c in onClick(c) }) } else { onClickSubscriber = nil } } } extension Clickable where Self: ButtonBase { public func setupOnClick() { if let onClick { onClickSubscriber = publisher(for: .touchUpInside) .sink(receiveValue: { c in onClick(c) }) } else { onClickSubscriber = nil } } }