vds_ios/VDS/Protocols/Clickable.swift
Matt Bruce 77f8dfa3d8 CXTDT-552825 - Tilelet - Accessibility – The role of button is not provided for the tilelet.
CXTDT-552834 - TileContainer - Accessibility – Voice over is not rendering the information present click state.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-05-03 09:30:02 -05:00

37 lines
1.1 KiB
Swift

//
// Clickable.swift
// VDS
//
// Created by Matt Bruce on 3/29/23.
//
import Foundation
import UIKit
import Combine
public protocol Clickable: ViewProtocol where Self: UIControl {
/// Sets the primary Subscriber used for the UIControl event .touchUpInside.
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 {
onClickSubscriber?.cancel()
if let newValue {
onClickSubscriber = publisher(for: .touchUpInside)
.sink { [weak self] c in
guard let self, self.isEnabled else { return }
newValue(c)
}
} else {
onClickSubscriber = nil
}
setNeedsUpdate()
}
}
}