vds_ios/VDS/Protocols/Changeable.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

36 lines
996 B
Swift

//
// Changeable.swift
// VDS
//
// Created by Matt Bruce on 4/3/23.
//
import Foundation
import UIKit
import Combine
public protocol Changeable: ViewProtocol where Self: UIControl {
/// Sets the primary Subscriber used for the UIControl event .valueChanged.
var onChangeSubscriber: AnyCancellable? { get set }
}
extension Changeable {
/// Allows the setting of a completion block against the onChangeSubscriber cancellable. This will
/// completion block will get executed against the UIControl publisher for the 'valueChange' action.
public var onChange: ((Self) -> ())? {
get { return nil }
set {
onChangeSubscriber?.cancel()
if let newValue {
onChangeSubscriber = publisher(for: .valueChanged)
.sink { c in
newValue(c)
}
} else {
onChangeSubscriber = nil
}
setNeedsUpdate()
}
}
}