vds_ios/VDS/Protocols/Clickable.swift
Matt Bruce cd88205b40 added comments
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-07-26 10:20:11 -05:00

35 lines
928 B
Swift

//
// Clickable.swift
// VDS
//
// Created by Matt Bruce on 3/29/23.
//
import Foundation
import UIKit
import Combine
public protocol Clickable: Handlerable where Self: UIControl {
var touchUpInsideCount: Int { get set }
var onClickSubscriber: AnyCancellable? { get set }
}
extension Clickable {
/// Allows the setting of a completion block against the onClickSubscriber cancellable. This will
/// completion block will get executed against the UIControl publisher for the 'touchUpInside' action.
public var onClick: ((Self) -> ())? {
get { return nil }
set {
if let newValue {
onClickSubscriber = publisher(for: .touchUpInside)
.sink { c in
newValue(c)
}
} else {
onClickSubscriber?.cancel()
onClickSubscriber = nil
}
}
}
}