refactored to use modelHandler instead direct model change
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
6b16782b6c
commit
421ea78991
@ -10,16 +10,10 @@ import UIKit
|
||||
|
||||
public class CheckboxGroup: CheckboxGroupBase<DefaultCheckboxGroupModel, Checkbox> {
|
||||
public override func didSelect(_ selectedControl: Checkbox) {
|
||||
for (index, control) in selectorViews.enumerated() {
|
||||
//only change the old and new
|
||||
if control == selectedControl {
|
||||
let updated = model.selectors[index].copyWith {
|
||||
$0.selected.toggle()
|
||||
}
|
||||
model.selectors[index] = updated
|
||||
}
|
||||
selectedControl.toggle()
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + Constants.ModelStateDebounce) { [weak self] in
|
||||
self?.sendActions(for: .valueChanged)
|
||||
}
|
||||
sendActions(for: .valueChanged)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,23 +11,12 @@ import UIKit
|
||||
public class RadioBoxGroup: RadioBoxGroupBase<DefaultRadioBoxGroupModel, RadioBox> {
|
||||
|
||||
public override func didSelect(_ selectedControl: RadioBox) {
|
||||
for (index, control) in selectorViews.enumerated() {
|
||||
//only change the old and new
|
||||
if control == selectedControl {
|
||||
let updated = model.selectors[index].copyWith {
|
||||
$0.selected = true
|
||||
}
|
||||
model.selectors[index] = updated
|
||||
|
||||
} else if control.isSelected {
|
||||
let updated = model.selectors[index].copyWith {
|
||||
$0.selected = false
|
||||
}
|
||||
model.selectors[index] = updated
|
||||
|
||||
}
|
||||
let oldSelectedControl = selectorViews.filter { $0.isSelected == true }.first
|
||||
oldSelectedControl?.toggle()
|
||||
selectedControl.toggle()
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + Constants.ModelStateDebounce) { [weak self] in
|
||||
self?.sendActions(for: .valueChanged)
|
||||
}
|
||||
sendActions(for: .valueChanged)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,16 @@ import UIKit
|
||||
import VDSColorTokens
|
||||
import VDSFormControlsTokens
|
||||
|
||||
public class RadioButton: RadioButtonBase<DefaultRadioButtonModel>{ }
|
||||
public class RadioButton: RadioButtonBase<DefaultRadioButtonModel>{
|
||||
//for groups allows "toggle"
|
||||
open override func toggle() {
|
||||
//removed error
|
||||
if hasError && isSelected == false {
|
||||
hasError.toggle()
|
||||
}
|
||||
isSelected.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
public class SoloRadioButton: RadioButtonBase<DefaultRadioButtonModel>{
|
||||
public override func initialSetup() {
|
||||
|
||||
@ -11,26 +11,15 @@ import UIKit
|
||||
public class RadioButtonGroup: RadioButtonGroupBase<DefaultRadioButtonGroupModel, RadioButton> {
|
||||
|
||||
public override func didSelect(_ selectedControl: RadioButton) {
|
||||
for (index, control) in selectorViews.enumerated() {
|
||||
//only change the old and new
|
||||
if control == selectedControl {
|
||||
let updated = model.selectors[index].copyWith {
|
||||
$0.selected = true
|
||||
}
|
||||
model.selectors[index] = updated
|
||||
if hasError {
|
||||
hasError = false
|
||||
}
|
||||
|
||||
} else if control.isSelected {
|
||||
let updated = model.selectors[index].copyWith {
|
||||
$0.selected = false
|
||||
}
|
||||
model.selectors[index] = updated
|
||||
|
||||
}
|
||||
let oldSelectedControl = selectorViews.filter { $0.isSelected == true }.first
|
||||
oldSelectedControl?.toggle()
|
||||
selectedControl.toggle()
|
||||
if hasError {
|
||||
hasError = false
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + Constants.ModelStateDebounce) { [weak self] in
|
||||
self?.sendActions(for: .valueChanged)
|
||||
}
|
||||
sendActions(for: .valueChanged)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user