refactored label
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
7d1924c21d
commit
d8eebd69c7
@ -31,6 +31,12 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
||||
super.viewDidLoad()
|
||||
addContentTopView(view: checkboxGroup)
|
||||
|
||||
setupForm()
|
||||
setupPicker()
|
||||
setupModel()
|
||||
}
|
||||
|
||||
func setupForm() {
|
||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||
addFormRow(label: "Label Text", view: labelTextField)
|
||||
@ -67,15 +73,11 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
||||
self?.checkbox?.childText = text
|
||||
}.store(in: &subscribers)
|
||||
|
||||
|
||||
surfacePickerSelectorView.button
|
||||
.publisher(for: .touchUpInside)
|
||||
.sink { [weak self] _ in
|
||||
self?.pickerType = .surface
|
||||
}.store(in: &subscribers)
|
||||
|
||||
setupPicker()
|
||||
setupModel()
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
|
||||
@ -31,6 +31,12 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
||||
super.viewDidLoad()
|
||||
addContentTopView(view: checkbox)
|
||||
|
||||
setupForm()
|
||||
setupPicker()
|
||||
setupModel()
|
||||
}
|
||||
|
||||
func setupForm(){
|
||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||
addFormRow(label: "Label Text", view: labelTextField)
|
||||
@ -80,9 +86,6 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
||||
.sink { [weak self] _ in
|
||||
self?.pickerType = .surface
|
||||
}.store(in: &subscribers)
|
||||
|
||||
setupPicker()
|
||||
setupModel()
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
|
||||
@ -10,7 +10,7 @@ import UIKit
|
||||
import VDS
|
||||
import VDSColorTokens
|
||||
|
||||
class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardInitable {
|
||||
class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
|
||||
deinit {
|
||||
print("\(Self.self) deinit")
|
||||
}
|
||||
@ -18,38 +18,72 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
||||
enum PickerType {
|
||||
case surface, textSize, fontCategory
|
||||
}
|
||||
|
||||
static var storyboardId: String = "label"
|
||||
static var storyboardName: String = "Components"
|
||||
|
||||
@IBOutlet weak var containerView: UIView!
|
||||
@IBOutlet weak var picker: UIPickerView!
|
||||
@IBOutlet weak var surfaceLabel: UILabel!
|
||||
@IBOutlet weak var textSizeLabel: UILabel!
|
||||
@IBOutlet weak var fontCategoryLabel: UILabel!
|
||||
@IBOutlet weak var boldswitch: UISwitch!
|
||||
@IBOutlet weak var disabledSwitch: UISwitch!
|
||||
@IBOutlet weak var textField: UITextField!
|
||||
var picker = UIPickerView()
|
||||
var surfacePickerSelectorView = PickerSelectorView(title: "")
|
||||
var textSizePickerSelectorView = PickerSelectorView(title: "")
|
||||
var fontCategoryPickerSelectorView = PickerSelectorView(title: "")
|
||||
var boldSwitch = UISwitch()
|
||||
var disabledSwitch = UISwitch()
|
||||
var textField = TextField()
|
||||
private var isBold: Bool = false
|
||||
|
||||
var label: Label!
|
||||
var label = Label()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
label = Label()
|
||||
label.translatesAutoresizingMaskIntoConstraints = false
|
||||
containerView.addSubview(label)
|
||||
label.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 20).isActive = true
|
||||
label.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 20).isActive = true
|
||||
label.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -20).isActive = true
|
||||
label.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -20).isActive = true
|
||||
|
||||
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
||||
addContentTopView(view: label)
|
||||
|
||||
setupForm()
|
||||
setupPicker()
|
||||
setupModel()
|
||||
}
|
||||
|
||||
func setupForm(){
|
||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||
addFormRow(label: "Bold", view: boldSwitch)
|
||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||
addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView)
|
||||
addFormRow(label: "Text Size", view: textSizePickerSelectorView)
|
||||
addFormRow(label: "Text", view: textField)
|
||||
|
||||
disabledSwitch
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] sender in
|
||||
self?.label.disabled = sender.isOn
|
||||
}.store(in: &subscribers)
|
||||
|
||||
boldSwitch
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] sender in
|
||||
self?.isBold = sender.isOn
|
||||
self?.updateLabelStyle()
|
||||
}.store(in: &subscribers)
|
||||
|
||||
surfacePickerSelectorView.button
|
||||
.publisher(for: .touchUpInside)
|
||||
.sink { [weak self] _ in
|
||||
self?.pickerType = .surface
|
||||
}.store(in: &subscribers)
|
||||
|
||||
fontCategoryPickerSelectorView.button
|
||||
.publisher(for: .touchUpInside)
|
||||
.sink { [weak self] _ in
|
||||
self?.pickerType = .fontCategory
|
||||
}.store(in: &subscribers)
|
||||
|
||||
textSizePickerSelectorView.button
|
||||
.publisher(for: .touchUpInside)
|
||||
.sink { [weak self] _ in
|
||||
self?.pickerType = .textSize
|
||||
}.store(in: &subscribers)
|
||||
|
||||
textField
|
||||
.textPublisher
|
||||
.sink { [weak self] text in
|
||||
self?.label.text = text
|
||||
}.store(in: &subscribers)
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
var defaultModel = DefaultLabelModel()
|
||||
defaultModel.text = "Label Component"
|
||||
@ -61,50 +95,24 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
||||
.sink { [weak self] viewModel in
|
||||
self?.model = viewModel
|
||||
}.store(in: &subscribers)
|
||||
|
||||
|
||||
//setup UI
|
||||
surfaceLabel.text = model.surface.rawValue
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
disabledSwitch.isOn = model.disabled
|
||||
boldswitch.isOn = isBold
|
||||
boldSwitch.isOn = isBold
|
||||
textField.text = model.text
|
||||
|
||||
//set the font
|
||||
fontCategory = .feature
|
||||
fontCategoryLabel.text = "Feature"
|
||||
fontCategoryPickerSelectorView.text = "Feature"
|
||||
textSize = .small
|
||||
textSizeLabel.text = "Small"
|
||||
textSizePickerSelectorView.text = "Small"
|
||||
}
|
||||
|
||||
override func updateView(viewModel: DefaultLabelModel) {
|
||||
label.set(with: viewModel)
|
||||
}
|
||||
|
||||
@IBAction func disabledChanged(_ sender: UISwitch) {
|
||||
label.isEnabled = !sender.isOn
|
||||
}
|
||||
|
||||
@IBAction func boldChanged(_ sender: UISwitch) {
|
||||
isBold = sender.isOn
|
||||
updateLabelStyle()
|
||||
}
|
||||
|
||||
@IBAction func textDidEnd(_ sender: UITextField) {
|
||||
label.text = sender.text?.replacingOccurrences(of: "\\n", with: "\n") ?? "Label Component"
|
||||
sender.resignFirstResponder()
|
||||
}
|
||||
|
||||
@IBAction func surfaceClick(_ sender: Any) {
|
||||
pickerType = .surface
|
||||
}
|
||||
|
||||
@IBAction func textSizeClick(_ sender: Any) {
|
||||
pickerType = .textSize
|
||||
}
|
||||
|
||||
@IBAction func fontCategoryClick(_ sender: Any) {
|
||||
pickerType = .fontCategory
|
||||
}
|
||||
|
||||
|
||||
//Picker
|
||||
var surfacePicker = SurfacePicker()
|
||||
var textSizePicker = TextSizePicker()
|
||||
@ -133,7 +141,7 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
||||
|
||||
private var fontCategory: TypographicalStyle.FontCategory = .feature {
|
||||
didSet {
|
||||
fontCategoryLabel.text = fontCategory.rawValue
|
||||
fontCategoryPickerSelectorView.text = fontCategory.rawValue
|
||||
textSizePicker.items = fontCategory.sizes
|
||||
if textSizePicker.items.count > 0 {
|
||||
textSize = textSizePicker.items[0]
|
||||
@ -146,7 +154,7 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
||||
|
||||
private var textSize: TypographicalStyle.FontSize? = .large {
|
||||
didSet {
|
||||
textSizeLabel.text = textSize?.rawValue ?? ""
|
||||
textSizePickerSelectorView.text = textSize?.rawValue ?? ""
|
||||
updateLabelStyle()
|
||||
}
|
||||
|
||||
@ -159,11 +167,12 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
||||
}
|
||||
|
||||
func setupPicker(){
|
||||
contentStackView.addArrangedSubview(picker)
|
||||
picker.isHidden = true
|
||||
surfacePicker.onPickerDidSelect = { [weak self] item in
|
||||
self?.label.surface = item
|
||||
self?.containerView.backgroundColor = item.color
|
||||
self?.surfaceLabel.text = item.rawValue
|
||||
self?.contentTopView.backgroundColor = item.color
|
||||
self?.surfacePickerSelectorView.text = item.rawValue
|
||||
}
|
||||
|
||||
textSizePicker.onPickerDidSelect = { [weak self] item in
|
||||
|
||||
Loading…
Reference in New Issue
Block a user