vds_ios_sample/VDSSample/ViewControllers/RadioSwatchGroupViewController.swift
Matt Bruce 8d6c744ae4 convert forms to use Toggle/Button instead of native
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-11-18 14:44:50 -06:00

112 lines
3.5 KiB
Swift

//
// RadioSwatchGroupViewController.swift
// VDSSample
//
// Created by Matt Bruce on 8/30/22.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
import Combine
class RadioSwatchGroupViewController: BaseViewController {
var disabledSwitch = Toggle()
var strikeThroughSwitch = Toggle()
var radioSwatchGroup = RadioSwatchGroup()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: radioSwatchGroup)
setupForm()
setupPicker()
setupModel()
}
func setupForm() {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Strikethrough", view: .makeWrapper(for: strikeThroughSwitch))
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioSwatchGroup.disabled = sender.isOn
}.store(in: &subscribers)
strikeThroughSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioSwatchGroup.selectorViews.first?.strikethrough = sender.isOn
}.store(in: &subscribers)
}
func setupModel(){
let radioSwatch1 = RadioSwatch()
radioSwatch1.fillImage = UIImage(named: "imageSwatch")
radioSwatch1.text = "Image"
radioSwatch1.inputId = "radioSwatch1"
let radioSwatch2 = RadioSwatch()
radioSwatch2.primaryColor = .red
radioSwatch2.secondaryColor = .blue
radioSwatch2.text = "Red/Blue"
radioSwatch2.inputId = "radioSwatch2"
let radioSwatch3 = RadioSwatch()
radioSwatch3.primaryColor = .green
radioSwatch3.text = "Green"
radioSwatch3.inputId = "radioSwatch3"
let radioSwatch4 = RadioSwatch()
radioSwatch4.primaryColor = .orange
radioSwatch4.text = "Orange"
radioSwatch4.inputId = "radioSwatch4"
let radioSwatch5 = RadioSwatch()
radioSwatch5.primaryColor = .brown
radioSwatch5.text = "Brown"
radioSwatch5.inputId = "radioSwatch5"
let radioSwatch6 = RadioSwatch()
radioSwatch6.primaryColor = .yellow
radioSwatch6.text = "Yellow"
radioSwatch6.inputId = "radioSwatch6"
let radioSwatch7 = RadioSwatch()
radioSwatch7.primaryColor = .purple
radioSwatch7.text = "Puple"
radioSwatch7.inputId = "radioSwatch7"
let radioSwatch8 = RadioSwatch()
radioSwatch8.primaryColor = .systemPink
radioSwatch8.text = "Pink"
radioSwatch8.inputId = "radioSwatch8"
radioSwatchGroup.selectorViews = [radioSwatch1, radioSwatch2, radioSwatch3, radioSwatch4, radioSwatch5, radioSwatch6, radioSwatch7, radioSwatch8]
radioSwatchGroup
.publisher(for: .valueChanged)
.sink { group in
print("Selected: \(group.selectedHandler?.text ?? "none")")
}.store(in: &subscribers)
//set UI values
surfacePickerSelectorView.text = radioSwatchGroup.surface.rawValue
disabledSwitch.isOn = radioSwatchGroup.disabled
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.radioSwatchGroup.surface = item
self?.contentTopView.backgroundColor = item.color
}
}
}