// // TextLink.swift // VDSSample // // Created by Matt Bruce on 11/1/22. // import Foundation import UIKit import VDS import VDSColorTokens class TextLinkViewController: BaseViewController { lazy var buttonSizePickerSelectorView = { PickerSelectorView(title: "", picker: self.picker, items: ButtonSize.allCases) }() var disabledSwitch = UISwitch() var textField = TextField() let textLink = TextLink() override func viewDidLoad() { super.viewDidLoad() let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false view.addSubview(textLink) textLink.pinTop() textLink.pinBottom() textLink.pinLeading() textLink.trailingAnchor.constraint(lessThanOrEqualTo: view.trailingAnchor).isActive = true addContentTopView(view: view) setupForm() setupPicker() setupModel() } func setupForm(){ addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Label", view: textField) addFormRow(label: "Size", view: buttonSizePickerSelectorView) disabledSwitch .publisher(for: .valueChanged) .sink { [weak self] sender in self?.textLink.disabled = sender.isOn }.store(in: &subscribers) textField .textPublisher .sink { [weak self] text in self?.textLink.text = text }.store(in: &subscribers) } func setupModel() { textLink.text = "Text Link" textLink .publisher(for: .touchUpInside) .sink { [weak self] control in let alertController:UIAlertController = UIAlertController(title: "Alert", message: "\(control.text!) Clicked", preferredStyle: UIAlertController.Style.alert) alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) self?.present(alertController, animated: true) print("clicked me") }.store(in: &subscribers) //setup UI surfacePickerSelectorView.text = textLink.surface.rawValue disabledSwitch.isOn = textLink.disabled textField.text = textLink.text buttonSizePickerSelectorView.text = ButtonSize.large.rawValue } func setupPicker(){ surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.textLink.surface = item self?.contentTopView.backgroundColor = item.color } buttonSizePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.textLink.size = item } } }