// // BadgeViewController.swift // VDSSample // // Created by Matt Bruce on 9/22/22. // import Foundation import UIKit import VDS import VDSTokens import Combine class BadgeViewController: BaseViewController { enum NumberOfLines: String, CaseIterable { case unlimited case one case two case three case four var intValue: Int { switch self { case .unlimited: return 0 case .one: return 1 case .two: return 2 case .three: return 3 case .four: return 4 } } } lazy var fillColorPickerSelectorView = { PickerSelectorView(title: "red", picker: self.picker, items: Badge.FillColor.allCases) }() lazy var numberOfLinesPickerSelectorView = { PickerSelectorView(title: "one", picker: self.picker, items: NumberOfLines.allCases) }() var textField = TextField() var maxWidthTextField = NumericField() override func viewDidLoad() { super.viewDidLoad() addContentTopView(view: .makeWrapper(for: component)) setupPicker() setupModel() } override func setupForm(){ super.setupForm() addFormRow(label: "Fill Color", view: fillColorPickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Text", view: textField) addFormRow(label: "Max Width", view: maxWidthTextField) addFormRow(label: "Number of Lines", view: numberOfLinesPickerSelectorView) textField .textPublisher .sink { [weak self] text in self?.component.text = text }.store(in: &subscribers) maxWidthTextField .numberPublisher .sink { [weak self] number in guard let number else { return } self?.component.maxWidth = number.cgFloatValue }.store(in: &subscribers) } func setupModel() { component.fillColor = .red component.text = "Terms and conditions" component.numberOfLines = 1 //setup UI surfacePickerSelectorView.text = component.surface.rawValue textField.text = component.text } func setupPicker(){ surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.surface = item self?.contentTopView.backgroundColor = item.color } fillColorPickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.fillColor = item } numberOfLinesPickerSelectorView.onPickerDidSelect = { [weak self] item in self?.component.numberOfLines = item.intValue } } } extension BadgeViewController: ComponentSampleable { static func makeSample() -> ComponentSample { let component = Self.makeComponent() component.fillColor = .red component.text = "Terms and conditions" component.maxWidth = 70 component.numberOfLines = 3 return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual) } }