refactor for titlelockup/tilelet

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-06-29 15:31:21 -05:00
parent 8b945943e2
commit 8298f02d3b
2 changed files with 77 additions and 41 deletions

View File

@ -13,16 +13,16 @@ import Combine
class TileletViewController: BaseViewController<Tilelet> { class TileletViewController: BaseViewController<Tilelet> {
lazy var titleTextStylePickerSelectorView = { lazy var titleStandardStylePickerSelectorView = {
PickerSelectorView(title: "", PickerSelectorView(title: "",
picker: self.picker, picker: self.picker,
items: Tilelet.TitleModel.TextStyle.allCases.sorted{ $0.rawValue < $1.rawValue }) items: Tilelet.TitleModel.StandardStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
}() }()
lazy var otherTextStylePickerSelectorView = { lazy var otherStandardStylePickerSelectorView = {
PickerSelectorView(title: "", PickerSelectorView(title: "",
picker: self.picker, picker: self.picker,
items: Tilelet.SubTitleModel.TextStyle.allCases.sorted{ $0.rawValue < $1.rawValue }) items: Tilelet.SubTitleModel.StandardStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
}() }()
lazy var subtitleColorPickerSelectorView = { lazy var subtitleColorPickerSelectorView = {
@ -59,8 +59,8 @@ class TileletViewController: BaseViewController<Tilelet> {
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: titleStandardStylePickerSelectorView)
addFormRow(label: "Other Style", view: otherTextStylePickerSelectorView) addFormRow(label: "Other Style", view: otherStandardStylePickerSelectorView)
addFormRow(label: "Title Text", view: titleTextField) addFormRow(label: "Title Text", view: titleTextField)
addFormRow(label: "Subtitle Color", view: subtitleColorPickerSelectorView) addFormRow(label: "Subtitle Color", view: subtitleColorPickerSelectorView)
@ -173,12 +173,15 @@ class TileletViewController: BaseViewController<Tilelet> {
//setup UI //setup UI
surfacePickerSelectorView.text = component.surface.rawValue surfacePickerSelectorView.text = component.surface.rawValue
otherTextStylePickerSelectorView.text = subTitleModel.textStyle.rawValue otherStandardStylePickerSelectorView.text = subTitleModel.standardStyle.rawValue
titleTextStylePickerSelectorView.text = titleModel.textStyle.rawValue titleStandardStylePickerSelectorView.text = titleModel.standardStyle.rawValue
subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue
titleTextField.text = titleModel.text titleTextField.text = titleModel.text
subTitleTextField.text = subTitleModel.text subTitleTextField.text = subTitleModel.text
widthTextField.text = component.width != nil ? "\(component.width!)" : "" widthTextField.text = component.width != nil ? "\(component.width!)" : ""
self.updateOtherTextStyles()
} }
//sub models //sub models
@ -192,7 +195,7 @@ class TileletViewController: BaseViewController<Tilelet> {
func setTitleModel() { func setTitleModel() {
if let text = titleTextField.text, !text.isEmpty { if let text = titleTextField.text, !text.isEmpty {
component.titleModel = Tilelet.TitleModel(text: text, textStyle: titleTextStylePickerSelectorView.selectedItem) component.titleModel = Tilelet.TitleModel(text: text, standardStyle: titleStandardStylePickerSelectorView.selectedItem)
} else { } else {
component.titleModel = nil component.titleModel = nil
} }
@ -200,12 +203,20 @@ class TileletViewController: BaseViewController<Tilelet> {
func setSubTitleModel() { func setSubTitleModel() {
if let text = subTitleTextField.text, !text.isEmpty { if let text = subTitleTextField.text, !text.isEmpty {
component.subTitleModel = Tilelet.SubTitleModel(text: text, textStyle: otherTextStylePickerSelectorView.selectedItem) component.subTitleModel = Tilelet.SubTitleModel(text: text, standardStyle: otherStandardStylePickerSelectorView.selectedItem)
} else { } else {
component.subTitleModel = nil component.subTitleModel = nil
} }
} }
func updateOtherTextStyles() {
let items = component.titleLockup.standardStyleConfiguration.configuration(for: titleStandardStylePickerSelectorView.selectedItem.value)!.allOtherStandardStyles
let otheritems = items.compactMap { Tilelet.SubTitleModel.StandardStyle(rawValue: $0.rawValue)! }
otherStandardStylePickerSelectorView.items = otheritems
otherStandardStylePickerSelectorView.text = otheritems.first?.rawValue ?? ""
setSubTitleModel()
}
//Picker //Picker
func setupPicker(){ func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
@ -213,11 +224,13 @@ class TileletViewController: BaseViewController<Tilelet> {
self?.contentTopView.backgroundColor = item.color self?.contentTopView.backgroundColor = item.color
} }
titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in titleStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.setTitleModel() guard let self else { return }
self.setTitleModel()
self.updateOtherTextStyles()
} }
otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in otherStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.setSubTitleModel() self?.setSubTitleModel()
} }

View File

@ -18,16 +18,16 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
items: TitleLockup.TextPosition.allCases) items: TitleLockup.TextPosition.allCases)
}() }()
lazy var titleTextStylePickerSelectorView = { lazy var titleStandardStylePickerSelectorView = {
PickerSelectorView(title: "", PickerSelectorView(title: "",
picker: self.picker, picker: self.picker,
items: TitleLockup.TitleTextStyle.allCases.sorted{ $0.rawValue < $1.rawValue }) items: TitleLockup.TitleStandardStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
}() }()
lazy var otherTextStylePickerSelectorView = { lazy var otherStandardStylePickerSelectorView = {
PickerSelectorView(title: "", PickerSelectorView(title: "",
picker: self.picker, picker: self.picker,
items: TitleLockup.OtherTextStyle.allCases.sorted{ $0.rawValue < $1.rawValue }) items: TitleLockup.OtherStandardStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
}() }()
lazy var subtitleColorPickerSelectorView = { lazy var subtitleColorPickerSelectorView = {
@ -36,6 +36,8 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
items: [.primary, .secondary]) items: [.primary, .secondary])
}() }()
var titleIsBold = Toggle().with { $0.isOn = true }
var eyebrowIsBold = Toggle()
var eyebrowTextField = TextField() var eyebrowTextField = TextField()
var titleTextField = TextField() var titleTextField = TextField()
var subTitleTextField = TextField() var subTitleTextField = TextField()
@ -54,20 +56,31 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
super.setupForm() super.setupForm()
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Text Position", view: textPositionPickerSelectorView) addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
addFormRow(label: "Title Style", view: titleTextStylePickerSelectorView) addFormRow(label: "Title is Bold", view: .makeWrapper(for: titleIsBold))
addFormRow(label: "Other Style", view: otherTextStylePickerSelectorView) addFormRow(label: "Eyebrow is Bold", view: .makeWrapper(for: eyebrowIsBold))
addFormRow(label: "Title Style", view: titleStandardStylePickerSelectorView)
addFormRow(label: "Other Style", view: otherStandardStylePickerSelectorView)
addFormRow(label: "Eyebrow Text", view: eyebrowTextField) addFormRow(label: "Eyebrow Text", view: eyebrowTextField)
addFormRow(label: "Title Text", view: titleTextField) addFormRow(label: "Title Text", view: titleTextField)
addFormRow(label: "Subtitle Color", view: subtitleColorPickerSelectorView) addFormRow(label: "Subtitle Color", view: subtitleColorPickerSelectorView)
addFormRow(label: "Subtitle Text", view: subTitleTextField) addFormRow(label: "Subtitle Text", view: subTitleTextField)
eyebrowIsBold.publisher(for: .valueChanged).sink { [weak self] toggle in
self?.setOtherModels()
}.store(in: &subscribers)
titleIsBold.publisher(for: .valueChanged).sink { [weak self] toggle in
self?.setTitleModel()
}.store(in: &subscribers)
eyebrowTextField eyebrowTextField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in
self?.setEyebrowModel() self?.setOtherModels()
}.store(in: &subscribers) }.store(in: &subscribers)
titleTextField titleTextField
@ -79,7 +92,7 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
subTitleTextField subTitleTextField
.textPublisher .textPublisher
.sink { [weak self] text in .sink { [weak self] text in
self?.setSubTitleModel() self?.setOtherModels()
}.store(in: &subscribers) }.store(in: &subscribers)
} }
@ -95,36 +108,45 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
//setup UI //setup UI
surfacePickerSelectorView.text = component.surface.rawValue surfacePickerSelectorView.text = component.surface.rawValue
textPositionPickerSelectorView.text = component.textPosition.rawValue textPositionPickerSelectorView.text = component.textPosition.rawValue
otherTextStylePickerSelectorView.text = component.otherTextStyle.rawValue otherStandardStylePickerSelectorView.text = subTitleModel.standardStyle.rawValue
titleTextStylePickerSelectorView.text = titleModel.textStyle.rawValue titleStandardStylePickerSelectorView.text = titleModel.standardStyle.rawValue
subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue
eyebrowTextField.text = eyebrowModel.text eyebrowTextField.text = eyebrowModel.text
titleTextField.text = titleModel.text titleTextField.text = titleModel.text
subTitleTextField.text = subTitleModel.text subTitleTextField.text = subTitleModel.text
updateOtherTextStyles()
} }
func setEyebrowModel() {
if let text = eyebrowTextField.text, !text.isEmpty {
component.eyebrowModel = TitleLockup.EyebrowModel(text: text)
} else {
component.eyebrowModel = nil
}
}
func setTitleModel() { func setTitleModel() {
if let text = titleTextField.text, !text.isEmpty { if let text = titleTextField.text, !text.isEmpty {
component.titleModel = TitleLockup.TitleModel(text: text, textStyle: titleTextStylePickerSelectorView.selectedItem) component.titleModel = TitleLockup.TitleModel(text: text, isBold: titleIsBold.isOn, standardStyle: titleStandardStylePickerSelectorView.selectedItem)
} else { } else {
component.titleModel = nil component.titleModel = nil
} }
} }
func setSubTitleModel() { func updateOtherTextStyles() {
let items = component.standardStyleConfiguration.configuration(for: titleStandardStylePickerSelectorView.selectedItem)!.allOtherStandardStyles
otherStandardStylePickerSelectorView.items = items
otherStandardStylePickerSelectorView.text = items.first?.rawValue ?? ""
setOtherModels()
}
func setOtherModels() {
let style = otherStandardStylePickerSelectorView.selectedItem
if let text = subTitleTextField.text, !text.isEmpty { if let text = subTitleTextField.text, !text.isEmpty {
component.subTitleModel = TitleLockup.SubTitleModel(text: text, textColor: subtitleColorPickerSelectorView.selectedItem) component.subTitleModel = TitleLockup.SubTitleModel(text: text, standardStyle: style, textColor: subtitleColorPickerSelectorView.selectedItem)
} else { } else {
component.subTitleModel = nil component.subTitleModel = nil
} }
if let text = eyebrowTextField.text, !text.isEmpty {
component.eyebrowModel = TitleLockup.EyebrowModel(text: text, isBold: eyebrowIsBold.isOn, standardStyle: style)
} else {
component.eyebrowModel = nil
}
} }
//Picker //Picker
@ -138,16 +160,17 @@ class TitleLockupViewController: BaseViewController<TitleLockup> {
self?.component.textPosition = item self?.component.textPosition = item
} }
titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in titleStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.setTitleModel() self?.setTitleModel()
self?.updateOtherTextStyles()
} }
otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in otherStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.otherTextStyle = item self?.setOtherModels()
} }
subtitleColorPickerSelectorView.onPickerDidSelect = { [weak self] item in subtitleColorPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.setSubTitleModel() self?.setOtherModels()
} }
} }
} }