vds_ios/VDS/Protocols/Clickable.swift
Matt Bruce 01725e634f added clickable
removed old code

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-03-29 13:46:55 -05:00

50 lines
1.1 KiB
Swift

//
// 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
}
}
}