vds_ios_sample/VDSSample/ViewControllers/RadioButtonItemViewController.swift
Matt Bruce 20689203c8 added component sample
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-08-14 11:26:36 -05:00

111 lines
3.4 KiB
Swift

//
// RadioButtonItemViewController.swift
// VDSSample
//
// Created by Matt Bruce on 7/18/23.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
import Combine
class RadioButtonItemViewController: BaseViewController<RadioButtonItem> {
var disabledSwitch = Toggle()
var labelTextField = TextField()
var childTextField = TextField()
var errorTextField = TextField()
var showErrorSwitch = Toggle()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: component)
setupPicker()
setupModel()
}
override func setupForm(){
super.setupForm()
addActionRow()
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)
addFormRow(label: "Error Text", view: errorTextField)
showErrorSwitch.onChange = { [weak self] sender in
guard let self else { return }
self.component.showError = sender.isOn
if self.component.showError != sender.isOn {
self.showErrorSwitch.isOn = self.component.showError
}
}
disabledSwitch.onChange = { [weak self] sender in
self?.component.disabled = sender.isOn
}
labelTextField
.textPublisher
.sink { [weak self] text in
self?.component.labelText = text
}.store(in: &subscribers)
childTextField
.textPublisher
.sink { [weak self] text in
self?.component.childText = text
}.store(in: &subscribers)
errorTextField
.textPublisher
.sink { [weak self] text in
self?.component.errorText = text
}.store(in: &subscribers)
}
func setupModel() {
component.labelText = "Terms and conditions"
component.childText = "I agree to Verizon's terms and conditions click here"
component.errorText = "Error Text"
component.onChange = { [weak self] item in
let newText = "\(item.labelText!): \(item.isSelected)"
self?.showErrorSwitch.isOn = item.showError
self?.actionLabel.text = newText
}
//setup UI
surfacePickerSelectorView.text = component.surface.rawValue
disabledSwitch.isOn = component.disabled
labelTextField.text = component.labelText
childTextField.text = component.childText
showErrorSwitch.isOn = component.showError
errorTextField.text = component.errorText
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.surface = item
self?.contentTopView.backgroundColor = item.color
}
}
}
extension RadioButtonItemViewController: Componentable {
static func getComponent() -> TestViewWrapper {
let component = Self.makeComponent()
component.labelText = "Terms and conditions"
component.childText = "I agree to Verizon's terms and conditions click here"
component.errorText = "Error Text"
return TestViewWrapper(component: component, isTrailing: true)
}
}