refactored radiobutton
This commit is contained in:
parent
ae4a63bfcc
commit
4390c29c08
@ -42,12 +42,6 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
|||||||
addFormRow(label: "Child Text", view: childTextField)
|
addFormRow(label: "Child Text", view: childTextField)
|
||||||
addFormRow(label: "Error", view: showErrorSwitch)
|
addFormRow(label: "Error", view: showErrorSwitch)
|
||||||
|
|
||||||
checkboxGroup
|
|
||||||
.handlerPublisher()
|
|
||||||
.sink { [weak self] viewModel in
|
|
||||||
self?.model = viewModel
|
|
||||||
}.store(in: &subscribers)
|
|
||||||
|
|
||||||
showErrorSwitch
|
showErrorSwitch
|
||||||
.publisher(for: .valueChanged)
|
.publisher(for: .valueChanged)
|
||||||
.sink { [weak self] sender in
|
.sink { [weak self] sender in
|
||||||
@ -93,6 +87,12 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
|||||||
defaultModel.selectors = [model1, model2]
|
defaultModel.selectors = [model1, model2]
|
||||||
set(with: defaultModel)
|
set(with: defaultModel)
|
||||||
|
|
||||||
|
checkboxGroup
|
||||||
|
.handlerPublisher()
|
||||||
|
.sink { [weak self] viewModel in
|
||||||
|
self?.model = viewModel
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//setup UI
|
//setup UI
|
||||||
surfacePickerSelectorView.text = model.surface.rawValue
|
surfacePickerSelectorView.text = model.surface.rawValue
|
||||||
disabledSwitch.isOn = model.disabled
|
disabledSwitch.isOn = model.disabled
|
||||||
|
|||||||
@ -11,9 +11,6 @@ import VDS
|
|||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
|
|
||||||
class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
|
class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
|
||||||
deinit {
|
|
||||||
print("\(Self.self) deinit")
|
|
||||||
}
|
|
||||||
|
|
||||||
enum PickerType {
|
enum PickerType {
|
||||||
case surface, textSize, fontCategory
|
case surface, textSize, fontCategory
|
||||||
|
|||||||
@ -11,148 +11,7 @@ import VDS
|
|||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
//class RadioBoxGroupViewController: ModelViewController<DefaultRadioBoxGroupModel>, StoryboardInitable {
|
|
||||||
// deinit {
|
|
||||||
// print("\(Self.self) deinit")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// enum PickerType {
|
|
||||||
// case surface
|
|
||||||
// }
|
|
||||||
// static var storyboardId: String = "radioBoxGroup"
|
|
||||||
// static var storyboardName: String = "Components"
|
|
||||||
//
|
|
||||||
// @IBOutlet weak var componentContainerView: UIView!
|
|
||||||
// @IBOutlet weak var disabledSwitch: UISwitch!
|
|
||||||
// @IBOutlet weak var picker: UIPickerView!
|
|
||||||
// @IBOutlet weak var surfaceLabel: UILabel!
|
|
||||||
// @IBOutlet weak var textField: UITextField!
|
|
||||||
// @IBOutlet weak var subTextField: UITextField!
|
|
||||||
// @IBOutlet weak var subTextRightField: UITextField!
|
|
||||||
// @IBOutlet weak var showErrorSwitch: UISwitch!
|
|
||||||
//
|
|
||||||
// var radioBoxGroup = RadioBoxGroup()
|
|
||||||
//
|
|
||||||
// override func viewDidLoad() {
|
|
||||||
// super.viewDidLoad()
|
|
||||||
// view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
|
||||||
//
|
|
||||||
// componentContainerView.addSubview(radioBoxGroup)
|
|
||||||
// radioBoxGroup.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
|
|
||||||
// radioBoxGroup.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
|
|
||||||
// radioBoxGroup.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
|
|
||||||
// radioBoxGroup.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
|
|
||||||
// setupPicker()
|
|
||||||
// setupModel()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func setupModel(){
|
|
||||||
// var defaultModel = DefaultRadioBoxGroupModel()
|
|
||||||
// var model1 = DefaultRadioBoxModel()
|
|
||||||
// model1.value = "model 1 Value"
|
|
||||||
// model1.text = "iPhone 11 Bundle 1"
|
|
||||||
// model1.subText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
|
|
||||||
// model1.subTextRight = "Right Text"
|
|
||||||
//
|
|
||||||
// var model2 = DefaultRadioBoxModel()
|
|
||||||
// model2.strikethrough = true
|
|
||||||
// model2.value = "model 2 Value"
|
|
||||||
// model2.text = "iPhone 11 Bundle 2"
|
|
||||||
// model2.subText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
|
||||||
//
|
|
||||||
// defaultModel.selectors = [model1, model2]
|
|
||||||
// set(with: defaultModel)
|
|
||||||
//
|
|
||||||
// //update the model
|
|
||||||
// radioBoxGroup
|
|
||||||
// .handlerPublisher()
|
|
||||||
// .sink { [weak self] updatedModel in
|
|
||||||
// self?.model = updatedModel
|
|
||||||
// self?.showErrorSwitch.isOn = updatedModel.hasError
|
|
||||||
// self?.disabledSwitch.isOn = updatedModel.disabled
|
|
||||||
// }
|
|
||||||
// .store(in: &subscribers)
|
|
||||||
//
|
|
||||||
// //set UI values
|
|
||||||
// surfaceLabel.text = model.surface.rawValue
|
|
||||||
// disabledSwitch.isOn = model.disabled
|
|
||||||
// showErrorSwitch.isOn = model.hasError
|
|
||||||
// textField.text = model1.text
|
|
||||||
// subTextField.text = model1.subText
|
|
||||||
// subTextRightField.text = model1.subTextRight
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override func updateView(viewModel: ModelType) {
|
|
||||||
// print("\(Self.self) updateView(viewModel)")
|
|
||||||
// showErrorSwitch.isOn = viewModel.hasError
|
|
||||||
// disabledSwitch.isOn = viewModel.disabled
|
|
||||||
// radioBoxGroup.set(with: viewModel)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var radioBox: RadioBox? {
|
|
||||||
// radioBoxGroup.selectorViews.first
|
|
||||||
// }
|
|
||||||
// @IBAction func disabledChanged(_ sender: UISwitch) {
|
|
||||||
// radioBoxGroup.disabled = sender.isOn
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @IBAction func onTextDidEnd(_ sender: UITextField) {
|
|
||||||
// radioBox?.text = sender.text ?? "No value entered"
|
|
||||||
// sender.resignFirstResponder()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @IBAction func onSubTextDidEnd(_ sender: UITextField) {
|
|
||||||
// radioBox?.subText = sender.text
|
|
||||||
// sender.resignFirstResponder()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @IBAction func onSubTextRightDidEnd(_ sender: UITextField) {
|
|
||||||
// radioBox?.subTextRight = sender.text
|
|
||||||
// sender.resignFirstResponder()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @IBAction func showErrorChanged(_ sender: UISwitch) {
|
|
||||||
// radioBoxGroup.hasError = sender.isOn
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @IBAction func surfaceClick(_ sender: Any) {
|
|
||||||
// pickerType = .surface
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //Picker
|
|
||||||
// var surfacePicker = SurfacePicker()
|
|
||||||
//
|
|
||||||
// var pickerType: PickerType = .surface {
|
|
||||||
// didSet {
|
|
||||||
// func update(object: UIPickerViewDelegate & UIPickerViewDataSource){
|
|
||||||
// picker.delegate = object
|
|
||||||
// picker.dataSource = object
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// switch pickerType{
|
|
||||||
// case .surface:
|
|
||||||
// update(object: surfacePicker)
|
|
||||||
// }
|
|
||||||
// picker.reloadAllComponents()
|
|
||||||
// picker.selectRow(0, inComponent: 0, animated: false)
|
|
||||||
// picker.isHidden = false
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func setupPicker(){
|
|
||||||
// picker.isHidden = true
|
|
||||||
// surfacePicker.onPickerDidSelect = { [weak self] item in
|
|
||||||
// self?.radioBoxGroup.surface = item
|
|
||||||
// self?.componentContainerView.backgroundColor = item.color
|
|
||||||
// self?.surfaceLabel.text = item.rawValue
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGroupModel> {
|
class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGroupModel> {
|
||||||
deinit {
|
|
||||||
print("\(Self.self) deinit")
|
|
||||||
}
|
|
||||||
|
|
||||||
enum PickerType {
|
enum PickerType {
|
||||||
case surface
|
case surface
|
||||||
|
|||||||
@ -11,41 +11,66 @@ import VDS
|
|||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
class RadioButtonViewController: ModelViewController<DefaultRadioButtonGroupModel>, StoryboardInitable {
|
class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGroupModel> {
|
||||||
deinit {
|
|
||||||
print("\(Self.self) deinit")
|
|
||||||
}
|
|
||||||
|
|
||||||
enum PickerType {
|
enum PickerType {
|
||||||
case surface
|
case surface
|
||||||
}
|
}
|
||||||
static var storyboardId: String = "radioButton"
|
var surfacePickerSelectorView = PickerSelectorView(title: "light")
|
||||||
static var storyboardName: String = "Components"
|
var disabledSwitch = UISwitch()
|
||||||
|
var labelTextField = TextField()
|
||||||
@IBOutlet weak var componentContainerView: UIView!
|
var childTextField = TextField()
|
||||||
@IBOutlet weak var picker: UIPickerView!
|
var showErrorSwitch = UISwitch()
|
||||||
@IBOutlet weak var surfaceLabel: UILabel!
|
|
||||||
|
|
||||||
@IBOutlet weak var disabledSwitch: UISwitch!
|
|
||||||
@IBOutlet weak var labelTextField: UITextField!
|
|
||||||
@IBOutlet weak var childTextField: UITextField!
|
|
||||||
@IBOutlet weak var showErrorSwitch: UISwitch!
|
|
||||||
|
|
||||||
var radioButtonGroup = RadioButtonGroup()
|
var radioButtonGroup = RadioButtonGroup()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
addContentTopView(view: radioButtonGroup)
|
||||||
|
|
||||||
componentContainerView.addSubview(radioButtonGroup)
|
setupForm()
|
||||||
radioButtonGroup.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
|
|
||||||
radioButtonGroup.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
|
|
||||||
radioButtonGroup.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
|
|
||||||
radioButtonGroup.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
|
|
||||||
setupPicker()
|
setupPicker()
|
||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupForm() {
|
||||||
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||||
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
|
addFormRow(label: "Label Text", view: labelTextField)
|
||||||
|
addFormRow(label: "Child Text", view: childTextField)
|
||||||
|
addFormRow(label: "Error", view: showErrorSwitch)
|
||||||
|
|
||||||
|
showErrorSwitch
|
||||||
|
.publisher(for: .valueChanged)
|
||||||
|
.sink { [weak self] sender in
|
||||||
|
self?.radioButtonGroup.hasError = sender.isOn
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
disabledSwitch
|
||||||
|
.publisher(for: .valueChanged)
|
||||||
|
.sink { [weak self] sender in
|
||||||
|
self?.radioButtonGroup.disabled = sender.isOn
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
labelTextField
|
||||||
|
.textPublisher
|
||||||
|
.sink { [weak self] text in
|
||||||
|
self?.radioButton?.labelText = text
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
childTextField
|
||||||
|
.textPublisher
|
||||||
|
.sink { [weak self] text in
|
||||||
|
self?.radioButton?.childText = text
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
surfacePickerSelectorView.button
|
||||||
|
.publisher(for: .touchUpInside)
|
||||||
|
.sink { [weak self] _ in
|
||||||
|
self?.pickerType = .surface
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
}
|
||||||
|
|
||||||
func setupModel(){
|
func setupModel(){
|
||||||
var defaultModel = DefaultRadioButtonGroupModel()
|
var defaultModel = DefaultRadioButtonGroupModel()
|
||||||
var model1 = DefaultRadioButtonModel()
|
var model1 = DefaultRadioButtonModel()
|
||||||
@ -71,7 +96,7 @@ class RadioButtonViewController: ModelViewController<DefaultRadioButtonGroupMod
|
|||||||
.store(in: &subscribers)
|
.store(in: &subscribers)
|
||||||
|
|
||||||
//set UI values
|
//set UI values
|
||||||
surfaceLabel.text = model.surface.rawValue
|
surfacePickerSelectorView.text = model.surface.rawValue
|
||||||
disabledSwitch.isOn = model.disabled
|
disabledSwitch.isOn = model.disabled
|
||||||
showErrorSwitch.isOn = model.hasError
|
showErrorSwitch.isOn = model.hasError
|
||||||
labelTextField.text = model1.labelText
|
labelTextField.text = model1.labelText
|
||||||
@ -88,27 +113,6 @@ class RadioButtonViewController: ModelViewController<DefaultRadioButtonGroupMod
|
|||||||
var radioButton: RadioButton? {
|
var radioButton: RadioButton? {
|
||||||
radioButtonGroup.selectorViews.first
|
radioButtonGroup.selectorViews.first
|
||||||
}
|
}
|
||||||
@IBAction func disabledChanged(_ sender: UISwitch) {
|
|
||||||
radioButtonGroup.disabled = sender.isOn
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func onLabelTextDidEnd(_ sender: UITextField) {
|
|
||||||
radioButton?.labelText = sender.text
|
|
||||||
sender.resignFirstResponder()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func onChildTextDidEnd(_ sender: UITextField) {
|
|
||||||
radioButton?.childText = sender.text
|
|
||||||
sender.resignFirstResponder()
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func showErrorChanged(_ sender: UISwitch) {
|
|
||||||
radioButtonGroup.hasError = sender.isOn
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func surfaceClick(_ sender: Any) {
|
|
||||||
pickerType = .surface
|
|
||||||
}
|
|
||||||
|
|
||||||
//Picker
|
//Picker
|
||||||
var surfacePicker = SurfacePicker()
|
var surfacePicker = SurfacePicker()
|
||||||
@ -134,8 +138,8 @@ class RadioButtonViewController: ModelViewController<DefaultRadioButtonGroupMod
|
|||||||
picker.isHidden = true
|
picker.isHidden = true
|
||||||
surfacePicker.onPickerDidSelect = { [weak self] item in
|
surfacePicker.onPickerDidSelect = { [weak self] item in
|
||||||
self?.radioButtonGroup.surface = item
|
self?.radioButtonGroup.surface = item
|
||||||
self?.componentContainerView.backgroundColor = item.color
|
self?.contentTopView.backgroundColor = item.color
|
||||||
self?.surfaceLabel.text = item.rawValue
|
self?.surfacePickerSelectorView.text = item.rawValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user