115 lines
3.6 KiB
Swift
115 lines
3.6 KiB
Swift
//
|
|
// RadioButtonViewController.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Matt Bruce on 8/1/22.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDS
|
|
import VDSColorTokens
|
|
import Combine
|
|
|
|
class RadioButtonViewController: ModelScrollViewController {
|
|
|
|
var disabledSwitch = UISwitch()
|
|
var labelTextField = TextField()
|
|
var childTextField = TextField()
|
|
var showErrorSwitch = UISwitch()
|
|
|
|
var radioButtonGroup = RadioButtonGroup()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
addContentTopView(view: radioButtonGroup)
|
|
|
|
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?.radioButtonGroup.showError = sender.isOn
|
|
}.store(in: &subscribers)
|
|
|
|
disabledSwitch
|
|
.publisher(for: .valueChanged)
|
|
.sink { [weak self] sender in
|
|
self?.radioButtonGroup.disabled = sender.isOn
|
|
}.store(in: &subscribers)
|
|
|
|
labelTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.radioButton?.labelText = text
|
|
}.store(in: &subscribers)
|
|
|
|
childTextField
|
|
.textPublisher
|
|
.sink { [weak self] text in
|
|
self?.radioButton?.childText = text
|
|
}.store(in: &subscribers)
|
|
|
|
}
|
|
|
|
func setupModel(){
|
|
let radioButton1 = RadioButton()
|
|
radioButton1.inputId = "model1"
|
|
radioButton1.value = "model 1 Value"
|
|
radioButton1.labelText = "iPhone 11 Bundle 1"
|
|
radioButton1.childText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
|
|
|
|
let radioButton2 = RadioButton()
|
|
radioButton2.inputId = "model2"
|
|
radioButton2.value = "model 2 Value"
|
|
radioButton2.labelText = "iPhone 11 Bundle 2"
|
|
radioButton2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
|
|
|
let radioButton3 = RadioButton()
|
|
radioButton3.inputId = "model3"
|
|
radioButton3.value = "model 3 Value"
|
|
radioButton3.labelText = "iPhone 11 Bundle 3"
|
|
radioButton3.childText = "Apple iPhone 11 - 256 GB\nOtterbox Case Black\nScreen Protector"
|
|
|
|
radioButtonGroup.selectorViews = [radioButton1, radioButton2, radioButton3]
|
|
|
|
radioButtonGroup
|
|
.publisher(for: .valueChanged)
|
|
.sink { group in
|
|
print("Selected: \(group.selectedHandler?.labelText ?? "none")")
|
|
}.store(in: &subscribers)
|
|
|
|
//set UI values
|
|
surfacePickerSelectorView.text = radioButtonGroup.surface.rawValue
|
|
disabledSwitch.isOn = radioButtonGroup.disabled
|
|
showErrorSwitch.isOn = radioButtonGroup.showError
|
|
labelTextField.text = radioButton1.labelText
|
|
childTextField.text = radioButton1.childText
|
|
}
|
|
|
|
var radioButton: RadioButton? {
|
|
radioButtonGroup.selectorViews.first
|
|
}
|
|
|
|
//Picker
|
|
func setupPicker(){
|
|
|
|
picker.isHidden = true
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.radioButtonGroup.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
|
|
}
|
|
}
|