vds_ios_sample/VDSSample/ViewControllers/CheckBoxGroupViewController.swift
Matt Bruce 0c0fb2ef44 removed stuff with model
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-10-20 15:42:04 -05:00

111 lines
3.3 KiB
Swift

//
// CheckBoxGroup2ViewController.swift
// VDSSample
//
// Created by Matt Bruce on 8/24/22.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
import Combine
class CheckboxGroupViewController: BaseViewController {
var disabledSwitch = UISwitch()
var labelTextField = TextField()
var childTextField = TextField()
var showErrorSwitch = UISwitch()
var checkboxGroup = CheckboxGroup()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: checkboxGroup)
setupForm()
setupPicker()
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?.checkboxGroup.showError = sender.isOn
}.store(in: &subscribers)
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.checkboxGroup.disabled = sender.isOn
}.store(in: &subscribers)
labelTextField
.textPublisher
.sink { [weak self] text in
self?.checkbox?.labelText = text
}.store(in: &subscribers)
childTextField
.textPublisher
.sink { [weak self] text in
self?.checkbox?.childText = text
}.store(in: &subscribers)
}
func setupModel() {
var checkbox1 = Checkbox()
checkbox1.inputId = "model1"
checkbox1.value = "model 1 Value"
checkbox1.labelText = "iPhone 11 Bundle 1"
checkbox1.childText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
var checkbox2 = Checkbox()
checkbox2.inputId = "model2"
checkbox2.value = "model 2 Value"
checkbox2.labelText = "iPhone 11 Bundle 2"
checkbox2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
checkboxGroup.selectorViews = [checkbox1, checkbox2]
checkboxGroup
.publisher(for: .valueChanged)
.sink { group in
let selected = group.selectedHandlers?
.compactMap{$0.labelText}
.joined(separator: ", ") ?? "none"
print("Selected: \(selected)")
}.store(in: &subscribers)
//setup UI
surfacePickerSelectorView.text = checkboxGroup.surface.rawValue
disabledSwitch.isOn = checkboxGroup.disabled
labelTextField.text = checkbox1.labelText
childTextField.text = checkbox1.childText
showErrorSwitch.isOn = checkboxGroup.showError
}
var checkbox: Checkbox? {
checkboxGroup.selectorViews.first
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.checkboxGroup.surface = item
self?.contentTopView.backgroundColor = item.color
}
}
}