diff --git a/VDSSample/Classes/Helper.swift b/VDSSample/Classes/Helper.swift index cd392ab..dcae0bd 100644 --- a/VDSSample/Classes/Helper.swift +++ b/VDSSample/Classes/Helper.swift @@ -37,6 +37,22 @@ extension UIView { } } +extension Changeable { + func labelPublisher(_ text: String, label: UILabel) { + onChange = { _ in + let newText = "\(text) clicked - " + if let labelText = label.text { + let components = labelText.components(separatedBy: " - ") + let last: String = (components.last ?? "0").trimmingCharacters(in: .whitespaces) + let count = Int(last)! + label.text = "\(newText)\(count+1)" + } else { + label.text = "\(newText)1" + } + } + } +} + extension ButtonBase { func labelPublisher(_ label: UILabel){ onClick = { control in diff --git a/VDSSample/ViewControllers/CheckBoxGroupViewController.swift b/VDSSample/ViewControllers/CheckBoxGroupViewController.swift index 9224816..1a649b3 100644 --- a/VDSSample/ViewControllers/CheckBoxGroupViewController.swift +++ b/VDSSample/ViewControllers/CheckBoxGroupViewController.swift @@ -28,8 +28,10 @@ class CheckboxGroupViewController: BaseViewController { setupModel() } - override func setupForm() { + var actionLabel = Label() + override func setupForm(){ super.setupForm() + addFormRow(label: "Action", view: actionLabel) addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Label Text", view: labelTextField) @@ -55,6 +57,25 @@ class CheckboxGroupViewController: BaseViewController { .sink { [weak self] text in self?.checkbox?.childText = text }.store(in: &subscribers) + + component.onChange = { [weak self] group in + guard let label = self?.actionLabel else { return } + let selected = group.selectedHandlers? + .compactMap{"\($0.labelText!)"} + .joined(separator: "\r") ?? "none selected" + + let newText = "Selected Checkboxes:\r\(selected) \rclicked - " + if let labelText = label.text { + let components = labelText.components(separatedBy: " - ") + let last: String = (components.last ?? "0").trimmingCharacters(in: .whitespaces) + let count = Int(last)! + label.text = "\(newText)\(count+1)" + } else { + label.text = "\(newText)1" + } + } + + } func setupModel() { @@ -73,18 +94,6 @@ class CheckboxGroupViewController: BaseViewController { checkbox2.errorText = "Please Choose 2" component.selectorModels = [checkbox1, checkbox2] - - component.onChange = { [weak self] group in - let selected = group.selectedHandlers? - .compactMap{"\($0.labelText!)"} - .joined(separator: "\r") ?? "none selected" - - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "Selected Checkboxes:\r\(selected)", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) - } //setup UI surfacePickerSelectorView.text = component.surface.rawValue diff --git a/VDSSample/ViewControllers/CheckboxItemViewController.swift b/VDSSample/ViewControllers/CheckboxItemViewController.swift index b6debe4..6acb10a 100644 --- a/VDSSample/ViewControllers/CheckboxItemViewController.swift +++ b/VDSSample/ViewControllers/CheckboxItemViewController.swift @@ -27,8 +27,10 @@ class CheckboxItemViewController: BaseViewController { setupModel() } + var actionLabel = Label() override func setupForm(){ - super.setupForm() + super.setupForm() + addFormRow(label: "Action", view: actionLabel) addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Label Text", view: labelTextField) @@ -65,23 +67,15 @@ class CheckboxItemViewController: BaseViewController { .sink { [weak self] text in self?.component.errorText = text }.store(in: &subscribers) + + component.labelPublisher("Checkbox", label: actionLabel) } func setupModel() { component.labelText = "Terms and conditions" component.childText = "I agree to Verizon's terms and conditions click here" component.errorText = "Error Text" - - component.onChange = { [weak self] checkbox in - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "\(checkbox.labelText!): \(checkbox.isSelected)", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) - self?.showErrorSwitch.isOn = checkbox.showError - print("checkbox selected: \(checkbox.isSelected)") - } - + //setup UI surfacePickerSelectorView.text = component.surface.rawValue disabledSwitch.isOn = component.disabled diff --git a/VDSSample/ViewControllers/CheckboxViewController.swift b/VDSSample/ViewControllers/CheckboxViewController.swift index 1514327..21b90ec 100644 --- a/VDSSample/ViewControllers/CheckboxViewController.swift +++ b/VDSSample/ViewControllers/CheckboxViewController.swift @@ -22,8 +22,11 @@ class CheckboxViewController: BaseViewController { setupPicker() setupModel() } + + var actionLabel = Label() override func setupForm(){ super.setupForm() + addFormRow(label: "Action", view: actionLabel) addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Error", view: showErrorSwitch) @@ -40,19 +43,10 @@ class CheckboxViewController: BaseViewController { self?.component.disabled = sender.isOn } + component.labelPublisher("Checkbox", label: actionLabel) } - + func setupModel() { - component.onChange = { [weak self] checkbox in - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "Checkbox: \(checkbox.isSelected)", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) - self?.showErrorSwitch.isOn = checkbox.showError - print("checkbox selected: \(checkbox.isSelected)") - } - //setup UI surfacePickerSelectorView.text = component.surface.rawValue disabledSwitch.isOn = component.disabled diff --git a/VDSSample/ViewControllers/RadioButtonGroupViewController.swift b/VDSSample/ViewControllers/RadioButtonGroupViewController.swift index 5437034..3eeaa2f 100644 --- a/VDSSample/ViewControllers/RadioButtonGroupViewController.swift +++ b/VDSSample/ViewControllers/RadioButtonGroupViewController.swift @@ -26,8 +26,10 @@ class RadioButtonGroupViewController: BaseViewController { setupModel() } - override func setupForm() { + var actionLabel = Label() + override func setupForm(){ super.setupForm() + addFormRow(label: "Action", view: actionLabel) addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Label Text", view: labelTextField) @@ -78,13 +80,9 @@ class RadioButtonGroupViewController: BaseViewController { component.selectorModels = [radioButton1, radioButton2, radioButton3] component.onChange = { [weak self] group in - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "Selected:\r\(group.selectedHandler?.labelText ?? "none")", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) - - print("Selected: \(group.selectedHandler?.labelText ?? "none")") + let newText = "Selected:\r\(group.selectedHandler?.labelText ?? "none")" + self?.showErrorSwitch.isOn = group.showError + self?.actionLabel.text = newText } //set UI values diff --git a/VDSSample/ViewControllers/RadioButtonItemViewController.swift b/VDSSample/ViewControllers/RadioButtonItemViewController.swift index 4b70e85..895c69d 100644 --- a/VDSSample/ViewControllers/RadioButtonItemViewController.swift +++ b/VDSSample/ViewControllers/RadioButtonItemViewController.swift @@ -27,8 +27,10 @@ class RadioButtonItemViewController: BaseViewController { setupModel() } + var actionLabel = Label() override func setupForm(){ super.setupForm() + addFormRow(label: "Action", view: actionLabel) addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Label Text", view: labelTextField) @@ -73,13 +75,9 @@ class RadioButtonItemViewController: BaseViewController { component.errorText = "Error Text" component.onChange = { [weak self] item in - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "\(item.labelText!): \(item.isSelected)", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) + let newText = "\(item.labelText!): \(item.isSelected)" self?.showErrorSwitch.isOn = item.showError - print("checkbox selected: \(item.isSelected)") + self?.actionLabel.text = newText } //setup UI diff --git a/VDSSample/ViewControllers/RadioButtonViewController.swift b/VDSSample/ViewControllers/RadioButtonViewController.swift index f42dce1..071a447 100644 --- a/VDSSample/ViewControllers/RadioButtonViewController.swift +++ b/VDSSample/ViewControllers/RadioButtonViewController.swift @@ -22,8 +22,10 @@ class RadioButtonViewController: BaseViewController { setupPicker() setupModel() } + var actionLabel = Label() override func setupForm(){ super.setupForm() + addFormRow(label: "Action", view: actionLabel) addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Error", view: showErrorSwitch) @@ -44,12 +46,9 @@ class RadioButtonViewController: BaseViewController { func setupModel() { component.onChange = { [weak self] item in - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "RadioButton: \(item.isSelected)", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) + let newText = "Radiobutton: \(item.isSelected)" self?.showErrorSwitch.isOn = item.showError + self?.actionLabel.text = newText } //setup UI diff --git a/VDSSample/ViewControllers/TooltipViewController.swift b/VDSSample/ViewControllers/TooltipViewController.swift index e62e5da..0543664 100644 --- a/VDSSample/ViewControllers/TooltipViewController.swift +++ b/VDSSample/ViewControllers/TooltipViewController.swift @@ -73,7 +73,7 @@ class TooltipViewController: BaseViewController { func setupModel() { component.title = "5G Ultra Wideband is available in your area." - component.content = "$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in/promo credit applied over 36 mos.; promo credit ends if eligibility req’s are no longer met; 0% APR. Trade-in conditions apply.$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in. LAST" + component.content = "$799.99 (128 GB only) " //component.contentView = Icon().with { $0.name = .addFolder; $0.size = .medium } //setup UI diff --git a/VDSSample/ViewControllers/TrailingTooltipLabelViewController.swift b/VDSSample/ViewControllers/TrailingTooltipLabelViewController.swift index 41ce50f..0ffec92 100644 --- a/VDSSample/ViewControllers/TrailingTooltipLabelViewController.swift +++ b/VDSSample/ViewControllers/TrailingTooltipLabelViewController.swift @@ -40,7 +40,7 @@ class TrailingTooltipLabelViewController: BaseViewController