diff --git a/VDSSample/ViewControllers/TileContainerViewController.swift b/VDSSample/ViewControllers/TileContainerViewController.swift index e59486f..013dc4e 100644 --- a/VDSSample/ViewControllers/TileContainerViewController.swift +++ b/VDSSample/ViewControllers/TileContainerViewController.swift @@ -9,6 +9,7 @@ import Foundation import UIKit import VDS import VDSColorTokens +import Combine class TileContainerViewController: BaseViewController { @@ -34,6 +35,9 @@ class TileContainerViewController: BaseViewController { items: TileContainer.ContainerScalingType.allCases) }() + var clickableSwitch = Toggle() + var clickableCancel: AnyCancellable? + var showBackgroundImageSwitch = Toggle() var showBorderSwitch = Toggle() var showDropShadowSwitch = Toggle() @@ -46,20 +50,20 @@ class TileContainerViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() addContentTopView(view: .makeWrapper(for: tileContainer)) - + tileContainer.width = 150 setupForm() setupPicker() setupModel() } override func allTextFields() -> [TextField]? { [widthTextField, heightTextField] } - func setupForm(){ formStackView.addArrangedSubview(Label().with{ $0.typograpicalStyle = .BoldBodyLarge $0.text = "This object does NOT reflect normal \"surface\" changes, all properties are maually set" }) addFormRow(label: "Surface", view: surfacePickerSelectorView) + addFormRow(label: "Clickable", view: .makeWrapper(for: clickableSwitch)) addFormRow(label: "Width", view: widthTextField) addFormRow(label: "Height", view: heightTextField) addFormRow(label: "Show Border", view: showBorderSwitch) @@ -67,9 +71,24 @@ class TileContainerViewController: BaseViewController { addFormRow(label: "Background Color", view: backgroundColorPickerSelectorView) addFormRow(label: "Padding", view: paddingPickerSelectorView) addFormRow(label: "Aspect Ratio", view: scalingTypePickerSelectorView) - addFormRow(label: "Background Image", view: showBackgroundImageSwitch) + addFormRow(label: "Background Image", view: .makeWrapper(for: showBackgroundImageSwitch)) addFormRow(label: "Image Fallback Color", view: imageFallbackColorPickerSelectorView) + clickableSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + if sender.isOn { + self?.clickableCancel = self?.tileContainer + .publisher(for: .touchUpInside) + .sink(receiveValue: { _ in + print("you click on me!") + }) + } else { + self?.clickableCancel?.cancel() + self?.clickableCancel = nil + } + }.store(in: &subscribers) + showBackgroundImageSwitch .publisher(for: .valueChanged) .sink { [weak self] sender in @@ -117,7 +136,7 @@ class TileContainerViewController: BaseViewController { surfacePickerSelectorView.text = tileContainer.surface.rawValue paddingPickerSelectorView.text = tileContainer.containerPadding.rawValue scalingTypePickerSelectorView.text = tileContainer.aspectRatio.rawValue - widthTextField.text = "\(tileContainer.width)" + widthTextField.text = tileContainer.width != nil ? "\(tileContainer.width!)" : "" heightTextField.text = tileContainer.height != nil ? "\(tileContainer.height!)" : "" } diff --git a/VDSSample/ViewControllers/TiletViewController.swift b/VDSSample/ViewControllers/TiletViewController.swift index 7b58fea..57b5621 100644 --- a/VDSSample/ViewControllers/TiletViewController.swift +++ b/VDSSample/ViewControllers/TiletViewController.swift @@ -9,6 +9,7 @@ import Foundation import UIKit import VDS import VDSColorTokens +import Combine class TiletViewController: BaseViewController { @@ -30,6 +31,9 @@ class TiletViewController: BaseViewController { items: [.primary, .secondary]) }() + var clickableSwitch = Toggle() + var clickableCancel: AnyCancellable? + var titleTextField = TextField() var subTitleTextField = TextField() var widthTextField = NumericField() @@ -55,7 +59,8 @@ class TiletViewController: BaseViewController { func setupForm(){ addFormRow(label: "Surface", view: surfacePickerSelectorView) - + addFormRow(label: "Clickable", view: .makeWrapper(for: clickableSwitch)) + addFormRow(label: "Title Style", view: titleTextStylePickerSelectorView) addFormRow(label: "Other Style", view: otherTextStylePickerSelectorView) @@ -67,9 +72,23 @@ class TiletViewController: BaseViewController { addFormRow(label: "Text Width", view: textWidthTextField) addFormRow(label: "Text Percentage", view: badgeTextField) addFormRow(label: "Badge Text", view: badgeTextField) - addFormRow(label: "Description Icon", view: showDescriptionIconSwitch) - addFormRow(label: "Directional Icon", view: showDirectionalIconSwitch) + addFormRow(label: "Description Icon", view: .makeWrapper(for: showDescriptionIconSwitch)) + addFormRow(label: "Directional Icon", view: .makeWrapper(for: showDirectionalIconSwitch)) + clickableSwitch + .publisher(for: .valueChanged) + .sink { [weak self] sender in + if sender.isOn { + self?.clickableCancel = self?.tilet + .publisher(for: .touchUpInside) + .sink(receiveValue: { _ in + print("you click on me!") + }) + } else { + self?.clickableCancel?.cancel() + self?.clickableCancel = nil + } + }.store(in: &subscribers) widthTextField .textPublisher @@ -93,7 +112,7 @@ class TiletViewController: BaseViewController { .textPublisher .sink { [weak self] text in guard let self else { return } - if let n = NumberFormatter().number(from: text), n.floatValue > 50.0 && n.floatValue <= Float(self.tilet.width) { + if let n = NumberFormatter().number(from: text), n.floatValue > 50.0 { self.tilet.textWidth = CGFloat(truncating: n) self.textPercentageTextField.text = "" } else { @@ -159,7 +178,6 @@ class TiletViewController: BaseViewController { let subTitleModel = TiletSubTitleModel(text: "Enroll in Auto Pay & paper-free billing to save on your monthly bill.") tilet.surface = .light - tilet.width = 312 tilet.titleModel = titleModel tilet.subTitleModel = subTitleModel @@ -170,7 +188,7 @@ class TiletViewController: BaseViewController { subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue titleTextField.text = titleModel.text subTitleTextField.text = subTitleModel.text - widthTextField.text = "\(tilet.width)" + widthTextField.text = tilet.width != nil ? "\(tilet.width!)" : "" } //sub models