135 lines
4.2 KiB
Swift
135 lines
4.2 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<RadioBoxGroup>{
|
|
|
|
var disabledSwitch = Toggle()
|
|
var strikeThroughSwitch = Toggle()
|
|
var textField = TextField()
|
|
var subTextField = TextField()
|
|
var subTextRightField = 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: "Strikethrough", view: strikeThroughSwitch)
|
|
addFormRow(label: "Text", view: textField)
|
|
addFormRow(label: "Sub Text", view: subTextField)
|
|
addFormRow(label: "Sub Text Right", view: subTextRightField)
|
|
|
|
disabledSwitch.onChange = { [weak self] sender in
|
|
self?.component.isEnabled = !sender.isOn
|
|
}
|
|
|
|
strikeThroughSwitch.onChange = { [weak self] sender in
|
|
self?.radioBox?.strikethrough = sender.isOn
|
|
}
|
|
|
|
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 = RadioBoxGroup.RadioBoxItemModel()
|
|
radioBox1.inputId = "model1"
|
|
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 = RadioBoxGroup.RadioBoxItemModel()
|
|
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"
|
|
|
|
component.selectorModels = [radioBox1, radioBox2]
|
|
|
|
component.onChange = { [weak self] group in
|
|
let newText = "Selected:\r\(group.selectedItem?.text ?? "none")"
|
|
self?.actionLabel.text = newText
|
|
}
|
|
|
|
//set UI values
|
|
surfacePickerSelectorView.text = component.surface.rawValue
|
|
disabledSwitch.isOn = !component.isEnabled
|
|
textField.text = radioBox1.text
|
|
subTextField.text = radioBox1.subText
|
|
subTextRightField.text = radioBox1.subTextRight
|
|
}
|
|
|
|
var radioBox: RadioBoxItem? {
|
|
component.items.first
|
|
}
|
|
|
|
//Picker
|
|
func setupPicker(){
|
|
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.component.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
extension RadioBoxGroupViewController: ComponentSampleable {
|
|
static func makeSample() -> ComponentSample {
|
|
let component = Self.makeComponent()
|
|
|
|
var radioBox1 = RadioBoxGroup.RadioBoxItemModel()
|
|
radioBox1.inputId = "model1"
|
|
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 = RadioBoxGroup.RadioBoxItemModel()
|
|
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"
|
|
|
|
component.selectorModels = [radioBox1, radioBox2]
|
|
|
|
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual)
|
|
}
|
|
}
|