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()
|
super.viewDidLoad()
|
||||||
addContentTopView(view: checkboxGroup)
|
addContentTopView(view: checkboxGroup)
|
||||||
|
|
||||||
|
setupForm()
|
||||||
|
setupPicker()
|
||||||
|
setupModel()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupForm() {
|
||||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
addFormRow(label: "Label Text", view: labelTextField)
|
addFormRow(label: "Label Text", view: labelTextField)
|
||||||
@ -67,15 +73,11 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
|||||||
self?.checkbox?.childText = text
|
self?.checkbox?.childText = text
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
|
||||||
surfacePickerSelectorView.button
|
surfacePickerSelectorView.button
|
||||||
.publisher(for: .touchUpInside)
|
.publisher(for: .touchUpInside)
|
||||||
.sink { [weak self] _ in
|
.sink { [weak self] _ in
|
||||||
self?.pickerType = .surface
|
self?.pickerType = .surface
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
setupPicker()
|
|
||||||
setupModel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupModel() {
|
func setupModel() {
|
||||||
|
|||||||
@ -31,6 +31,12 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
|||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
addContentTopView(view: checkbox)
|
addContentTopView(view: checkbox)
|
||||||
|
|
||||||
|
setupForm()
|
||||||
|
setupPicker()
|
||||||
|
setupModel()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupForm(){
|
||||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
addFormRow(label: "Label Text", view: labelTextField)
|
addFormRow(label: "Label Text", view: labelTextField)
|
||||||
@ -80,9 +86,6 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
|||||||
.sink { [weak self] _ in
|
.sink { [weak self] _ in
|
||||||
self?.pickerType = .surface
|
self?.pickerType = .surface
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
setupPicker()
|
|
||||||
setupModel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupModel() {
|
func setupModel() {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import UIKit
|
|||||||
import VDS
|
import VDS
|
||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
|
|
||||||
class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardInitable {
|
class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
|
||||||
deinit {
|
deinit {
|
||||||
print("\(Self.self) deinit")
|
print("\(Self.self) deinit")
|
||||||
}
|
}
|
||||||
@ -18,38 +18,72 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
|||||||
enum PickerType {
|
enum PickerType {
|
||||||
case surface, textSize, fontCategory
|
case surface, textSize, fontCategory
|
||||||
}
|
}
|
||||||
|
var picker = UIPickerView()
|
||||||
static var storyboardId: String = "label"
|
var surfacePickerSelectorView = PickerSelectorView(title: "")
|
||||||
static var storyboardName: String = "Components"
|
var textSizePickerSelectorView = PickerSelectorView(title: "")
|
||||||
|
var fontCategoryPickerSelectorView = PickerSelectorView(title: "")
|
||||||
@IBOutlet weak var containerView: UIView!
|
var boldSwitch = UISwitch()
|
||||||
@IBOutlet weak var picker: UIPickerView!
|
var disabledSwitch = UISwitch()
|
||||||
@IBOutlet weak var surfaceLabel: UILabel!
|
var textField = TextField()
|
||||||
@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!
|
|
||||||
private var isBold: Bool = false
|
private var isBold: Bool = false
|
||||||
|
|
||||||
var label: Label!
|
var label = Label()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
addContentTopView(view: label)
|
||||||
label = Label()
|
|
||||||
label.translatesAutoresizingMaskIntoConstraints = false
|
setupForm()
|
||||||
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(_:))))
|
|
||||||
setupPicker()
|
setupPicker()
|
||||||
setupModel()
|
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() {
|
func setupModel() {
|
||||||
var defaultModel = DefaultLabelModel()
|
var defaultModel = DefaultLabelModel()
|
||||||
defaultModel.text = "Label Component"
|
defaultModel.text = "Label Component"
|
||||||
@ -61,50 +95,24 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
|||||||
.sink { [weak self] viewModel in
|
.sink { [weak self] viewModel in
|
||||||
self?.model = viewModel
|
self?.model = viewModel
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//setup UI
|
//setup UI
|
||||||
surfaceLabel.text = model.surface.rawValue
|
surfacePickerSelectorView.text = model.surface.rawValue
|
||||||
disabledSwitch.isOn = model.disabled
|
disabledSwitch.isOn = model.disabled
|
||||||
boldswitch.isOn = isBold
|
boldSwitch.isOn = isBold
|
||||||
textField.text = model.text
|
textField.text = model.text
|
||||||
|
|
||||||
//set the font
|
//set the font
|
||||||
fontCategory = .feature
|
fontCategory = .feature
|
||||||
fontCategoryLabel.text = "Feature"
|
fontCategoryPickerSelectorView.text = "Feature"
|
||||||
textSize = .small
|
textSize = .small
|
||||||
textSizeLabel.text = "Small"
|
textSizePickerSelectorView.text = "Small"
|
||||||
}
|
}
|
||||||
|
|
||||||
override func updateView(viewModel: DefaultLabelModel) {
|
override func updateView(viewModel: DefaultLabelModel) {
|
||||||
label.set(with: viewModel)
|
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
|
//Picker
|
||||||
var surfacePicker = SurfacePicker()
|
var surfacePicker = SurfacePicker()
|
||||||
var textSizePicker = TextSizePicker()
|
var textSizePicker = TextSizePicker()
|
||||||
@ -133,7 +141,7 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
|||||||
|
|
||||||
private var fontCategory: TypographicalStyle.FontCategory = .feature {
|
private var fontCategory: TypographicalStyle.FontCategory = .feature {
|
||||||
didSet {
|
didSet {
|
||||||
fontCategoryLabel.text = fontCategory.rawValue
|
fontCategoryPickerSelectorView.text = fontCategory.rawValue
|
||||||
textSizePicker.items = fontCategory.sizes
|
textSizePicker.items = fontCategory.sizes
|
||||||
if textSizePicker.items.count > 0 {
|
if textSizePicker.items.count > 0 {
|
||||||
textSize = textSizePicker.items[0]
|
textSize = textSizePicker.items[0]
|
||||||
@ -146,7 +154,7 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
|||||||
|
|
||||||
private var textSize: TypographicalStyle.FontSize? = .large {
|
private var textSize: TypographicalStyle.FontSize? = .large {
|
||||||
didSet {
|
didSet {
|
||||||
textSizeLabel.text = textSize?.rawValue ?? ""
|
textSizePickerSelectorView.text = textSize?.rawValue ?? ""
|
||||||
updateLabelStyle()
|
updateLabelStyle()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,11 +167,12 @@ class LabelViewController: ModelViewController<DefaultLabelModel>, StoryboardIni
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupPicker(){
|
func setupPicker(){
|
||||||
|
contentStackView.addArrangedSubview(picker)
|
||||||
picker.isHidden = true
|
picker.isHidden = true
|
||||||
surfacePicker.onPickerDidSelect = { [weak self] item in
|
surfacePicker.onPickerDidSelect = { [weak self] item in
|
||||||
self?.label.surface = item
|
self?.label.surface = item
|
||||||
self?.containerView.backgroundColor = item.color
|
self?.contentTopView.backgroundColor = item.color
|
||||||
self?.surfaceLabel.text = item.rawValue
|
self?.surfacePickerSelectorView.text = item.rawValue
|
||||||
}
|
}
|
||||||
|
|
||||||
textSizePicker.onPickerDidSelect = { [weak self] item in
|
textSizePicker.onPickerDidSelect = { [weak self] item in
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user