diff --git a/VDSSample/Classes/Helper.swift b/VDSSample/Classes/Helper.swift index ae446bd..de7b63a 100644 --- a/VDSSample/Classes/Helper.swift +++ b/VDSSample/Classes/Helper.swift @@ -24,21 +24,20 @@ extension UIView { } } -extension ButtonBase { +extension Clickable where Self: ButtonBase { func labelPublisher(_ label: UILabel){ - onClickSubscriber = publisher(for: .touchUpInside) - .sink { control in - let newText = "\(control.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" - } - print("clicked me") + onClick = { control in + let newText = "\(control.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" } + print("clicked me") + } } } diff --git a/VDSSample/Protocols/PickerBase.swift b/VDSSample/Protocols/PickerBase.swift index a674209..d589d37 100644 --- a/VDSSample/Protocols/PickerBase.swift +++ b/VDSSample/Protocols/PickerBase.swift @@ -74,16 +74,14 @@ public class PickerSelectorView: UIStackView, Picker updateSelectedIndex() addArrangedSubview(label) addArrangedSubview(button) - button - .publisher(for: .touchUpInside) - .sink { [weak self] _ in - self?.picker?.delegate = self - self?.picker?.dataSource = self - self?.picker?.reloadAllComponents() - self?.picker?.selectRow(self?.selectedIndex ?? 0, inComponent: 0, animated: false) - self?.picker?.isHidden = false - self?.scrollToBottom?() - }.store(in: &subscribers) + button.onClick = { [weak self] _ in + self?.picker?.delegate = self + self?.picker?.dataSource = self + self?.picker?.reloadAllComponents() + self?.picker?.selectRow(self?.selectedIndex ?? 0, inComponent: 0, animated: false) + self?.picker?.isHidden = false + self?.scrollToBottom?() + } } func updateSelectedIndex() { diff --git a/VDSSample/ViewControllers/CheckboxViewController.swift b/VDSSample/ViewControllers/CheckboxViewController.swift index 3682077..3325694 100644 --- a/VDSSample/ViewControllers/CheckboxViewController.swift +++ b/VDSSample/ViewControllers/CheckboxViewController.swift @@ -19,7 +19,7 @@ class CheckboxViewController: BaseViewController { var errorTextField = TextField() var showErrorSwitch = Toggle() - var checkbox = SoloCheckbox() + var checkbox = Checkbox() override func viewDidLoad() { super.viewDidLoad() diff --git a/VDSSample/ViewControllers/TileContainerViewController.swift b/VDSSample/ViewControllers/TileContainerViewController.swift index 7f249c0..d9d72fd 100644 --- a/VDSSample/ViewControllers/TileContainerViewController.swift +++ b/VDSSample/ViewControllers/TileContainerViewController.swift @@ -36,7 +36,6 @@ class TileContainerViewController: BaseViewController { }() var clickableSwitch = Toggle() - var clickableCancel: AnyCancellable? var showBackgroundImageSwitch = Toggle() var showBorderSwitch = Toggle() @@ -78,15 +77,13 @@ class TileContainerViewController: BaseViewController { clickableSwitch .publisher(for: .valueChanged) .sink { [weak self] sender in + guard let self else { return } if sender.isOn { - self?.clickableCancel = self?.tileContainer - .publisher(for: .touchUpInside) - .sink(receiveValue: { _ in - print("you click on me!") - }) + self.tileContainer.onClick = { _ in + print("you click on me!") + } } else { - self?.clickableCancel?.cancel() - self?.clickableCancel = nil + self.tileContainer.onClick = nil } }.store(in: &subscribers) diff --git a/VDSSample/ViewControllers/TileletViewController.swift b/VDSSample/ViewControllers/TileletViewController.swift index 23533b8..d3e5ed5 100644 --- a/VDSSample/ViewControllers/TileletViewController.swift +++ b/VDSSample/ViewControllers/TileletViewController.swift @@ -79,13 +79,13 @@ class TileletViewController: BaseViewController { .sink { [weak self] sender in guard let tilelet = self?.tilelet else { return } if sender.isOn { - tilelet.onClickSubscriber = tilelet.publisher(for: .touchUpInside) - .sink(receiveValue: { _ in - print("you click on me!") - }) + tilelet.onClick = { t in + print("you click on me!") + } + } else { + tilelet.onClick = nil } }.store(in: &subscribers) - widthTextField .textPublisher .sink { [weak self] text in