From 8298f02d3bf1587f27d981848bd72b97397ea260 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 29 Jun 2023 15:31:21 -0500 Subject: [PATCH] refactor for titlelockup/tilelet Signed-off-by: Matt Bruce --- .../TileletViewController.swift | 41 ++++++---- .../TitleLockupViewController.swift | 77 ++++++++++++------- 2 files changed, 77 insertions(+), 41 deletions(-) diff --git a/VDSSample/ViewControllers/TileletViewController.swift b/VDSSample/ViewControllers/TileletViewController.swift index bffad19..a3aa99a 100644 --- a/VDSSample/ViewControllers/TileletViewController.swift +++ b/VDSSample/ViewControllers/TileletViewController.swift @@ -13,16 +13,16 @@ import Combine class TileletViewController: BaseViewController { - lazy var titleTextStylePickerSelectorView = { + lazy var titleStandardStylePickerSelectorView = { PickerSelectorView(title: "", 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: "", 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 = { @@ -59,8 +59,8 @@ class TileletViewController: BaseViewController { addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Clickable", view: .makeWrapper(for: clickableSwitch)) - addFormRow(label: "Title Style", view: titleTextStylePickerSelectorView) - addFormRow(label: "Other Style", view: otherTextStylePickerSelectorView) + addFormRow(label: "Title Style", view: titleStandardStylePickerSelectorView) + addFormRow(label: "Other Style", view: otherStandardStylePickerSelectorView) addFormRow(label: "Title Text", view: titleTextField) addFormRow(label: "Subtitle Color", view: subtitleColorPickerSelectorView) @@ -173,12 +173,15 @@ class TileletViewController: BaseViewController { //setup UI surfacePickerSelectorView.text = component.surface.rawValue - otherTextStylePickerSelectorView.text = subTitleModel.textStyle.rawValue - titleTextStylePickerSelectorView.text = titleModel.textStyle.rawValue + otherStandardStylePickerSelectorView.text = subTitleModel.standardStyle.rawValue + titleStandardStylePickerSelectorView.text = titleModel.standardStyle.rawValue subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue titleTextField.text = titleModel.text subTitleTextField.text = subTitleModel.text widthTextField.text = component.width != nil ? "\(component.width!)" : "" + + self.updateOtherTextStyles() + } //sub models @@ -192,7 +195,7 @@ class TileletViewController: BaseViewController { func setTitleModel() { 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 { component.titleModel = nil } @@ -200,12 +203,20 @@ class TileletViewController: BaseViewController { func setSubTitleModel() { 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 { 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 func setupPicker(){ surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in @@ -213,11 +224,13 @@ class TileletViewController: BaseViewController { self?.contentTopView.backgroundColor = item.color } - titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in - self?.setTitleModel() + titleStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in + guard let self else { return } + self.setTitleModel() + self.updateOtherTextStyles() } - otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in + otherStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.setSubTitleModel() } diff --git a/VDSSample/ViewControllers/TitleLockupViewController.swift b/VDSSample/ViewControllers/TitleLockupViewController.swift index cae960d..ff79f54 100644 --- a/VDSSample/ViewControllers/TitleLockupViewController.swift +++ b/VDSSample/ViewControllers/TitleLockupViewController.swift @@ -18,16 +18,16 @@ class TitleLockupViewController: BaseViewController { items: TitleLockup.TextPosition.allCases) }() - lazy var titleTextStylePickerSelectorView = { + lazy var titleStandardStylePickerSelectorView = { PickerSelectorView(title: "", 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: "", picker: self.picker, - items: TitleLockup.OtherTextStyle.allCases.sorted{ $0.rawValue < $1.rawValue }) + items: TitleLockup.OtherStandardStyle.allCases.sorted{ $0.rawValue < $1.rawValue }) }() lazy var subtitleColorPickerSelectorView = { @@ -36,6 +36,8 @@ class TitleLockupViewController: BaseViewController { items: [.primary, .secondary]) }() + var titleIsBold = Toggle().with { $0.isOn = true } + var eyebrowIsBold = Toggle() var eyebrowTextField = TextField() var titleTextField = TextField() var subTitleTextField = TextField() @@ -54,20 +56,31 @@ class TitleLockupViewController: BaseViewController { super.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: "Title is Bold", view: .makeWrapper(for: titleIsBold)) + 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: "Title Text", view: titleTextField) addFormRow(label: "Subtitle Color", view: subtitleColorPickerSelectorView) 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 .textPublisher .sink { [weak self] text in - self?.setEyebrowModel() + self?.setOtherModels() }.store(in: &subscribers) titleTextField @@ -79,7 +92,7 @@ class TitleLockupViewController: BaseViewController { subTitleTextField .textPublisher .sink { [weak self] text in - self?.setSubTitleModel() + self?.setOtherModels() }.store(in: &subscribers) } @@ -95,36 +108,45 @@ class TitleLockupViewController: BaseViewController { //setup UI surfacePickerSelectorView.text = component.surface.rawValue textPositionPickerSelectorView.text = component.textPosition.rawValue - otherTextStylePickerSelectorView.text = component.otherTextStyle.rawValue - titleTextStylePickerSelectorView.text = titleModel.textStyle.rawValue + otherStandardStylePickerSelectorView.text = subTitleModel.standardStyle.rawValue + titleStandardStylePickerSelectorView.text = titleModel.standardStyle.rawValue subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue eyebrowTextField.text = eyebrowModel.text titleTextField.text = titleModel.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() { 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 { 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 { - component.subTitleModel = TitleLockup.SubTitleModel(text: text, textColor: subtitleColorPickerSelectorView.selectedItem) + component.subTitleModel = TitleLockup.SubTitleModel(text: text, standardStyle: style, textColor: subtitleColorPickerSelectorView.selectedItem) } else { 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 @@ -138,16 +160,17 @@ class TitleLockupViewController: BaseViewController { self?.component.textPosition = item } - titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in + titleStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in self?.setTitleModel() + self?.updateOtherTextStyles() } - otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in - self?.component.otherTextStyle = item + otherStandardStylePickerSelectorView.onPickerDidSelect = { [weak self] item in + self?.setOtherModels() } subtitleColorPickerSelectorView.onPickerDidSelect = { [weak self] item in - self?.setSubTitleModel() + self?.setOtherModels() } } }