Merge branch 'feature/Notification' into 'develop'

Adding Notification controller

See merge request BPHV_MIPS/vds_ios_sample!29
This commit is contained in:
Bruce, Matt R 2023-04-04 17:04:02 +00:00
commit 63964b57e8
18 changed files with 270 additions and 312 deletions

View File

@ -56,6 +56,7 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
updateSelectedIndex() updateSelectedIndex()
} }
} }
public var items: [EnumType] { public var items: [EnumType] {
didSet { selectedIndex = 0 } didSet { selectedIndex = 0 }
} }
@ -117,6 +118,13 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
return label return label
} }
public func set(item: EnumType) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.001) { [weak self] in
guard let self else { return }
self.text = "\(item.rawValue)"
}
}
private func title(for row: Int) -> String { private func title(for row: Int) -> String {
guard let item = items[row].rawValue as? String else { return "" } guard let item = items[row].rawValue as? String else { return "" }
return item return item

View File

@ -112,15 +112,13 @@ class ButtonGroupViewController: BaseViewController {
addFormRow(label: "Width", view: widthTextField) addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "Row Quantity", view: rowQuantitySelectorView) addFormRow(label: "Row Quantity", view: rowQuantitySelectorView)
addFormRow(label: "Percentage (1-100)", view: percentageTextField) addFormRow(label: "Percentage (1-100)", view: percentageTextField)
disabledSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.largeLabel.disabled = sender.isOn
.sink { [weak self] sender in self?.smallLabel.disabled = sender.isOn
self?.largeLabel.disabled = sender.isOn self?.largeButtonGroup.disabled = sender.isOn
self?.smallLabel.disabled = sender.isOn self?.smallButtonGroup.disabled = sender.isOn
self?.largeButtonGroup.disabled = sender.isOn }
self?.smallButtonGroup.disabled = sender.isOn
}.store(in: &subscribers)
widthTextField widthTextField
.textPublisher .textPublisher

View File

@ -51,13 +51,11 @@ class ButtonViewController: BaseViewController {
addFormRow(label: "Text", view: textField) addFormRow(label: "Text", view: textField)
addFormRow(label: "Width", view: widthTextField) addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "Size", view: buttonSizePickerSelectorView) addFormRow(label: "Size", view: buttonSizePickerSelectorView)
disabledSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.button.disabled = sender.isOn
.sink { [weak self] sender in }
self?.button.disabled = sender.isOn
}.store(in: &subscribers)
textField textField
.textPublisher .textPublisher

View File

@ -37,18 +37,14 @@ class CheckboxGroupViewController: BaseViewController {
addFormRow(label: "Label Text", view: labelTextField) addFormRow(label: "Label Text", view: labelTextField)
addFormRow(label: "Child Text", view: childTextField) addFormRow(label: "Child Text", view: childTextField)
addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch)) addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch))
showErrorSwitch showErrorSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.checkboxGroup.showError = sender.isOn
.sink { [weak self] sender in }
self?.checkboxGroup.showError = sender.isOn
}.store(in: &subscribers) disabledSwitch.onChange = { [weak self] sender in
self?.checkboxGroup.disabled = sender.isOn
disabledSwitch }
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.checkboxGroup.disabled = sender.isOn
}.store(in: &subscribers)
labelTextField labelTextField
.textPublisher .textPublisher
@ -77,20 +73,18 @@ class CheckboxGroupViewController: BaseViewController {
checkbox2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector" checkbox2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
checkboxGroup.selectorViews = [checkbox1, checkbox2] checkboxGroup.selectorViews = [checkbox1, checkbox2]
checkboxGroup checkboxGroup.onChange = { [weak self] group in
.publisher(for: .valueChanged) let selected = group.selectedHandlers?
.sink { [weak self] group in .compactMap{"\($0.labelText!)"}
let selected = group.selectedHandlers? .joined(separator: "\r") ?? "none selected"
.compactMap{"\($0.labelText!)"}
.joined(separator: "\r") ?? "none selected" let alertController:UIAlertController = UIAlertController(title: "Alert",
message: "Selected Checkboxes:\r\(selected)",
let alertController:UIAlertController = UIAlertController(title: "Alert", preferredStyle: UIAlertController.Style.alert)
message: "Selected Checkboxes:\r\(selected)", alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
preferredStyle: UIAlertController.Style.alert) self?.present(alertController, animated: true)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) }
self?.present(alertController, animated: true)
}.store(in: &subscribers)
//setup UI //setup UI
surfacePickerSelectorView.text = checkboxGroup.surface.rawValue surfacePickerSelectorView.text = checkboxGroup.surface.rawValue

View File

@ -39,22 +39,18 @@ class CheckboxViewController: BaseViewController {
addFormRow(label: "Child Text", view: childTextField) addFormRow(label: "Child Text", view: childTextField)
addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch)) addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch))
addFormRow(label: "Error Text", view: errorTextField) addFormRow(label: "Error Text", view: errorTextField)
showErrorSwitch showErrorSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) guard let self else { return }
.sink { [weak self] sender in self.checkbox.showError = sender.isOn
guard let self else { return } if self.checkbox.showError != sender.isOn {
self.checkbox.showError = sender.isOn self.showErrorSwitch.isOn = self.checkbox.showError
if self.checkbox.showError != sender.isOn { }
self.showErrorSwitch.isOn = self.checkbox.showError }
}
}.store(in: &subscribers) disabledSwitch.onChange = { [weak self] sender in
self?.checkbox.disabled = sender.isOn
disabledSwitch }
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.checkbox.disabled = sender.isOn
}.store(in: &subscribers)
labelTextField labelTextField
.textPublisher .textPublisher
@ -80,17 +76,15 @@ class CheckboxViewController: BaseViewController {
checkbox.childText = "I agree to Verizon's terms and conditions click here" checkbox.childText = "I agree to Verizon's terms and conditions click here"
checkbox.errorText = "Error Text" checkbox.errorText = "Error Text"
checkbox checkbox.onChange = { [weak self] checkbox in
.publisher(for: .valueChanged) let alertController:UIAlertController = UIAlertController(title: "Alert",
.sink { [weak self] checkbox in message: "\(checkbox.labelText!): \(checkbox.isSelected)",
let alertController:UIAlertController = UIAlertController(title: "Alert", preferredStyle: UIAlertController.Style.alert)
message: "\(checkbox.labelText!): \(checkbox.isSelected)", alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
preferredStyle: UIAlertController.Style.alert) self?.present(alertController, animated: true)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) self?.showErrorSwitch.isOn = checkbox.showError
self?.present(alertController, animated: true) print("checkbox selected: \(checkbox.isSelected)")
self?.showErrorSwitch.isOn = checkbox.showError }
print("checkbox selected: \(checkbox.isSelected)")
}.store(in: &subscribers)
//setup UI //setup UI
surfacePickerSelectorView.text = checkbox.surface.rawValue surfacePickerSelectorView.text = checkbox.surface.rawValue

View File

@ -57,38 +57,30 @@ class InputFieldViewController: BaseViewController {
addFormRow(label: "Width", view: widthTextField) addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "ToolTip Title", view: tooltipTitleTextField) addFormRow(label: "ToolTip Title", view: tooltipTitleTextField)
addFormRow(label: "ToolTip Content", view: tooltipContentTextField) addFormRow(label: "ToolTip Content", view: tooltipContentTextField)
requiredSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.textEntryField.required = sender.isOn
}.store(in: &subscribers)
showErrorSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
guard let self else { return }
self.textEntryField.showError = sender.isOn
if self.textEntryField.showError != sender.isOn {
self.showErrorSwitch.isOn = self.textEntryField.showError
}
}.store(in: &subscribers)
showSuccessSwitch requiredSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.textEntryField.required = sender.isOn
.sink { [weak self] sender in }
guard let self else { return }
self.textEntryField.showSuccess = sender.isOn
if self.textEntryField.showSuccess != sender.isOn {
self.showSuccessSwitch.isOn = self.textEntryField.showSuccess
}
}.store(in: &subscribers)
disabledSwitch showErrorSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) guard let self else { return }
.sink { [weak self] sender in self.textEntryField.showError = sender.isOn
self?.textEntryField.disabled = sender.isOn if self.textEntryField.showError != sender.isOn {
}.store(in: &subscribers) self.showErrorSwitch.isOn = self.textEntryField.showError
}
}
showSuccessSwitch.onChange = { [weak self] sender in
guard let self else { return }
self.textEntryField.showSuccess = sender.isOn
if self.textEntryField.showSuccess != sender.isOn {
self.showSuccessSwitch.isOn = self.textEntryField.showSuccess
}
}
disabledSwitch.onChange = { [weak self] sender in
self?.textEntryField.disabled = sender.isOn
}
labelTextField labelTextField
.textPublisher .textPublisher

View File

@ -47,12 +47,10 @@ class LabelViewController: BaseViewController {
addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView) addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView)
addFormRow(label: "Text Size", view: textSizePickerSelectorView) addFormRow(label: "Text Size", view: textSizePickerSelectorView)
addFormRow(label: "Text", view: textField) addFormRow(label: "Text", view: textField)
disabledSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.label.disabled = sender.isOn
.sink { [weak self] sender in }
self?.label.disabled = sender.isOn
}.store(in: &subscribers)
boldSwitch boldSwitch
.publisher(for: .valueChanged) .publisher(for: .valueChanged)

View File

@ -79,8 +79,8 @@ class MenuViewController: UITableViewController {
MenuComponent(title: "Icon", completed: true, viewController: IconViewController.self), MenuComponent(title: "Icon", completed: true, viewController: IconViewController.self),
MenuComponent(title: "InputField", completed: false, viewController: InputFieldViewController.self), MenuComponent(title: "InputField", completed: false, viewController: InputFieldViewController.self),
MenuComponent(title: "Label", completed: true, viewController: LabelViewController.self), MenuComponent(title: "Label", completed: true, viewController: LabelViewController.self),
MenuComponent(title: "Line", completed: false, viewController: LineViewController.self), MenuComponent(title: "Line", completed: true, viewController: LineViewController.self),
MenuComponent(title: "Notification", completed: false, viewController: NotificationViewController.self), MenuComponent(title: "Notification", completed: true, viewController: NotificationViewController.self),
MenuComponent(title: "RadioBoxGroup", completed: true, viewController: RadioBoxGroupViewController.self), MenuComponent(title: "RadioBoxGroup", completed: true, viewController: RadioBoxGroupViewController.self),
MenuComponent(title: "RadioButtonGroup", completed: true, viewController: RadioButtonViewController.self), MenuComponent(title: "RadioButtonGroup", completed: true, viewController: RadioButtonViewController.self),
MenuComponent(title: "RadioSwatchGroup", completed: true, viewController: RadioSwatchGroupViewController.self), MenuComponent(title: "RadioSwatchGroup", completed: true, viewController: RadioSwatchGroupViewController.self),

View File

@ -17,6 +17,8 @@ class NotificationViewController: BaseViewController {
let buttonGroupToggle = Toggle() let buttonGroupToggle = Toggle()
let firstButtonTextField = TextField() let firstButtonTextField = TextField()
let secondButtonTextField = TextField() let secondButtonTextField = TextField()
let hideCloseButtonToggle = Toggle()
let fullBleedToggle = Toggle()
let titleDefaultText = "This is title" let titleDefaultText = "This is title"
let subtitleDefaultText = "This is subtitle" let subtitleDefaultText = "This is subtitle"
@ -24,16 +26,21 @@ class NotificationViewController: BaseViewController {
let secondButtonDefaultText = "Button 2" let secondButtonDefaultText = "Button 2"
lazy var notificationTypePickerSelectorView = { lazy var notificationTypePickerSelectorView = {
PickerSelectorView(title: "Info", PickerSelectorView(title: "info",
picker: self.picker, picker: self.picker,
items: Notification.NotificationStyle.allCases) items: Notification.Style.allCases)
}()
lazy var layoutTypePickerSelectorView = {
PickerSelectorView(title: "vertical", picker: self.picker, items: Notification.Layout.allCases)
}() }()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
addContentTopView(view: notificationView)
notificationView.titleText = titleDefaultText notificationView.title = titleDefaultText
notificationView.subTitleText = subtitleDefaultText notificationView.subTitle = subtitleDefaultText
titleTextField.text = titleDefaultText titleTextField.text = titleDefaultText
subTitleTextField.text = subtitleDefaultText subTitleTextField.text = subtitleDefaultText
@ -41,35 +48,36 @@ class NotificationViewController: BaseViewController {
firstButtonTextField.text = firstButtonDefaultText firstButtonTextField.text = firstButtonDefaultText
secondButtonTextField.text = secondButtonDefaultText secondButtonTextField.text = secondButtonDefaultText
addContentTopView(view: notificationView)
setupForm() setupForm()
setupPicker() setupPicker()
} }
func setupForm() { func setupForm() {
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Style", view: notificationTypePickerSelectorView) addFormRow(label: "Type", view: notificationTypePickerSelectorView)
addFormRow(label: "Layout", view: layoutTypePickerSelectorView)
addFormRow(label: "Title", view: titleTextField) addFormRow(label: "Title", view: titleTextField)
addFormRow(label: "SubTitle", view: subTitleTextField) addFormRow(label: "SubTitle", view: subTitleTextField)
addFormRow(label: "Hide Button Group", view: buttonGroupToggle) addFormRow(label: "Hide Button Group", view: buttonGroupToggle)
addFormRow(label: "Hide Close Button", view: hideCloseButtonToggle)
addFormRow(label: "Full bleed", view: fullBleedToggle)
addFormRow(label: "Button Action", view: label) addFormRow(label: "Button Action", view: label)
addFormRow(label: "First Button Text", view: firstButtonTextField) addFormRow(label: "First Button Text", view: firstButtonTextField)
addFormRow(label: "Second Button Text", view: secondButtonTextField) addFormRow(label: "Second Button Text", view: secondButtonTextField)
notificationView.onCloseClick = { notification in notificationView.onCloseClick = { notification in
print("onCloseClick: \(notification.titleText)") print("onCloseClick: \(notification.title)")
} }
titleTextField.textPublisher.sink { newString in titleTextField.textPublisher.sink { newString in
self.notificationView.titleText = newString self.notificationView.title = newString
}.store(in: &subscribers) }.store(in: &subscribers)
subTitleTextField.textPublisher.sink { newString in subTitleTextField.textPublisher.sink { newString in
self.notificationView.subTitleText = newString self.notificationView.subTitle = newString
}.store(in: &subscribers) }.store(in: &subscribers)
buttonGroupToggle.publisher(for: .valueChanged).sink { [weak self] toggle in buttonGroupToggle.onChange = { [weak self] toggle in
if toggle.isOn { if toggle.isOn {
self?.notificationView.primaryButtonModel = nil self?.notificationView.primaryButtonModel = nil
self?.notificationView.secondaryButtonModel = nil self?.notificationView.secondaryButtonModel = nil
@ -77,8 +85,7 @@ class NotificationViewController: BaseViewController {
} else { } else {
self?.setupButtons(with: self?.firstButtonDefaultText, secondButtonText: self?.secondButtonDefaultText) self?.setupButtons(with: self?.firstButtonDefaultText, secondButtonText: self?.secondButtonDefaultText)
} }
}.store(in: &subscribers) }
firstButtonTextField.textPublisher.sink { newString in firstButtonTextField.textPublisher.sink { newString in
@ -96,6 +103,14 @@ class NotificationViewController: BaseViewController {
self.setupButtons(secondButtonText: newString) self.setupButtons(secondButtonText: newString)
} }
}.store(in: &subscribers) }.store(in: &subscribers)
hideCloseButtonToggle.onChange = { [weak self] toggle in
self?.notificationView.hideCloseButton = toggle.isOn
}
fullBleedToggle.onChange = { [weak self] toggle in
self?.notificationView.fullBleed = toggle.isOn
}
} }
func setupPicker() { func setupPicker() {
@ -108,6 +123,13 @@ class NotificationViewController: BaseViewController {
self?.notificationView.type = item self?.notificationView.type = item
} }
layoutTypePickerSelectorView.onPickerDidSelect = { [weak self] item in
guard let self else { return }
self.notificationView.layout = item
if self.notificationView.layout != item {
self.layoutTypePickerSelectorView.set(item: self.notificationView.layout)
}
}
} }
func setupButtons(with firstButtonText: String? = nil, secondButtonText: String? = nil) { func setupButtons(with firstButtonText: String? = nil, secondButtonText: String? = nil) {

View File

@ -41,17 +41,13 @@ class RadioBoxGroupViewController: BaseViewController {
addFormRow(label: "Sub Text", view: subTextField) addFormRow(label: "Sub Text", view: subTextField)
addFormRow(label: "Sub Text Right", view: subTextRightField) addFormRow(label: "Sub Text Right", view: subTextRightField)
disabledSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.radioBoxGroup.disabled = sender.isOn
.sink { [weak self] sender in }
self?.radioBoxGroup.disabled = sender.isOn
}.store(in: &subscribers)
strikeThroughSwitch strikeThroughSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.radioBox?.strikethrough = sender.isOn
.sink { [weak self] sender in }
self?.radioBox?.strikethrough = sender.isOn
}.store(in: &subscribers)
textField textField
.textPublisher .textPublisher

View File

@ -38,17 +38,13 @@ class RadioButtonViewController: BaseViewController {
addFormRow(label: "Child Text", view: childTextField) addFormRow(label: "Child Text", view: childTextField)
addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch)) addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch))
showErrorSwitch showErrorSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.radioButtonGroup.showError = sender.isOn
.sink { [weak self] sender in }
self?.radioButtonGroup.showError = sender.isOn
}.store(in: &subscribers)
disabledSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.radioButtonGroup.disabled = sender.isOn
.sink { [weak self] sender in }
self?.radioButtonGroup.disabled = sender.isOn
}.store(in: &subscribers)
labelTextField labelTextField
.textPublisher .textPublisher
@ -84,18 +80,16 @@ class RadioButtonViewController: BaseViewController {
radioButton3.childText = "Apple iPhone 11 - 256 GB\nOtterbox Case Black\nScreen Protector" radioButton3.childText = "Apple iPhone 11 - 256 GB\nOtterbox Case Black\nScreen Protector"
radioButtonGroup.selectorViews = [radioButton1, radioButton2, radioButton3] radioButtonGroup.selectorViews = [radioButton1, radioButton2, radioButton3]
radioButtonGroup radioButtonGroup.onChange = { [weak self] group in
.publisher(for: .valueChanged) let alertController:UIAlertController = UIAlertController(title: "Alert",
.sink { [weak self] group in message: "Selected:\r\(group.selectedHandler?.labelText ?? "none")",
let alertController:UIAlertController = UIAlertController(title: "Alert", preferredStyle: UIAlertController.Style.alert)
message: "Selected:\r\(group.selectedHandler?.labelText ?? "none")", alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
preferredStyle: UIAlertController.Style.alert) self?.present(alertController, animated: true)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
self?.present(alertController, animated: true) print("Selected: \(group.selectedHandler?.labelText ?? "none")")
}
print("Selected: \(group.selectedHandler?.labelText ?? "none")")
}.store(in: &subscribers)
//set UI values //set UI values
surfacePickerSelectorView.text = radioButtonGroup.surface.rawValue surfacePickerSelectorView.text = radioButtonGroup.surface.rawValue

View File

@ -29,19 +29,15 @@ class RadioSwatchGroupViewController: BaseViewController {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Strikethrough", view: .makeWrapper(for: strikeThroughSwitch)) addFormRow(label: "Strikethrough", view: .makeWrapper(for: strikeThroughSwitch))
disabledSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.radioSwatchGroup.disabled = sender.isOn
.sink { [weak self] sender in }
self?.radioSwatchGroup.disabled = sender.isOn
}.store(in: &subscribers) strikeThroughSwitch.onChange = { [weak self] sender in
self?.radioSwatchGroup.selectorViews.first?.strikethrough = sender.isOn
strikeThroughSwitch self?.radioSwatchGroup.reload()
.publisher(for: .valueChanged) }
.sink { [weak self] sender in
self?.radioSwatchGroup.selectorViews.first?.strikethrough = sender.isOn
self?.radioSwatchGroup.reload()
}.store(in: &subscribers)
} }
func setupModel(){ func setupModel(){
@ -88,12 +84,10 @@ class RadioSwatchGroupViewController: BaseViewController {
radioSwatch8.inputId = "radioSwatch8" radioSwatch8.inputId = "radioSwatch8"
radioSwatchGroup.selectorViews = [radioSwatch1, radioSwatch2, radioSwatch3, radioSwatch4, radioSwatch5, radioSwatch6, radioSwatch7, radioSwatch8] radioSwatchGroup.selectorViews = [radioSwatch1, radioSwatch2, radioSwatch3, radioSwatch4, radioSwatch5, radioSwatch6, radioSwatch7, radioSwatch8]
radioSwatchGroup radioSwatchGroup.onChange = { group in
.publisher(for: .valueChanged) print("Selected: \(group.selectedHandler?.text ?? "none")")
.sink { group in }
print("Selected: \(group.selectedHandler?.text ?? "none")")
}.store(in: &subscribers)
//set UI values //set UI values
surfacePickerSelectorView.text = radioSwatchGroup.surface.rawValue surfacePickerSelectorView.text = radioSwatchGroup.surface.rawValue

View File

@ -47,28 +47,22 @@ class TextAreaViewController: BaseViewController {
addFormRow(label: "Width", view: widthTextField) addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "ToolTip Title", view: tooltipTitleTextField) addFormRow(label: "ToolTip Title", view: tooltipTitleTextField)
addFormRow(label: "ToolTip Content", view: tooltipContentTextField) addFormRow(label: "ToolTip Content", view: tooltipContentTextField)
requiredSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.textArea.required = sender.isOn
}.store(in: &subscribers)
showErrorSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
guard let self else { return }
self.textArea.showError = sender.isOn
if self.textArea.showError != sender.isOn {
self.showErrorSwitch.isOn = self.textArea.showError
}
}.store(in: &subscribers)
disabledSwitch requiredSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.textArea.required = sender.isOn
.sink { [weak self] sender in }
self?.textArea.disabled = sender.isOn
}.store(in: &subscribers) showErrorSwitch.onChange = { [weak self] sender in
guard let self else { return }
self.textArea.showError = sender.isOn
if self.textArea.showError != sender.isOn {
self.showErrorSwitch.isOn = self.textArea.showError
}
}
disabledSwitch.onChange = { [weak self] sender in
self?.textArea.disabled = sender.isOn
}
labelTextField labelTextField
.textPublisher .textPublisher

View File

@ -42,12 +42,10 @@ class TextLinkCaretViewController: BaseViewController {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Label", view: textField) addFormRow(label: "Label", view: textField)
addFormRow(label: "Caret Position", view: caretPositionPickerSelectorView) addFormRow(label: "Caret Position", view: caretPositionPickerSelectorView)
disabledSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.textLinkCaret.disabled = sender.isOn
.sink { [weak self] sender in }
self?.textLinkCaret.disabled = sender.isOn
}.store(in: &subscribers)
textField textField
.textPublisher .textPublisher

View File

@ -43,13 +43,11 @@ class TextLinkViewController: BaseViewController {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Label", view: textField) addFormRow(label: "Label", view: textField)
addFormRow(label: "Size", view: buttonSizePickerSelectorView) addFormRow(label: "Size", view: buttonSizePickerSelectorView)
disabledSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.textLink.disabled = sender.isOn
.sink { [weak self] sender in }
self?.textLink.disabled = sender.isOn
}.store(in: &subscribers)
textField textField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in

View File

@ -73,41 +73,33 @@ class TileContainerViewController: BaseViewController {
addFormRow(label: "Aspect Ratio", view: scalingTypePickerSelectorView) addFormRow(label: "Aspect Ratio", view: scalingTypePickerSelectorView)
addFormRow(label: "Background Image", view: .makeWrapper(for: showBackgroundImageSwitch)) addFormRow(label: "Background Image", view: .makeWrapper(for: showBackgroundImageSwitch))
addFormRow(label: "Image Fallback Color", view: imageFallbackColorPickerSelectorView) addFormRow(label: "Image Fallback Color", view: imageFallbackColorPickerSelectorView)
clickableSwitch clickableSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) guard let self else { return }
.sink { [weak self] sender in if sender.isOn {
guard let self else { return } self.tileContainer.onClick = { _ in
if sender.isOn { print("you click on me!")
self.tileContainer.onClick = { _ in
print("you click on me!")
}
} else {
self.tileContainer.onClick = nil
} }
}.store(in: &subscribers) } else {
self.tileContainer.onClick = nil
}
}
showBackgroundImageSwitch.onChange = { [weak self] sender in
if let image = self?.backgroundImage, sender.isOn {
self?.tileContainer.backgroundImage = image
} else {
self?.tileContainer.backgroundImage = nil
}
}
showBackgroundImageSwitch showBorderSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged)
.sink { [weak self] sender in
if let image = self?.backgroundImage, sender.isOn {
self?.tileContainer.backgroundImage = image
} else {
self?.tileContainer.backgroundImage = nil
}
}.store(in: &subscribers)
showBorderSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.tileContainer.showBorder = sender.isOn self?.tileContainer.showBorder = sender.isOn
}.store(in: &subscribers) }
showDropShadowSwitch showDropShadowSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.tileContainer.showDropShadows = sender.isOn
.sink { [weak self] sender in }
self?.tileContainer.showDropShadows = sender.isOn
}.store(in: &subscribers)
heightTextField heightTextField
.textPublisher .textPublisher

View File

@ -27,19 +27,19 @@ class TileletViewController: BaseViewController {
lazy var subtitleColorPickerSelectorView = { lazy var subtitleColorPickerSelectorView = {
PickerSelectorView<Use>(title: "", PickerSelectorView<Use>(title: "",
picker: self.picker, picker: self.picker,
items: [.primary, .secondary]) items: [.primary, .secondary])
}() }()
var clickableSwitch = Toggle() var clickableSwitch = Toggle()
var titleTextField = TextField() var titleTextField = TextField()
var subTitleTextField = TextField() var subTitleTextField = TextField()
var widthTextField = NumericField() var widthTextField = NumericField()
var heightTextField = NumericField() var heightTextField = NumericField()
var textPercentageTextField = NumericField() var textPercentageTextField = NumericField()
var textWidthTextField = NumericField() var textWidthTextField = NumericField()
var showDescriptionIconSwitch = Toggle() var showDescriptionIconSwitch = Toggle()
var showDirectionalIconSwitch = Toggle() var showDirectionalIconSwitch = Toggle()
var badgeTextField = TextField() var badgeTextField = TextField()
@ -55,11 +55,11 @@ class TileletViewController: BaseViewController {
} }
override func allTextFields() -> [TextField]? { [titleTextField, subTitleTextField, widthTextField, heightTextField, textWidthTextField, textPercentageTextField, badgeTextField] } override func allTextFields() -> [TextField]? { [titleTextField, subTitleTextField, widthTextField, heightTextField, textWidthTextField, textPercentageTextField, badgeTextField] }
func setupForm(){ func setupForm(){
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Clickable", view: .makeWrapper(for: clickableSwitch)) addFormRow(label: "Clickable", view: .makeWrapper(for: clickableSwitch))
addFormRow(label: "Title Style", view: titleTextStylePickerSelectorView) addFormRow(label: "Title Style", view: titleTextStylePickerSelectorView)
addFormRow(label: "Other Style", view: otherTextStylePickerSelectorView) addFormRow(label: "Other Style", view: otherTextStylePickerSelectorView)
@ -74,18 +74,17 @@ class TileletViewController: BaseViewController {
addFormRow(label: "Description Icon", view: .makeWrapper(for: showDescriptionIconSwitch)) addFormRow(label: "Description Icon", view: .makeWrapper(for: showDescriptionIconSwitch))
addFormRow(label: "Directional Icon", view: .makeWrapper(for: showDirectionalIconSwitch)) addFormRow(label: "Directional Icon", view: .makeWrapper(for: showDirectionalIconSwitch))
clickableSwitch clickableSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) guard let tilelet = self?.tilelet else { return }
.sink { [weak self] sender in if sender.isOn {
guard let tilelet = self?.tilelet else { return } tilelet.onClick = { t in
if sender.isOn { print("you click on me!")
tilelet.onClick = { t in
print("you click on me!")
}
} else {
tilelet.onClick = nil
} }
}.store(in: &subscribers) } else {
tilelet.onClick = nil
}
}
widthTextField widthTextField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in
@ -93,7 +92,7 @@ class TileletViewController: BaseViewController {
self?.tilelet.width = CGFloat(truncating: n) self?.tilelet.width = CGFloat(truncating: n)
} }
}.store(in: &subscribers) }.store(in: &subscribers)
heightTextField heightTextField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in
@ -103,7 +102,7 @@ class TileletViewController: BaseViewController {
self?.tilelet.height = nil self?.tilelet.height = nil
} }
}.store(in: &subscribers) }.store(in: &subscribers)
textWidthTextField textWidthTextField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in
@ -126,49 +125,45 @@ class TileletViewController: BaseViewController {
self?.tilelet.textPercentage = nil self?.tilelet.textPercentage = nil
} }
}.store(in: &subscribers) }.store(in: &subscribers)
titleTextField titleTextField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in
self?.setTitleModel() self?.setTitleModel()
}.store(in: &subscribers) }.store(in: &subscribers)
subTitleTextField subTitleTextField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in
self?.setSubTitleModel() self?.setSubTitleModel()
}.store(in: &subscribers) }.store(in: &subscribers)
badgeTextField badgeTextField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in
self?.setBadgeModel() self?.setBadgeModel()
}.store(in: &subscribers) }.store(in: &subscribers)
showDescriptionIconSwitch showDescriptionIconSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) if sender.isOn {
.sink { [weak self] sender in self?.showDirectionalIconSwitch.isOn = false
if sender.isOn { self?.tilelet.descriptiveIconModel = .init(size: .medium, surface: .dark)
self?.showDirectionalIconSwitch.isOn = false } else {
self?.tilelet.descriptiveIconModel = .init(size: .medium, surface: .dark) self?.tilelet.descriptiveIconModel = nil
} else { }
self?.tilelet.descriptiveIconModel = nil }
}
}.store(in: &subscribers)
showDirectionalIconSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
if sender.isOn {
self?.showDescriptionIconSwitch.isOn = false
self?.tilelet.directionalIconModel = .init(size: .medium, surface: .dark)
} else {
self?.tilelet.directionalIconModel = nil
}
}.store(in: &subscribers)
}
showDirectionalIconSwitch.onChange = { [weak self] sender in
if sender.isOn {
self?.showDescriptionIconSwitch.isOn = false
self?.tilelet.directionalIconModel = .init(size: .medium, surface: .dark)
} else {
self?.tilelet.directionalIconModel = nil
}
}
}
func setupModel() { func setupModel() {
let titleModel = Tilelet.TitleModel(text: "Save $XX on your monthly bill.") let titleModel = Tilelet.TitleModel(text: "Save $XX on your monthly bill.")
let subTitleModel = Tilelet.SubTitleModel(text: "Enroll in Auto Pay & paper-free billing to save on your monthly bill.") let subTitleModel = Tilelet.SubTitleModel(text: "Enroll in Auto Pay & paper-free billing to save on your monthly bill.")
@ -176,7 +171,7 @@ class TileletViewController: BaseViewController {
tilelet.surface = .light tilelet.surface = .light
tilelet.titleModel = titleModel tilelet.titleModel = titleModel
tilelet.subTitleModel = subTitleModel tilelet.subTitleModel = subTitleModel
//setup UI //setup UI
surfacePickerSelectorView.text = tilelet.surface.rawValue surfacePickerSelectorView.text = tilelet.surface.rawValue
otherTextStylePickerSelectorView.text = subTitleModel.textStyle.rawValue otherTextStylePickerSelectorView.text = subTitleModel.textStyle.rawValue
@ -211,7 +206,7 @@ class TileletViewController: BaseViewController {
tilelet.subTitleModel = nil tilelet.subTitleModel = nil
} }
} }
//Picker //Picker
func setupPicker(){ func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
@ -222,7 +217,7 @@ class TileletViewController: BaseViewController {
titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.setTitleModel() self?.setTitleModel()
} }
otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.setSubTitleModel() self?.setSubTitleModel()
} }

View File

@ -69,34 +69,27 @@ class ToggleViewController: BaseViewController {
//add textFormStackView to main form //add textFormStackView to main form
formStackView.addArrangedSubview(textFormStackView) formStackView.addArrangedSubview(textFormStackView)
toggle.publisher(for: .valueChanged) toggle.onChange = { [weak self] toggle in
.sink { [weak self] toggle in let alertController:UIAlertController = UIAlertController(title: "Alert",
let alertController:UIAlertController = UIAlertController(title: "Alert", message: "Toggle Value: \(toggle.isOn)",
message: "Toggle Value: \(toggle.isOn)", preferredStyle: UIAlertController.Style.alert)
preferredStyle: UIAlertController.Style.alert) alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil))
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) self?.present(alertController, animated: true)
self?.present(alertController, animated: true) print("toggle changed: \(toggle.isOn)")
print("toggle changed: \(toggle.isOn)") }
}.store(in: &subscribers)
showTextSwitch showTextSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.toggle.showText = sender.isOn
.sink { [weak self] sender in self?.textFormStackView.isHidden = !sender.isOn
self?.toggle.showText = sender.isOn }
self?.textFormStackView.isHidden = !sender.isOn
}.store(in: &subscribers)
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.toggle.disabled = sender.isOn
}.store(in: &subscribers)
boldSwitch disabledSwitch.onChange = { [weak self] sender in
.publisher(for: .valueChanged) self?.toggle.disabled = sender.isOn
.sink { [weak self] sender in }
self?.toggle.textWeight = sender.isOn ? .bold : .regular
}.store(in: &subscribers) boldSwitch.onChange = { [weak self] sender in
self?.toggle.textWeight = sender.isOn ? .bold : .regular
}
onTextField onTextField
.textPublisher .textPublisher