139 lines
5.1 KiB
Swift
139 lines
5.1 KiB
Swift
//
|
|
// NotificationViewController.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Nadigadda, Sumanth on 14/03/23.
|
|
//
|
|
|
|
import Foundation
|
|
import VDS
|
|
|
|
class NotificationViewController: BaseViewController {
|
|
|
|
var notificationView = Notification()
|
|
let label = Label()
|
|
let titleTextField = TextField()
|
|
let subTitleTextField = TextField()
|
|
let buttonGroupToggle = Toggle()
|
|
let firstButtonTextField = TextField()
|
|
let secondButtonTextField = TextField()
|
|
|
|
let titleDefaultText = "This is title"
|
|
let subtitleDefaultText = "This is subtitle"
|
|
let firstButtonDefaultText = "Button 1"
|
|
let secondButtonDefaultText = "Button 2"
|
|
|
|
lazy var notificationTypePickerSelectorView = {
|
|
PickerSelectorView(title: "info",
|
|
picker: self.picker,
|
|
items: Notification.NotificationStyle.allCases)
|
|
}()
|
|
|
|
lazy var layoutTypePickerSelectorView = {
|
|
PickerSelectorView(title: "vertical", picker: self.picker, items: Notification.Layout.allCases)
|
|
}()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
notificationView.title = titleDefaultText
|
|
notificationView.subTitle = subtitleDefaultText
|
|
titleTextField.text = titleDefaultText
|
|
subTitleTextField.text = subtitleDefaultText
|
|
|
|
setupButtons(with: firstButtonDefaultText, secondButtonText: secondButtonDefaultText)
|
|
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: "Layout", view: layoutTypePickerSelectorView)
|
|
addFormRow(label: "Title", view: titleTextField)
|
|
addFormRow(label: "SubTitle", view: subTitleTextField)
|
|
addFormRow(label: "Hide Button Group", view: buttonGroupToggle)
|
|
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.title)")
|
|
}
|
|
|
|
titleTextField.textPublisher.sink { newString in
|
|
self.notificationView.title = newString
|
|
}.store(in: &subscribers)
|
|
|
|
subTitleTextField.textPublisher.sink { newString in
|
|
self.notificationView.subTitle = newString
|
|
}.store(in: &subscribers)
|
|
|
|
buttonGroupToggle.publisher(for: .valueChanged).sink { [weak self] toggle in
|
|
if toggle.isOn {
|
|
self?.notificationView.primaryButtonModel = nil
|
|
self?.notificationView.secondaryButtonModel = nil
|
|
self?.label.text = ""
|
|
} else {
|
|
self?.setupButtons(with: self?.firstButtonDefaultText, secondButtonText: self?.secondButtonDefaultText)
|
|
}
|
|
}.store(in: &subscribers)
|
|
|
|
|
|
firstButtonTextField.textPublisher.sink { newString in
|
|
|
|
if newString.isEmpty {
|
|
self.notificationView.primaryButtonModel = nil
|
|
self.notificationView.secondaryButtonModel = nil
|
|
} else {
|
|
self.setupButtons(with: newString, secondButtonText: self.secondButtonTextField.text)
|
|
}
|
|
|
|
}.store(in: &subscribers)
|
|
|
|
secondButtonTextField.textPublisher.sink { newString in
|
|
if !(self.firstButtonTextField.text?.isEmpty ?? true){
|
|
self.setupButtons(secondButtonText: newString)
|
|
}
|
|
}.store(in: &subscribers)
|
|
}
|
|
|
|
func setupPicker() {
|
|
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.notificationView.surface = item
|
|
self?.contentTopView.backgroundColor = item.color
|
|
}
|
|
|
|
notificationTypePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
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) {
|
|
if let firstButtonText {
|
|
notificationView.primaryButtonModel = .init(text: firstButtonText, onClick: { [weak self] button in
|
|
self?.label.text = "\(button.text!) button click"
|
|
})
|
|
}
|
|
|
|
if let secondButtonText {
|
|
notificationView.secondaryButtonModel = .init(text: secondButtonText, onClick: { [weak self] button in
|
|
self?.label.text = "\(button.text!) button click"
|
|
})
|
|
}
|
|
}
|
|
}
|