refactored to one selectorgrouphandlerbase
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
bb158f506f
commit
caf5415853
@ -11,13 +11,53 @@ import Combine
|
||||
|
||||
/// Base Class used for any Grouped Form Control of a Selector Type.
|
||||
open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
open var mainStackView: UIStackView = {
|
||||
return UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.alignment = .fill
|
||||
$0.distribution = .fill
|
||||
$0.axis = .vertical
|
||||
$0.spacing = VDSLayout.Spacing.space3X.value
|
||||
}
|
||||
}()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
/// Array of the HandlerType registered.
|
||||
open var selectorViews: [HandlerType] = []
|
||||
|
||||
/// Array of HandlerType that the user will have the ability to select from.
|
||||
open var selectorViews: [HandlerType] = [] {
|
||||
willSet {
|
||||
mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
|
||||
didSet {
|
||||
for selector in selectorViews {
|
||||
selector.onClick = { [weak self] handler in
|
||||
self?.didSelect(handler)
|
||||
self?.setNeedsUpdate()
|
||||
}
|
||||
mainStackView.addArrangedSubview(selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Current Selected Control for this group.
|
||||
open var selectedHandlers: [HandlerType]? {
|
||||
let selected = selectorViews.filter{ $0.isSelected == true }
|
||||
guard selected.count > 0 else { return nil }
|
||||
return selected
|
||||
}
|
||||
|
||||
/// Current Selected Control for this group.
|
||||
open var selectedHandler: HandlerType? {
|
||||
return selectorViews.filter { $0.isSelected == true }.first
|
||||
}
|
||||
|
||||
open var onChangeSubscriber: AnyCancellable? {
|
||||
willSet {
|
||||
if let onChangeSubscriber {
|
||||
@ -45,6 +85,14 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Overrides
|
||||
//--------------------------------------------------
|
||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
|
||||
addSubview(mainStackView)
|
||||
mainStackView.pinToSuperView()
|
||||
}
|
||||
|
||||
/// Handler for the Group to override on a select event.
|
||||
/// - Parameter selectedControl: Selected Control the user interacted.
|
||||
open func didSelect(_ selectedControl: HandlerType) {
|
||||
@ -63,27 +111,4 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
|
||||
super.reset()
|
||||
selectorViews.forEach{ $0.reset() }
|
||||
}
|
||||
|
||||
/// Used to update any Accessibility properties.
|
||||
open override func updateAccessibility() {
|
||||
super.updateAccessibility()
|
||||
setAccessibilityLabel(for: selectorViews)
|
||||
}
|
||||
}
|
||||
|
||||
open class SelectorGroupSelectedHandlerBase<HandlerType: Control>: SelectorGroupHandlerBase<HandlerType>{
|
||||
|
||||
/// Current Selected Control for this group.
|
||||
public var selectedHandler: HandlerType? {
|
||||
return selectorViews.filter { $0.isSelected == true }.first
|
||||
}
|
||||
|
||||
open override func updateAccessibility() {
|
||||
super.updateAccessibility()
|
||||
if let selectedHandler, let value = selectedHandler.accessibilityValue, let label = selectedHandler.accessibilityLabel {
|
||||
accessibilityValue = "\(label) \(value)"
|
||||
} else {
|
||||
accessibilityValue = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,29 +31,6 @@ open class CheckboxGroup: SelectorGroupHandlerBase<CheckboxItem> {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
/// Arrary of ``CheckboxItem`` within this group that are selected.
|
||||
open var selectedHandlers: [CheckboxItem]? {
|
||||
let selected = selectorViews.filter{ $0.isSelected == true }
|
||||
guard selected.count > 0 else { return nil }
|
||||
return selected
|
||||
}
|
||||
|
||||
/// Array of ``CheckboxItem`` that the user will have the ability to select from.
|
||||
open override var selectorViews: [CheckboxItem] {
|
||||
willSet {
|
||||
mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
|
||||
didSet {
|
||||
for selector in selectorViews {
|
||||
selector.onClick = { [weak self] handler in
|
||||
self?.didSelect(handler)
|
||||
}
|
||||
mainStackView.addArrangedSubview(selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Array of ``CheckboxItemModel`` that will be used to build the selectorViews of type ``CheckboxItem``.
|
||||
open var selectorModels: [CheckboxItemModel]? {
|
||||
didSet {
|
||||
@ -97,30 +74,14 @@ open class CheckboxGroup: SelectorGroupHandlerBase<CheckboxItem> {
|
||||
_showError = newShowError
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
private var mainStackView: UIStackView = {
|
||||
return UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.alignment = .fill
|
||||
$0.distribution = .fill
|
||||
$0.axis = .vertical
|
||||
$0.spacing = VDSLayout.Spacing.space6X.value
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Overrides
|
||||
//--------------------------------------------------
|
||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
|
||||
addSubview(mainStackView)
|
||||
|
||||
mainStackView.pinToSuperView()
|
||||
mainStackView.spacing = VDSLayout.Spacing.space6X.value
|
||||
}
|
||||
|
||||
public override func didSelect(_ selectedControl: CheckboxItem) {
|
||||
|
||||
@ -9,7 +9,7 @@ import Foundation
|
||||
import UIKit
|
||||
|
||||
@objc(VDSRadioBoxGroup)
|
||||
open class RadioBoxGroup: SelectorGroupSelectedHandlerBase<RadioBoxItem> {
|
||||
open class RadioBoxGroup: SelectorGroupHandlerBase<RadioBoxItem> {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -25,37 +25,10 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase<RadioBoxItem> {
|
||||
public required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
private var mainStackView: UIStackView = {
|
||||
return UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.spacing = VDSLayout.Spacing.space3X.value
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
/// Array of ``RadioBoxItem`` that the user will have the ability to select from.
|
||||
public override var selectorViews: [RadioBoxItem] {
|
||||
willSet {
|
||||
mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
|
||||
didSet {
|
||||
for selector in selectorViews {
|
||||
selector.onClick = { [weak self] handler in
|
||||
self?.didSelect(handler)
|
||||
self?.setNeedsUpdate()
|
||||
}
|
||||
mainStackView.addArrangedSubview(selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Array of ``RadioBoxItemModel`` that will be used to build the selectorViews of type ``RadioBoxItem``.
|
||||
open var selectorModels: [RadioBoxItemModel]? {
|
||||
didSet {
|
||||
@ -102,10 +75,7 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase<RadioBoxItem> {
|
||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
addSubview(mainStackView)
|
||||
ensureDevice()
|
||||
mainStackView.pinToSuperView()
|
||||
|
||||
NotificationCenter.default
|
||||
.publisher(for: UIDevice.orientationDidChangeNotification)
|
||||
.sink() { [weak self] _ in
|
||||
|
||||
@ -9,7 +9,7 @@ import Foundation
|
||||
import UIKit
|
||||
|
||||
@objc(VDSRadioButtonGroup)
|
||||
open class RadioButtonGroup: SelectorGroupSelectedHandlerBase<RadioButtonItem> {
|
||||
open class RadioButtonGroup: SelectorGroupHandlerBase<RadioButtonItem> {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -26,39 +26,9 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase<RadioButtonItem> {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
private var mainStackView: UIStackView = {
|
||||
return UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.alignment = .fill
|
||||
$0.distribution = .fill
|
||||
$0.axis = .vertical
|
||||
$0.spacing = VDSLayout.Spacing.space6X.value
|
||||
}
|
||||
}()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
/// Array of ``RadioButtonItem`` that the user will have the ability to select from.
|
||||
public override var selectorViews: [RadioButtonItem] {
|
||||
willSet {
|
||||
mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
|
||||
didSet {
|
||||
for selector in selectorViews {
|
||||
selector.onClick = { [weak self] handler in
|
||||
self?.didSelect(handler)
|
||||
self?.setNeedsUpdate()
|
||||
}
|
||||
mainStackView.addArrangedSubview(selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Array of ``RadioButtonItemModel`` that will be used to build the selectorViews of type ``RadioButtonItem``.
|
||||
open var selectorModels: [RadioButtonItemModel]? {
|
||||
didSet {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user