// // PriceLockupViewController.swift // VDSSample // // Created by Kanamarlapudi, Vasavi on 06/08/24. // import Foundation import UIKit import VDS class PriceLockupViewController: BaseViewController { lazy var kindPickerSelectorView = { PickerSelectorView(title: "primary", picker: self.picker, items: PriceLockup.Kind.allCases) }() lazy var termPickerSelectorView = { PickerSelectorView(title: "month", picker: self.picker, items: PriceLockup.Term.allCases) }() lazy var sizePickerSelectorView = { PickerSelectorView(title: "medium", picker: self.picker, items: PriceLockup.Size.allCases) }() var boldSwitch = Toggle() var hideCurrencySwitch = Toggle() var strikethroughSwitch = Toggle() var uniformSizeSwitch = Toggle() var priceTextField = NumericField() var leadingTextField = TextField() var termTextField = TextField() var trailingTextField = TextField() var superscriptTextField = TextField() override func viewDidLoad() { super.viewDidLoad() addContentTopView(view: component) setupPicker() setupModel() } override func setupForm() { super.setupForm() addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Bold", view: boldSwitch) addFormRow(label: "Kind", view: kindPickerSelectorView) addFormRow(label: "Size", view: sizePickerSelectorView) addFormRow(label: "Hide Currency", view: hideCurrencySwitch) addFormRow(label: "Price", view: priceTextField) addFormRow(label: "Leading Text", view: leadingTextField) addFormRow(label: "Strikethrough", view: strikethroughSwitch) addFormRow(label: "Uniform Size", view: uniformSizeSwitch) addFormRow(label: "Term", view: termPickerSelectorView) addFormRow(label: "Trailing Text", view: trailingTextField) addFormRow(label: "Superscript", view: superscriptTextField) boldSwitch.publisher(for: .valueChanged).sink { [weak self] control in self?.component.bold = control.isOn }.store(in: &subscribers) hideCurrencySwitch.publisher(for: .valueChanged).sink { [weak self] control in self?.component.hideCurrency = control.isOn }.store(in: &subscribers) strikethroughSwitch.publisher(for: .valueChanged).sink { [weak self] control in self?.component.strikethrough = control.isOn }.store(in: &subscribers) uniformSizeSwitch.publisher(for: .valueChanged).sink { [weak self] control in self?.component.uniformSize = control.isOn }.store(in: &subscribers) priceTextField .numberPublisher .sink { [weak self] number in if let number { self?.component.price = number.floatValue } else { self?.component.price = nil } }.store(in: &subscribers) leadingTextField .textPublisher .sink { [weak self] text in self?.component.leadingText = text }.store(in: &subscribers) trailingTextField .textPublisher .sink { [weak self] text in self?.component.trailingText = text }.store(in: &subscribers) superscriptTextField .textPublisher .sink { [weak self] text in self?.component.superscript = text }.store(in: &subscribers) } func setupModel() { component.price = 24.22 component.superscript = "*" component.leadingText = "Save" component.trailingText = "with Auto Pay" sizePickerSelectorView.text = component.size.rawValue kindPickerSelectorView.text = component.kind.rawValue termPickerSelectorView.text = component.term.rawValue priceTextField.text = "\(component.price!)" leadingTextField.text = component.leadingText trailingTextField.text = component.trailingText superscriptTextField.text = component.superscript } func setupPicker() { surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.surface = item self?.contentTopView.backgroundColor = item.color } kindPickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.kind = item } sizePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.size = item } termPickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.term = item } } }