// // RadioButtonViewController.swift // VDSSample // // Created by Matt Bruce on 7/18/23. // import Foundation import UIKit import VDS import VDSColorTokens import Combine class RadioButtonViewController: BaseViewController { var disabledSwitch = Toggle() var showErrorSwitch = Toggle() let toggle = UISwitch() override func viewDidLoad() { super.viewDidLoad() addContentTopView(view: .makeWrapper(for: component, edgeSpacing: 16.0), edgeSpacing: 0.0) setupPicker() setupModel() } override func setupForm(){ super.setupForm() addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch)) 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 } } func setupModel() { component.onChange = { [weak self] item in let alertController:UIAlertController = UIAlertController(title: "Alert", message: "RadioButton: \(item.isSelected)", preferredStyle: UIAlertController.Style.alert) alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) self?.present(alertController, animated: true) self?.showErrorSwitch.isOn = item.showError } //setup UI surfacePickerSelectorView.text = component.surface.rawValue disabledSwitch.isOn = component.disabled showErrorSwitch.isOn = component.showError } //Picker func setupPicker(){ surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.surface = item self?.contentTopView.backgroundColor = item.color } } }