added comments to the SelectorGroupHandlerBase

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-05-26 16:24:25 -05:00
parent dcf766a267
commit 814a048690

View File

@ -9,13 +9,17 @@ import Foundation
import UIKit
import Combine
/// Base Class used for any Grouped Form Control of a Selector Type
open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
/// Array of the HandlerType registered
public var selectorViews: [HandlerType] = []
/// The primary subscriber for onChange or the UIControl valueChanged event.
public var onChangeSubscriber: AnyCancellable? {
willSet {
if let onChangeSubscriber {
@ -27,6 +31,8 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
/// Override to update the child SelectorViews disabled property for this group
override public var disabled: Bool {
didSet {
selectorViews.forEach { handler in
@ -35,6 +41,7 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
}
}
/// Override to update the child SelectorViews surface property for this group
override public var surface: Surface {
didSet {
selectorViews.forEach { handler in
@ -43,16 +50,20 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
}
}
/// Handler for the Group to override on a select event
/// - Parameter selectedControl: Selected Control the user interacted
open func didSelect(_ selectedControl: HandlerType) {
fatalError("Must override didSelect")
}
/// Helper method to execute the valueChanged event
public func valueChanged() {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) { [weak self] in
self?.sendActions(for: .valueChanged)
}
}
/// Override to update the child SelectorViews reset method for this group
open override func reset() {
super.reset()
selectorViews.forEach{ $0.reset() }
@ -60,6 +71,8 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
}
open class SelectorGroupSelectedHandlerBase<HandlerType: Control>: SelectorGroupHandlerBase<HandlerType>{
/// Current Selected Control for this group
public var selectedHandler: HandlerType? {
return selectorViews.filter { $0.isSelected == true }.first
}