vds_ios_sample/VDSSample/ViewControllers/TitleLockupViewController.swift
Matt Bruce 8a709174a0 converted to use models for ease of use
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-01-06 14:55:52 -06:00

156 lines
5.4 KiB
Swift

//
// TitleLockupViewController.swift
// VDSSample
//
// Created by Matt Bruce on 12/19/22.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
class TitleLockupViewController: BaseViewController {
lazy var textPositionPickerSelectorView = {
PickerSelectorView(title: "left",
picker: self.picker,
items: TitleLockupTextPosition.allCases)
}()
lazy var titleTextStylePickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: TitleLockupTitleTypographicalStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
}()
lazy var otherTextStylePickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: TitleLockupOtherTypographicalStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
}()
lazy var subtitleColorPickerSelectorView = {
PickerSelectorView<Use>(title: "",
picker: self.picker,
items: [.primary, .secondary])
}()
var eyebrowTextField = TextField()
var titleTextField = TextField()
var subTitleTextField = TextField()
var titleLockup = TitleLockup()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: titleLockup)
setupForm()
setupPicker()
setupModel()
}
override func allTextFields() -> [TextField]? { [eyebrowTextField, titleTextField, subTitleTextField] }
func setupForm(){
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
addFormRow(label: "Title Style", view: titleTextStylePickerSelectorView)
addFormRow(label: "Other Style", view: otherTextStylePickerSelectorView)
addFormRow(label: "Eyebrow Text", view: eyebrowTextField)
addFormRow(label: "Title Text", view: titleTextField)
addFormRow(label: "Subtitle Color", view: subtitleColorPickerSelectorView)
addFormRow(label: "Subtitle Text", view: subTitleTextField)
eyebrowTextField
.textPublisher
.sink { [weak self] text in
self?.setEyebrowModel()
}.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)
}
func setupModel() {
let eyebrowModel = TitleLockupEyebrowModel(text: "Today only.")
let titleModel = TitleLockupTitleModel(text: "Get more of our best")
let subTitleModel = TitleLockupSubTitleModel(text: "Get both of our best and pay less. Pair 5G Home Internet with Verizon mobile to save every month.")
titleLockup.eyebrowModel = eyebrowModel
titleLockup.titleModel = titleModel
titleLockup.subTitleModel = subTitleModel
//setup UI
surfacePickerSelectorView.text = titleLockup.surface.rawValue
textPositionPickerSelectorView.text = titleLockup.textPosition.rawValue
otherTextStylePickerSelectorView.text = titleLockup.otherTypograpicalStyle.rawValue
titleTextStylePickerSelectorView.text = titleModel.typographicalStyle.rawValue
subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue
eyebrowTextField.text = eyebrowModel.text
titleTextField.text = titleModel.text
subTitleTextField.text = subTitleModel.text
}
func setEyebrowModel() {
if let text = eyebrowTextField.text, !text.isEmpty {
titleLockup.eyebrowModel = TitleLockupEyebrowModel(text: text)
} else {
titleLockup.eyebrowModel = nil
}
}
func setTitleModel() {
if let text = titleTextField.text, !text.isEmpty {
titleLockup.titleModel = TitleLockupTitleModel(text: text, typographicalStyle: titleTextStylePickerSelectorView.selectedItem)
} else {
titleLockup.titleModel = nil
}
}
func setSubTitleModel() {
if let text = subTitleTextField.text, !text.isEmpty {
titleLockup.subTitleModel = TitleLockupSubTitleModel(text: text, textColor: subtitleColorPickerSelectorView.selectedItem)
} else {
titleLockup.subTitleModel = nil
}
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.titleLockup.surface = item
self?.contentTopView.backgroundColor = item.color
}
textPositionPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.titleLockup.textPosition = item
}
titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.setTitleModel()
}
otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.titleLockup.otherTypograpicalStyle = item
}
subtitleColorPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.setSubTitleModel()
}
}
}