vds_ios_sample/VDSSample/ViewControllers/RadioBoxGroupViewController.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

119 lines
3.5 KiB
Swift

//
// RadioBoxGroupViewController.swift
// VDSSample
//
// Created by Matt Bruce on 8/23/22.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
import Combine
class RadioBoxGroupViewController: BaseViewController {
var disabledSwitch = UISwitch()
var strikeThroughSwitch = UISwitch()
var textField = TextField()
var subTextField = TextField()
var subTextRightField = TextField()
var showErrorSwitch = UISwitch()
var radioBoxGroup = RadioBoxGroup()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: radioBoxGroup)
setupForm()
setupPicker()
setupModel()
}
func setupForm() {
addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Strikethrough", view: strikeThroughSwitch)
addFormRow(label: "Text", view: textField)
addFormRow(label: "Sub Text", view: subTextField)
addFormRow(label: "Sub Text Right", view: subTextRightField)
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioBoxGroup.disabled = sender.isOn
}.store(in: &subscribers)
strikeThroughSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioBox?.strikethrough = sender.isOn
}.store(in: &subscribers)
textField
.textPublisher
.sink { [weak self] text in
self?.radioBox?.text = text
}.store(in: &subscribers)
subTextField
.textPublisher
.sink { [weak self] text in
self?.radioBox?.subText = text
}.store(in: &subscribers)
subTextRightField
.textPublisher
.sink { [weak self] text in
self?.radioBox?.subTextRight = text
}.store(in: &subscribers)
}
func setupModel(){
var radioBox1 = RadioBox()
radioBox1.inputId = "model1"
radioBox1.isSelected = true
radioBox1.value = "model 1 Value"
radioBox1.text = "iPhone 11 Bundle 1"
radioBox1.subText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
radioBox1.subTextRight = "Right Text"
var radioBox2 = RadioBox()
radioBox2.inputId = "model2"
radioBox2.value = "model 2 Value"
radioBox2.text = "iPhone 11 Bundle 2"
radioBox2.subText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
radioBoxGroup.selectorViews = [radioBox1, radioBox2]
radioBoxGroup
.publisher(for: .valueChanged)
.sink { group in
print("Selected: \(group.selectedHandler?.text ?? "none")")
}.store(in: &subscribers)
//set UI values
surfacePickerSelectorView.text = radioBoxGroup.surface.rawValue
disabledSwitch.isOn = radioBoxGroup.disabled
textField.text = radioBox1.text
subTextField.text = radioBox1.subText
subTextRightField.text = radioBox1.subTextRight
}
var radioBox: RadioBox? {
radioBoxGroup.selectorViews.first
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.radioBoxGroup.surface = item
self?.contentTopView.backgroundColor = item.color
}
}
}