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 {
func labelPublisher(_ text: String, label: UILabel) {
func onChangeActionPublisher(_ 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"
}
}
let handler = labelPublisherCompletionHandler()
handler(text, label)
}
}
}
extension Clickable {
func onClickActionPublisher(_ text: String, label: UILabel) {
onClick = { _ in
let handler = labelPublisherCompletionHandler()
handler(text, label)
}
}
}
extension ButtonBase {
func labelPublisher(_ label: UILabel){
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")
let handler = labelPublisherCompletionHandler()
handler(control.text!, label)
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ class ToggleViewController: BaseViewController<Toggle> {
override func setupForm() {
super.setupForm()
addActionRow()
addFormRow(label: "Show Text", view: showTextSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Disabled", view: disabledSwitch)
@ -59,12 +59,7 @@ class ToggleViewController: BaseViewController<Toggle> {
append(section: textFormStackView)
component.onChange = { [weak self] toggle in
let alertController:UIAlertController = UIAlertController(title: "Alert",
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)")
self?.actionLabel.text = "Toggle Value: \(toggle.isOn)"
}
showTextSwitch.onChange = { [weak self] sender in