diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index d6a28a98..b994a9cf 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -21,13 +21,38 @@ open class CheckboxGroup: SelectorGroupHandlerBase { } public override var selectorViews: [Checkbox] { + willSet { + mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } + } + didSet { for selector in selectorViews { - if !mainStackView.arrangedSubviews.contains(selector) { - selector.onClick = { [weak self] handler in - self?.didSelect(handler) + selector.onClick = { [weak self] handler in + self?.didSelect(handler) + } + mainStackView.addArrangedSubview(selector) + } + } + } + + public var selectorModels: [CheckboxModel]? { + didSet { + if let selectorModels { + selectorViews = selectorModels.map { model in + return Checkbox().with { + $0.disabled = model.disabled + $0.surface = model.surface + $0.inputId = model.inputId + $0.value = model.value + $0.accessibilityLabel = model.accessibileText + $0.labelText = model.labelText + $0.labelTextAttributes = model.labelTextAttributes + $0.childText = model.childText + $0.childTextAttributes = model.childTextAttributes + $0.isSelected = model.selected + $0.errorText = model.errorText + $0.showError = model.showError } - mainStackView.addArrangedSubview(selector) } } } @@ -117,24 +142,5 @@ extension CheckboxGroup { self.init(disabled: false) } } - - public func setSelectorViewModels(models: [CheckboxModel]) { - selectorViews = models.map { model in - return Checkbox().with { - $0.disabled = model.disabled - $0.surface = model.surface - $0.inputId = model.inputId - $0.value = model.value - $0.accessibilityLabel = model.accessibileText - $0.labelText = model.labelText - $0.labelTextAttributes = model.labelTextAttributes - $0.childText = model.childText - $0.childTextAttributes = model.childTextAttributes - $0.isSelected = model.selected - $0.errorText = model.errorText - $0.showError = model.showError - } - } - } } diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 6299eb7a..9c39bf19 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -15,18 +15,41 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { // MARK: - Public Properties //-------------------------------------------------- public override var selectorViews: [RadioBox] { + willSet { + mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } + } + didSet { for selector in selectorViews { - if !mainStackView.arrangedSubviews.contains(selector) { - selector.onClick = { [weak self] handler in - self?.didSelect(handler) - } - mainStackView.addArrangedSubview(selector) + selector.onClick = { [weak self] handler in + self?.didSelect(handler) } + mainStackView.addArrangedSubview(selector) } } } + public var selectorModels: [RadioBoxModel]? { + didSet { + if let selectorModels { + selectorViews = selectorModels.map { model in + return RadioBox().with { + $0.accessibilityLabel = model.accessibileText + $0.text = model.text + $0.textAttributes = model.textAttributes + $0.subText = model.subText + $0.subTextAttributes = model.subTextAttributes + $0.subTextRight = model.subText + $0.subTextRightAttributes = model.subTextAttributes + $0.disabled = model.disabled + $0.inputId = model.inputId + $0.isSelected = model.selected + } + } + } + } + } + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- @@ -119,21 +142,4 @@ extension RadioBoxGroup { self.init(disabled: false) } } - - public func setSelectorViewModels(models: [RadioBoxModel]) { - selectorViews = models.map { model in - return RadioBox().with { - $0.accessibilityLabel = model.accessibileText - $0.text = model.text - $0.textAttributes = model.textAttributes - $0.subText = model.subText - $0.subTextAttributes = model.subTextAttributes - $0.subTextRight = model.subText - $0.subTextRightAttributes = model.subTextAttributes - $0.disabled = model.disabled - $0.inputId = model.inputId - $0.isSelected = model.selected - } - } - } } diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 88e17440..ffdfdde3 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -15,13 +15,38 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { // MARK: - Public Properties //-------------------------------------------------- public override var selectorViews: [RadioButton] { + willSet { + mainStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } + } + didSet { for selector in selectorViews { - if !mainStackView.arrangedSubviews.contains(selector) { - selector.onClick = { [weak self] handler in - self?.didSelect(handler) + selector.onClick = { [weak self] handler in + self?.didSelect(handler) + } + mainStackView.addArrangedSubview(selector) + } + } + } + + public var selectorModels: [RadioButtonModel]? { + didSet { + if let selectorModels { + selectorViews = selectorModels.map { model in + return RadioButton().with { + $0.disabled = model.disabled + $0.surface = model.surface + $0.inputId = model.inputId + $0.value = model.value + $0.accessibilityLabel = model.accessibileText + $0.labelText = model.labelText + $0.labelTextAttributes = model.labelTextAttributes + $0.childText = model.childText + $0.childTextAttributes = model.childTextAttributes + $0.isSelected = model.selected + $0.errorText = model.errorText + $0.showError = model.showError } - mainStackView.addArrangedSubview(selector) } } } @@ -122,23 +147,4 @@ extension RadioButtonGroup { self.init(disabled: false) } } - - public func setSelectorViewModels(models: [RadioButtonModel]) { - selectorViews = models.map { model in - return RadioButton().with { - $0.disabled = model.disabled - $0.surface = model.surface - $0.inputId = model.inputId - $0.value = model.value - $0.accessibilityLabel = model.accessibileText - $0.labelText = model.labelText - $0.labelTextAttributes = model.labelTextAttributes - $0.childText = model.childText - $0.childTextAttributes = model.childTextAttributes - $0.isSelected = model.selected - $0.errorText = model.errorText - $0.showError = model.showError - } - } - } } diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index c6362f33..0a5b15da 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -20,6 +20,28 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo collectionView.reloadData() } } + + public var selectorModels: [RadioSwatchModel]? { + didSet { + if let selectorModels { + selectorViews = selectorModels.map { model in + return RadioSwatch().with { + $0.accessibilityLabel = model.accessibileText + $0.text = model.text + $0.fillImage = model.fillImage + $0.primaryColor = model.primaryColor + $0.secondaryColor = model.secondaryColor + $0.strikethrough = model.strikethrough + $0.disabled = model.disabled + $0.surface = model.surface + $0.inputId = model.inputId + $0.value = model.value + $0.isSelected = model.selected + } + } + } + } + } //-------------------------------------------------- // MARK: - Private Properties @@ -200,23 +222,5 @@ extension RadioSwatchGroup { self.init(disabled: false) } } - - public func setSelectorViewModels(models: [RadioSwatchModel]) { - selectorViews = models.map { model in - return RadioSwatch().with { - $0.accessibilityLabel = model.accessibileText - $0.text = model.text - $0.fillImage = model.fillImage - $0.primaryColor = model.primaryColor - $0.secondaryColor = model.secondaryColor - $0.strikethrough = model.strikethrough - $0.disabled = model.disabled - $0.surface = model.surface - $0.inputId = model.inputId - $0.value = model.value - $0.isSelected = model.selected - } - } - } }