added action handlers

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-02 12:00:13 -05:00
parent 93c0be4614
commit 0763df0c3a
12 changed files with 53 additions and 50 deletions

View File

@ -37,35 +37,43 @@ extension UIView {
} }
} }
func labelPublisherCompletionHandler() -> (String, UILabel) -> () {
return { (text, label) 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 Changeable { extension Changeable {
func labelPublisher(_ text: String, label: UILabel) { func onChangeActionPublisher(_ text: String, label: UILabel) {
onChange = { _ in onChange = { _ in
let newText = "\(text) clicked - " let handler = labelPublisherCompletionHandler()
if let labelText = label.text { handler(text, label)
let components = labelText.components(separatedBy: " - ") }
let last: String = (components.last ?? "0").trimmingCharacters(in: .whitespaces) }
let count = Int(last)! }
label.text = "\(newText)\(count+1)"
} else { extension Clickable {
label.text = "\(newText)1" func onClickActionPublisher(_ text: String, label: UILabel) {
} onClick = { _ in
} let handler = labelPublisherCompletionHandler()
handler(text, label)
}
} }
} }
extension ButtonBase { extension ButtonBase {
func labelPublisher(_ label: UILabel){ func labelPublisher(_ label: UILabel){
onClick = { control in onClick = { control in
let newText = "\(control.text!) clicked - " let handler = labelPublisherCompletionHandler()
if let labelText = label.text { handler(control.text!, label)
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")
} }
} }
} }

View File

@ -251,6 +251,13 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
addFormRow(label: "Show Bounds", view: debugViewSwitch) addFormRow(label: "Show Bounds", view: debugViewSwitch)
} }
let actionLabel = Label()
@discardableResult
public func addActionRow() -> UIView {
addFormRow(label: "Action", view: actionLabel)
}
public func scrollToBottom() { public func scrollToBottom() {
let bottomOffset = CGPoint(x: 0, y: bottomScrollView.contentSize.height - bottomScrollView.bounds.height + bottomScrollView.contentInset.bottom) let bottomOffset = CGPoint(x: 0, y: bottomScrollView.contentSize.height - bottomScrollView.bounds.height + bottomScrollView.contentInset.bottom)
bottomScrollView.setContentOffset(bottomOffset, animated: true) bottomScrollView.setContentOffset(bottomOffset, animated: true)

View File

@ -59,7 +59,6 @@ class ButtonGroupViewController: BaseViewController<ButtonGroup> {
items: RowQuantity.allCases) items: RowQuantity.allCases)
}() }()
var label = Label()
var disabledSwitch = Toggle() var disabledSwitch = Toggle()
var widthTextField = NumericField() var widthTextField = NumericField()
var percentageTextField = NumericField() var percentageTextField = NumericField()
@ -76,6 +75,8 @@ class ButtonGroupViewController: BaseViewController<ButtonGroup> {
stackView.axis = .vertical stackView.axis = .vertical
stackView.spacing = 30 stackView.spacing = 30
let label = actionLabel
component.buttons = [ component.buttons = [
makeButton("Secondary", label: label).with{ $0.use = .secondary }, makeButton("Secondary", label: label).with{ $0.use = .secondary },
makeButton("Primary", label: label), makeButton("Primary", label: label),
@ -107,8 +108,8 @@ class ButtonGroupViewController: BaseViewController<ButtonGroup> {
} }
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Action", view: label) addActionRow()
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Position", view: buttonPositionSelectorView) addFormRow(label: "Position", view: buttonPositionSelectorView)

View File

@ -60,6 +60,7 @@ class ButtonIconViewController: BaseViewController<ButtonIcon> {
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Surface Type", view: surfaceTypePickerSelectorView) addFormRow(label: "Surface Type", view: surfaceTypePickerSelectorView)
@ -77,9 +78,7 @@ class ButtonIconViewController: BaseViewController<ButtonIcon> {
self?.component.disabled = sender.isOn self?.component.disabled = sender.isOn
} }
component.onClick = { sender in component.onClickActionPublisher("ButtonIcon", label: actionLabel)
print("Button Icon was clicked")
}
floating.onChange = { [weak self] sender in floating.onChange = { [weak self] sender in
self?.component.floating = sender.isOn self?.component.floating = sender.isOn

View File

@ -28,10 +28,9 @@ class CheckboxGroupViewController: BaseViewController<CheckboxGroup> {
setupModel() setupModel()
} }
var actionLabel = Label()
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Action", view: actionLabel) addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Label Text", view: labelTextField) addFormRow(label: "Label Text", view: labelTextField)

View File

@ -27,10 +27,9 @@ class CheckboxItemViewController: BaseViewController<CheckboxItem> {
setupModel() setupModel()
} }
var actionLabel = Label()
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Action", view: actionLabel) addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Label Text", view: labelTextField) addFormRow(label: "Label Text", view: labelTextField)
@ -68,7 +67,7 @@ class CheckboxItemViewController: BaseViewController<CheckboxItem> {
self?.component.errorText = text self?.component.errorText = text
}.store(in: &subscribers) }.store(in: &subscribers)
component.labelPublisher("Checkbox", label: actionLabel) component.onChangeActionPublisher("Checkbox", label: actionLabel)
} }
func setupModel() { func setupModel() {

View File

@ -23,10 +23,9 @@ class CheckboxViewController: BaseViewController<Checkbox> {
setupModel() setupModel()
} }
var actionLabel = Label()
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Action", view: actionLabel) addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Error", view: showErrorSwitch) addFormRow(label: "Error", view: showErrorSwitch)
@ -43,7 +42,7 @@ class CheckboxViewController: BaseViewController<Checkbox> {
self?.component.disabled = sender.isOn self?.component.disabled = sender.isOn
} }
component.labelPublisher("Checkbox", label: actionLabel) component.onChangeActionPublisher("Checkbox", label: actionLabel)
} }
func setupModel() { func setupModel() {

View File

@ -28,10 +28,9 @@ class RadioBoxGroupViewController: BaseViewController<RadioBoxGroup>{
setupModel() setupModel()
} }
var actionLabel = Label()
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Action", view: actionLabel) addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Strikethrough", view: strikeThroughSwitch) addFormRow(label: "Strikethrough", view: strikeThroughSwitch)

View File

@ -26,10 +26,9 @@ class RadioButtonGroupViewController: BaseViewController<RadioButtonGroup> {
setupModel() setupModel()
} }
var actionLabel = Label()
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Action", view: actionLabel) addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Label Text", view: labelTextField) addFormRow(label: "Label Text", view: labelTextField)

View File

@ -27,10 +27,9 @@ class RadioButtonItemViewController: BaseViewController<RadioButtonItem> {
setupModel() setupModel()
} }
var actionLabel = Label()
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Action", view: actionLabel) addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Label Text", view: labelTextField) addFormRow(label: "Label Text", view: labelTextField)

View File

@ -22,10 +22,9 @@ class RadioButtonViewController: BaseViewController<RadioButton> {
setupPicker() setupPicker()
setupModel() setupModel()
} }
var actionLabel = Label()
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Action", view: actionLabel) addActionRow()
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Error", view: showErrorSwitch) addFormRow(label: "Error", view: showErrorSwitch)

View File

@ -43,7 +43,7 @@ class ToggleViewController: BaseViewController<Toggle> {
override func setupForm() { override func setupForm() {
super.setupForm() super.setupForm()
addActionRow()
addFormRow(label: "Show Text", view: showTextSwitch) addFormRow(label: "Show Text", view: showTextSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Disabled", view: disabledSwitch) addFormRow(label: "Disabled", view: disabledSwitch)
@ -59,12 +59,7 @@ class ToggleViewController: BaseViewController<Toggle> {
append(section: textFormStackView) append(section: textFormStackView)
component.onChange = { [weak self] toggle in component.onChange = { [weak self] toggle in
let alertController:UIAlertController = UIAlertController(title: "Alert", self?.actionLabel.text = "Toggle Value: \(toggle.isOn)"
message: "Toggle Value: \(toggle.isOn)",
preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true)
print("toggle changed: \(toggle.isOn)")
} }
showTextSwitch.onChange = { [weak self] sender in showTextSwitch.onChange = { [weak self] sender in