Merge branch 'feature/tilet' into 'develop'

added selectedItem

See merge request BPHV_MIPS/vds_ios_sample!16
This commit is contained in:
Bruce, Matt R 2023-01-06 21:31:50 +00:00
commit 996c1f343d
4 changed files with 117 additions and 35 deletions

View File

@ -8,6 +8,7 @@
import Foundation
import UIKit
import VDS
import VDSFormControlsTokens
public class TextField: UITextField {
public var isNumeric: Bool = false
@ -30,14 +31,14 @@ public class TextField: UITextField {
public override func textRect(forBounds bounds: CGRect) -> CGRect {
layer.borderColor = UIColor.black.cgColor
layer.borderWidth = 1
layer.borderWidth = VDSFormControls.widthBorder
let rect = super.textRect(forBounds: bounds)
return rect.inset(by: textPadding)
}
public override func editingRect(forBounds bounds: CGRect) -> CGRect {
layer.borderColor = UIColor.black.cgColor
layer.borderWidth = 1
layer.borderWidth = VDSFormControls.widthBorder
let rect = super.editingRect(forBounds: bounds)
return rect.inset(by: textPadding)
}

View File

@ -40,6 +40,10 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
$0.typograpicalStyle = .BodyLarge
}
public var selectedItem: EnumType {
return items[selectedIndex]
}
private var button = Button().with { instance in
instance.size = .small
instance.use = .secondary

View File

@ -11,17 +11,17 @@ import VDS
import VDSColorTokens
class TiletViewController: BaseViewController {
lazy var titleTextStylePickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: TiletTitleTypographicalStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
items: TiletTitleModel.TitleTypographicalStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
}()
lazy var otherTextStylePickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: TiletOtherTypographicalStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
items: TiletSubTitleModel.SubTitleTypographicalStyle.allCases.sorted{ $0.rawValue < $1.rawValue })
}()
lazy var subtitleColorPickerSelectorView = {
@ -33,11 +33,14 @@ class TiletViewController: BaseViewController {
var titleTextField = TextField()
var subTitleTextField = TextField()
var widthTextField = NumericField()
var heightTextField = NumericField()
var textPercentageTextField = NumericField()
var textWidthTextField = NumericField()
var showBadgeSwitch = Toggle()
var badgeTextField = TextField()
var tilet = Tilet()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: .makeWrapper(for: tilet))
@ -47,7 +50,7 @@ class TiletViewController: BaseViewController {
setupModel()
}
override func allTextFields() -> [TextField]? { [titleTextField, subTitleTextField, widthTextField, textWidthTextField, textPercentageTextField] }
override func allTextFields() -> [TextField]? { [titleTextField, subTitleTextField, widthTextField, heightTextField, textWidthTextField, textPercentageTextField, badgeTextField] }
func setupForm(){
addFormRow(label: "Surface", view: surfacePickerSelectorView)
@ -59,8 +62,11 @@ class TiletViewController: BaseViewController {
addFormRow(label: "Subtitle Color", view: subtitleColorPickerSelectorView)
addFormRow(label: "Subtitle Text", view: subTitleTextField)
addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "Height", view: heightTextField)
addFormRow(label: "Text Width", view: textWidthTextField)
addFormRow(label: "Text Percentage", view: textPercentageTextField)
addFormRow(label: "Text Percentage", view: badgeTextField)
addFormRow(label: "Badge Text", view: badgeTextField)
widthTextField
.textPublisher
@ -70,6 +76,16 @@ class TiletViewController: BaseViewController {
}
}.store(in: &subscribers)
heightTextField
.textPublisher
.sink { [weak self] text in
if let n = NumberFormatter().number(from: text) {
self?.tilet.height = CGFloat(truncating: n)
} else {
self?.tilet.height = nil
}
}.store(in: &subscribers)
textWidthTextField
.textPublisher
.sink { [weak self] text in
@ -96,32 +112,65 @@ class TiletViewController: BaseViewController {
titleTextField
.textPublisher
.sink { [weak self] text in
self?.tilet.titleText = text
self?.setTitleModel()
}.store(in: &subscribers)
subTitleTextField
.textPublisher
.sink { [weak self] text in
self?.tilet.subTitleText = text
self?.setSubTitleModel()
}.store(in: &subscribers)
badgeTextField
.textPublisher
.sink { [weak self] text in
self?.setBadgeModel()
}.store(in: &subscribers)
}
func setupModel() {
let titleModel = TiletTitleModel(text: "Save $XX on your monthly bill.")
let subTitleModel = TiletSubTitleModel(text: "Enroll in Auto Pay & paper-free billing to save on your monthly bill.")
tilet.surface = .light
tilet.width = 312
tilet.titleText = "Save $XX on your monthly bill."
tilet.subTitleText = "Enroll in Auto Pay & paper-free billing to save on your monthly bill."
tilet.titleModel = titleModel
tilet.subTitleModel = subTitleModel
//setup UI
surfacePickerSelectorView.text = tilet.surface.rawValue
otherTextStylePickerSelectorView.text = tilet.otherTypograpicalStyle.rawValue
titleTextStylePickerSelectorView.text = tilet.titleTypograpicalStyle.rawValue
subtitleColorPickerSelectorView.text = tilet.subTitleColor.rawValue
titleTextField.text = tilet.titleText
subTitleTextField.text = tilet.subTitleText
otherTextStylePickerSelectorView.text = subTitleModel.typographicalStyle.rawValue
titleTextStylePickerSelectorView.text = titleModel.typographicalStyle.rawValue
subtitleColorPickerSelectorView.text = subTitleModel.textColor.rawValue
titleTextField.text = titleModel.text
subTitleTextField.text = subTitleModel.text
widthTextField.text = "\(tilet.width)"
}
//sub models
func setBadgeModel() {
if let text = badgeTextField.text, !text.isEmpty {
tilet.badgeModel = TiletBadgeModel(text: text)
} else {
tilet.badgeModel = nil
}
}
func setTitleModel() {
if let text = titleTextField.text, !text.isEmpty {
tilet.titleModel = TiletTitleModel(text: text, typographicalStyle: titleTextStylePickerSelectorView.selectedItem)
} else {
tilet.titleModel = nil
}
}
func setSubTitleModel() {
if let text = subTitleTextField.text, !text.isEmpty {
tilet.subTitleModel = TiletSubTitleModel(text: text, typographicalStyle: otherTextStylePickerSelectorView.selectedItem)
} else {
tilet.subTitleModel = nil
}
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
@ -130,15 +179,15 @@ class TiletViewController: BaseViewController {
}
titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.tilet.titleTypograpicalStyle = item
self?.setTitleModel()
}
otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.tilet.otherTypograpicalStyle = item
self?.setSubTitleModel()
}
subtitleColorPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.tilet.subTitleColor = item
self?.setSubTitleModel()
}
}
}

View File

@ -69,36 +69,64 @@ class TitleLockupViewController: BaseViewController {
eyebrowTextField
.textPublisher
.sink { [weak self] text in
self?.titleLockup.eyebrowText = text
self?.setEyebrowModel()
}.store(in: &subscribers)
titleTextField
.textPublisher
.sink { [weak self] text in
self?.titleLockup.titleText = text
self?.setTitleModel()
}.store(in: &subscribers)
subTitleTextField
.textPublisher
.sink { [weak self] text in
self?.titleLockup.subTitleText = text
self?.setSubTitleModel()
}.store(in: &subscribers)
}
func setupModel() {
titleLockup.eyebrowText = "Today only."
titleLockup.titleText = "Get more of our best"
titleLockup.subTitleText = "Get both of our best and pay less. Pair 5G Home Internet with Verizon mobile to save every month."
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 = titleLockup.titleTypograpicalStyle.rawValue
subtitleColorPickerSelectorView.text = titleLockup.subTitleColor.rawValue
eyebrowTextField.text = titleLockup.eyebrowText
titleTextField.text = titleLockup.titleText
subTitleTextField.text = titleLockup.subTitleText
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
@ -113,7 +141,7 @@ class TitleLockupViewController: BaseViewController {
}
titleTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.titleLockup.titleTypograpicalStyle = item
self?.setTitleModel()
}
otherTextStylePickerSelectorView.onPickerDidSelect = { [weak self] item in
@ -121,7 +149,7 @@ class TitleLockupViewController: BaseViewController {
}
subtitleColorPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.titleLockup.subTitleColor = item
self?.setSubTitleModel()
}
}
}