vds_ios/VDS/Protocols/Clickable.swift
Matt Bruce 94d44c5d54 refactored clickable
removed old clickable code

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-03-29 15:37:32 -05:00

53 lines
1.2 KiB
Swift

//
// Clickable.swift
// VDS
//
// Created by Matt Bruce on 3/29/23.
//
import Foundation
import UIKit
public protocol Clickable where Self: UIControl {}
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: ButtonBase {
public var onClick: ((Self) -> ())? {
get { return nil }
set {
if let newValue {
onClickSubscriber = publisher(for: .touchUpInside)
.sink { c in
newValue(c)
}
} else {
onClickSubscriber = nil
}
}
}
}
extension Clickable where Self: Control {
public var onClick: ((Self) -> ())? {
get { return nil }
set {
if let newValue {
onClickSubscriber = publisher(for: .touchUpInside)
.sink { c in
newValue(c)
}
} else {
onClickSubscriber = nil
}
}
}
}