156 lines
5.4 KiB
Swift
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: TitleLockup.TextPosition.allCases)
|
|
}()
|
|
|
|
lazy var titleTextStylePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: TitleLockup.TitleTextStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
|
|
}()
|
|
|
|
lazy var otherTextStylePickerSelectorView = {
|
|
PickerSelectorView(title: "",
|
|
picker: self.picker,
|
|
items: TitleLockup.OtherTextStyle.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 = TitleLockup.EyebrowModel(text: "Today only.")
|
|
let titleModel = TitleLockup.TitleModel(text: "Get more of our best")
|
|
let subTitleModel = TitleLockup.SubTitleModel(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.otherTextStyle.rawValue
|
|
titleTextStylePickerSelectorView.text = titleModel.textStyle.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 = TitleLockup.EyebrowModel(text: text)
|
|
} else {
|
|
titleLockup.eyebrowModel = nil
|
|
}
|
|
}
|
|
|
|
func setTitleModel() {
|
|
if let text = titleTextField.text, !text.isEmpty {
|
|
titleLockup.titleModel = TitleLockup.TitleModel(text: text, textStyle: titleTextStylePickerSelectorView.selectedItem)
|
|
} else {
|
|
titleLockup.titleModel = nil
|
|
}
|
|
}
|
|
|
|
func setSubTitleModel() {
|
|
if let text = subTitleTextField.text, !text.isEmpty {
|
|
titleLockup.subTitleModel = TitleLockup.SubTitleModel(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.otherTextStyle = item
|
|
}
|
|
|
|
subtitleColorPickerSelectorView.onPickerDidSelect = { [weak self] item in
|
|
self?.setSubTitleModel()
|
|
}
|
|
}
|
|
}
|