vds_ios_sample/VDSSample/ViewControllers/RadioButtonViewController.swift
Matt Bruce d8a8caa957 converted to use isEnabled
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-08-25 15:07:54 -05:00

75 lines
2.2 KiB
Swift

//
// RadioButtonViewController.swift
// VDSSample
//
// Created by Matt Bruce on 7/18/23.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
import Combine
class RadioButtonViewController: BaseViewController<RadioButton> {
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()
addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Error", view: 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.isEnabled = !sender.isOn
}
}
func setupModel() {
component.onChange = { [weak self] item in
let newText = "Radiobutton: \(item.isSelected)"
self?.showErrorSwitch.isOn = item.showError
self?.actionLabel.text = newText
}
//setup UI
surfacePickerSelectorView.text = component.surface.rawValue
disabledSwitch.isOn = !component.isEnabled
showErrorSwitch.isOn = component.showError
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.surface = item
self?.contentTopView.backgroundColor = item.color
}
}
}
extension RadioButtonViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
}
}