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()
}
}
public var items: [EnumType] {
didSet { selectedIndex = 0 }
}
@ -117,6 +118,13 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
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 {
guard let item = items[row].rawValue as? String else { return "" }
return item

View File

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

View File

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

View File

@ -37,18 +37,14 @@ class CheckboxGroupViewController: BaseViewController {
addFormRow(label: "Label Text", view: labelTextField)
addFormRow(label: "Child Text", view: childTextField)
addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch))
showErrorSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.checkboxGroup.showError = sender.isOn
}.store(in: &subscribers)
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.checkboxGroup.disabled = sender.isOn
}.store(in: &subscribers)
showErrorSwitch.onChange = { [weak self] sender in
self?.checkboxGroup.showError = sender.isOn
}
disabledSwitch.onChange = { [weak self] sender in
self?.checkboxGroup.disabled = sender.isOn
}
labelTextField
.textPublisher
@ -77,20 +73,18 @@ class CheckboxGroupViewController: BaseViewController {
checkbox2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
checkboxGroup.selectorViews = [checkbox1, checkbox2]
checkboxGroup
.publisher(for: .valueChanged)
.sink { [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)
}.store(in: &subscribers)
checkboxGroup.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 = checkboxGroup.surface.rawValue

View File

@ -39,22 +39,18 @@ class CheckboxViewController: BaseViewController {
addFormRow(label: "Child Text", view: childTextField)
addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch))
addFormRow(label: "Error Text", view: errorTextField)
showErrorSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
guard let self else { return }
self.checkbox.showError = sender.isOn
if self.checkbox.showError != sender.isOn {
self.showErrorSwitch.isOn = self.checkbox.showError
}
}.store(in: &subscribers)
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.checkbox.disabled = sender.isOn
}.store(in: &subscribers)
showErrorSwitch.onChange = { [weak self] sender in
guard let self else { return }
self.checkbox.showError = sender.isOn
if self.checkbox.showError != sender.isOn {
self.showErrorSwitch.isOn = self.checkbox.showError
}
}
disabledSwitch.onChange = { [weak self] sender in
self?.checkbox.disabled = sender.isOn
}
labelTextField
.textPublisher
@ -80,17 +76,15 @@ class CheckboxViewController: BaseViewController {
checkbox.childText = "I agree to Verizon's terms and conditions click here"
checkbox.errorText = "Error Text"
checkbox
.publisher(for: .valueChanged)
.sink { [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)")
}.store(in: &subscribers)
checkbox.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 = checkbox.surface.rawValue

View File

@ -57,38 +57,30 @@ class InputFieldViewController: BaseViewController {
addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "ToolTip Title", view: tooltipTitleTextField)
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
.publisher(for: .valueChanged)
.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)
requiredSwitch.onChange = { [weak self] sender in
self?.textEntryField.required = sender.isOn
}
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.textEntryField.disabled = sender.isOn
}.store(in: &subscribers)
showErrorSwitch.onChange = { [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
}
}
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
.textPublisher

View File

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

View File

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

View File

@ -17,6 +17,8 @@ class NotificationViewController: BaseViewController {
let buttonGroupToggle = Toggle()
let firstButtonTextField = TextField()
let secondButtonTextField = TextField()
let hideCloseButtonToggle = Toggle()
let fullBleedToggle = Toggle()
let titleDefaultText = "This is title"
let subtitleDefaultText = "This is subtitle"
@ -24,16 +26,21 @@ class NotificationViewController: BaseViewController {
let secondButtonDefaultText = "Button 2"
lazy var notificationTypePickerSelectorView = {
PickerSelectorView(title: "Info",
PickerSelectorView(title: "info",
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() {
super.viewDidLoad()
addContentTopView(view: notificationView)
notificationView.titleText = titleDefaultText
notificationView.subTitleText = subtitleDefaultText
notificationView.title = titleDefaultText
notificationView.subTitle = subtitleDefaultText
titleTextField.text = titleDefaultText
subTitleTextField.text = subtitleDefaultText
@ -41,35 +48,36 @@ class NotificationViewController: BaseViewController {
firstButtonTextField.text = firstButtonDefaultText
secondButtonTextField.text = secondButtonDefaultText
addContentTopView(view: notificationView)
setupForm()
setupPicker()
}
func setupForm() {
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: "SubTitle", view: subTitleTextField)
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: "First Button Text", view: firstButtonTextField)
addFormRow(label: "Second Button Text", view: secondButtonTextField)
notificationView.onCloseClick = { notification in
print("onCloseClick: \(notification.titleText)")
print("onCloseClick: \(notification.title)")
}
titleTextField.textPublisher.sink { newString in
self.notificationView.titleText = newString
self.notificationView.title = newString
}.store(in: &subscribers)
subTitleTextField.textPublisher.sink { newString in
self.notificationView.subTitleText = newString
self.notificationView.subTitle = newString
}.store(in: &subscribers)
buttonGroupToggle.publisher(for: .valueChanged).sink { [weak self] toggle in
buttonGroupToggle.onChange = { [weak self] toggle in
if toggle.isOn {
self?.notificationView.primaryButtonModel = nil
self?.notificationView.secondaryButtonModel = nil
@ -77,8 +85,7 @@ class NotificationViewController: BaseViewController {
} else {
self?.setupButtons(with: self?.firstButtonDefaultText, secondButtonText: self?.secondButtonDefaultText)
}
}.store(in: &subscribers)
}
firstButtonTextField.textPublisher.sink { newString in
@ -96,6 +103,14 @@ class NotificationViewController: BaseViewController {
self.setupButtons(secondButtonText: newString)
}
}.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() {
@ -108,6 +123,13 @@ class NotificationViewController: BaseViewController {
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) {

View File

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

View File

@ -38,17 +38,13 @@ class RadioButtonViewController: BaseViewController {
addFormRow(label: "Child Text", view: childTextField)
addFormRow(label: "Error", view: .makeWrapper(for: showErrorSwitch))
showErrorSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioButtonGroup.showError = sender.isOn
}.store(in: &subscribers)
showErrorSwitch.onChange = { [weak self] sender in
self?.radioButtonGroup.showError = sender.isOn
}
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioButtonGroup.disabled = sender.isOn
}.store(in: &subscribers)
disabledSwitch.onChange = { [weak self] sender in
self?.radioButtonGroup.disabled = sender.isOn
}
labelTextField
.textPublisher
@ -84,18 +80,16 @@ class RadioButtonViewController: BaseViewController {
radioButton3.childText = "Apple iPhone 11 - 256 GB\nOtterbox Case Black\nScreen Protector"
radioButtonGroup.selectorViews = [radioButton1, radioButton2, radioButton3]
radioButtonGroup
.publisher(for: .valueChanged)
.sink { [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")")
}.store(in: &subscribers)
radioButtonGroup.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")")
}
//set UI values
surfacePickerSelectorView.text = radioButtonGroup.surface.rawValue

View File

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

View File

@ -47,28 +47,22 @@ class TextAreaViewController: BaseViewController {
addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "ToolTip Title", view: tooltipTitleTextField)
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
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.textArea.disabled = sender.isOn
}.store(in: &subscribers)
requiredSwitch.onChange = { [weak self] sender in
self?.textArea.required = sender.isOn
}
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
.textPublisher

View File

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

View File

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

View File

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

View File

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

View File

@ -69,34 +69,27 @@ class ToggleViewController: BaseViewController {
//add textFormStackView to main form
formStackView.addArrangedSubview(textFormStackView)
toggle.publisher(for: .valueChanged)
.sink { [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)")
}.store(in: &subscribers)
toggle.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)")
}
showTextSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
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)
showTextSwitch.onChange = { [weak self] sender in
self?.toggle.showText = sender.isOn
self?.textFormStackView.isHidden = !sender.isOn
}
boldSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.toggle.textWeight = sender.isOn ? .bold : .regular
}.store(in: &subscribers)
disabledSwitch.onChange = { [weak self] sender in
self?.toggle.disabled = sender.isOn
}
boldSwitch.onChange = { [weak self] sender in
self?.toggle.textWeight = sender.isOn ? .bold : .regular
}
onTextField
.textPublisher