updated to use a numeric field
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
7d0fe4c306
commit
73c5ae8114
@ -9,34 +9,47 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
import VDS
|
import VDS
|
||||||
|
|
||||||
class TextField: UITextField {
|
public class TextField: UITextField {
|
||||||
var textPadding = UIEdgeInsets(
|
public var isNumeric: Bool = false
|
||||||
|
|
||||||
|
public var textPadding = UIEdgeInsets(
|
||||||
top: 10,
|
top: 10,
|
||||||
left: 10,
|
left: 10,
|
||||||
bottom: 10,
|
bottom: 10,
|
||||||
right: 10
|
right: 10
|
||||||
)
|
)
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
font = TypographicalStyle.BodyLarge.font
|
font = TypographicalStyle.BodyLarge.font
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
public required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override func textRect(forBounds bounds: CGRect) -> CGRect {
|
public override func textRect(forBounds bounds: CGRect) -> CGRect {
|
||||||
layer.borderColor = UIColor.black.cgColor
|
layer.borderColor = UIColor.black.cgColor
|
||||||
layer.borderWidth = 1
|
layer.borderWidth = 1
|
||||||
let rect = super.textRect(forBounds: bounds)
|
let rect = super.textRect(forBounds: bounds)
|
||||||
return rect.inset(by: textPadding)
|
return rect.inset(by: textPadding)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func editingRect(forBounds bounds: CGRect) -> CGRect {
|
public override func editingRect(forBounds bounds: CGRect) -> CGRect {
|
||||||
layer.borderColor = UIColor.black.cgColor
|
layer.borderColor = UIColor.black.cgColor
|
||||||
layer.borderWidth = 1
|
layer.borderWidth = 1
|
||||||
let rect = super.editingRect(forBounds: bounds)
|
let rect = super.editingRect(forBounds: bounds)
|
||||||
return rect.inset(by: textPadding)
|
return rect.inset(by: textPadding)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class NumericField: TextField {
|
||||||
|
public override init(frame: CGRect) {
|
||||||
|
super.init(frame: frame)
|
||||||
|
isNumeric = true
|
||||||
|
}
|
||||||
|
|
||||||
|
public required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -50,10 +50,10 @@ class BadgeViewController: BaseViewController {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
var textField = TextField()
|
var textField = TextField()
|
||||||
var maxWidthTextField = TextField()
|
var maxWidthTextField = NumericField()
|
||||||
var badge = Badge()
|
var badge = Badge()
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [textField, maxWidthTextField] }
|
override func allTextFields() -> [TextField]? { [textField, maxWidthTextField] }
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|||||||
@ -188,8 +188,23 @@ public class BaseViewController: UIViewController, Initable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open func setup() {
|
open func setup() {
|
||||||
|
|
||||||
if let textFields = allTextFields() {
|
if let textFields = allTextFields() {
|
||||||
for textField in textFields {
|
for textField in textFields {
|
||||||
|
if textField.isNumeric {
|
||||||
|
let keypadToolbar: UIToolbar = UIToolbar()
|
||||||
|
|
||||||
|
// add a done button to the numberpad
|
||||||
|
keypadToolbar.items=[
|
||||||
|
UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: self, action: nil),
|
||||||
|
UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: textField, action: #selector(UITextField.resignFirstResponder))
|
||||||
|
]
|
||||||
|
keypadToolbar.sizeToFit()
|
||||||
|
|
||||||
|
// add a toolbar with a done button above the number pad
|
||||||
|
textField.inputAccessoryView = keypadToolbar
|
||||||
|
textField.keyboardType = .numberPad
|
||||||
|
}
|
||||||
textField.returnKeyType = .done
|
textField.returnKeyType = .done
|
||||||
textField
|
textField
|
||||||
.publisher(for: .editingDidEndOnExit)
|
.publisher(for: .editingDidEndOnExit)
|
||||||
@ -205,5 +220,5 @@ public class BaseViewController: UIViewController, Initable {
|
|||||||
print("\(Self.self) updateView()")
|
print("\(Self.self) updateView()")
|
||||||
}
|
}
|
||||||
|
|
||||||
open func allTextFields() -> [UITextField]? { nil }
|
open func allTextFields() -> [TextField]? { nil }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,15 +61,15 @@ class ButtonGroupViewController: BaseViewController {
|
|||||||
|
|
||||||
var label = Label()
|
var label = Label()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
var widthTextField = TextField()
|
var widthTextField = NumericField()
|
||||||
var percentageTextField = TextField()
|
var percentageTextField = NumericField()
|
||||||
|
|
||||||
let largeButtonGroup = ButtonGroup()
|
let largeButtonGroup = ButtonGroup()
|
||||||
let smallButtonGroup = ButtonGroup()
|
let smallButtonGroup = ButtonGroup()
|
||||||
let largeLabel = Label().with{ $0.text = "Large Button Group"; $0.typograpicalStyle = .BoldTitleSmall }
|
let largeLabel = Label().with{ $0.text = "Large Button Group"; $0.typograpicalStyle = .BoldTitleSmall }
|
||||||
let smallLabel = Label().with{ $0.text = "Small Button Group"; $0.typograpicalStyle = .BoldTitleSmall }
|
let smallLabel = Label().with{ $0.text = "Small Button Group"; $0.typograpicalStyle = .BoldTitleSmall }
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [widthTextField, percentageTextField] }
|
override func allTextFields() -> [TextField]? { [widthTextField, percentageTextField] }
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class ButtonViewController: BaseViewController {
|
|||||||
var label = Label()
|
var label = Label()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
var textField = TextField()
|
var textField = TextField()
|
||||||
var widthTextField = TextField()
|
var widthTextField = NumericField()
|
||||||
|
|
||||||
var button: Button!
|
var button: Button!
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class ButtonViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [textField, widthTextField] }
|
override func allTextFields() -> [TextField]? { [textField, widthTextField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
addFormRow(label: "Button Action", view: label)
|
addFormRow(label: "Button Action", view: label)
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class CheckboxGroupViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [labelTextField, childTextField] }
|
override func allTextFields() -> [TextField]? { [labelTextField, childTextField] }
|
||||||
|
|
||||||
func setupForm() {
|
func setupForm() {
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class CheckboxViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [labelTextField, childTextField, errorTextField] }
|
override func allTextFields() -> [TextField]? { [labelTextField, childTextField, errorTextField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class LabelViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [textField] }
|
override func allTextFields() -> [TextField]? { [textField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class RadioBoxGroupViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [textField, subTextField, subTextRightField] }
|
override func allTextFields() -> [TextField]? { [textField, subTextField, subTextRightField] }
|
||||||
|
|
||||||
func setupForm() {
|
func setupForm() {
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class RadioButtonViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [labelTextField, childTextField] }
|
override func allTextFields() -> [TextField]? { [labelTextField, childTextField] }
|
||||||
|
|
||||||
func setupForm() {
|
func setupForm() {
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class TextEntryFieldViewController: BaseViewController {
|
|||||||
var errorTextField = TextField()
|
var errorTextField = TextField()
|
||||||
var successTextField = TextField()
|
var successTextField = TextField()
|
||||||
var helperTextField = TextField()
|
var helperTextField = TextField()
|
||||||
var widthTextField = TextField()
|
var widthTextField = NumericField()
|
||||||
var showErrorSwitch = Toggle()
|
var showErrorSwitch = Toggle()
|
||||||
var showSuccessSwitch = Toggle()
|
var showSuccessSwitch = Toggle()
|
||||||
var tooltipTitleTextField = TextField()
|
var tooltipTitleTextField = TextField()
|
||||||
@ -41,7 +41,7 @@ class TextEntryFieldViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [labelTextField, errorTextField, successTextField, helperTextField, widthTextField, tooltipTitleTextField, tooltipContentTextField] }
|
override func allTextFields() -> [TextField]? { [labelTextField, errorTextField, successTextField, helperTextField, widthTextField, tooltipTitleTextField, tooltipContentTextField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class TextLinkCaretViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [textField] }
|
override func allTextFields() -> [TextField]? { [textField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
addFormRow(label: "Button Action", view: label)
|
addFormRow(label: "Button Action", view: label)
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class TextLinkViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [textField] }
|
override func allTextFields() -> [TextField]? { [textField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
addFormRow(label: "Button Action", view: label)
|
addFormRow(label: "Button Action", view: label)
|
||||||
|
|||||||
@ -37,8 +37,8 @@ class TileContainerViewController: BaseViewController {
|
|||||||
var showBackgroundImageSwitch = Toggle()
|
var showBackgroundImageSwitch = Toggle()
|
||||||
var showBorderSwitch = Toggle()
|
var showBorderSwitch = Toggle()
|
||||||
var showDropShadowSwitch = Toggle()
|
var showDropShadowSwitch = Toggle()
|
||||||
var heightTextField = TextField()
|
var heightTextField = NumericField()
|
||||||
var widthTextField = TextField()
|
var widthTextField = NumericField()
|
||||||
|
|
||||||
var tileContainer = TileContainer()
|
var tileContainer = TileContainer()
|
||||||
var backgroundImage = UIImage(named: "backgroundTest")!
|
var backgroundImage = UIImage(named: "backgroundTest")!
|
||||||
@ -52,7 +52,7 @@ class TileContainerViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [widthTextField, heightTextField] }
|
override func allTextFields() -> [TextField]? { [widthTextField, heightTextField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
formStackView.addArrangedSubview(Label().with{
|
formStackView.addArrangedSubview(Label().with{
|
||||||
|
|||||||
@ -32,9 +32,9 @@ class TiletViewController: BaseViewController {
|
|||||||
|
|
||||||
var titleTextField = TextField()
|
var titleTextField = TextField()
|
||||||
var subTitleTextField = TextField()
|
var subTitleTextField = TextField()
|
||||||
var widthTextField = TextField()
|
var widthTextField = NumericField()
|
||||||
var textPercentageTextField = TextField()
|
var textPercentageTextField = NumericField()
|
||||||
var textWidthTextField = TextField()
|
var textWidthTextField = NumericField()
|
||||||
|
|
||||||
var tilet = Tilet()
|
var tilet = Tilet()
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ class TiletViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [titleTextField, subTitleTextField, widthTextField, textWidthTextField, textPercentageTextField] }
|
override func allTextFields() -> [TextField]? { [titleTextField, subTitleTextField, widthTextField, textWidthTextField, textPercentageTextField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class TitleLockupViewController: BaseViewController {
|
|||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [eyebrowTextField, titleTextField, subTitleTextField] }
|
override func allTextFields() -> [TextField]? { [eyebrowTextField, titleTextField, subTitleTextField] }
|
||||||
|
|
||||||
func setupForm(){
|
func setupForm(){
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
|
|||||||
@ -52,7 +52,7 @@ class ToggleViewController: BaseViewController {
|
|||||||
setupPicker()
|
setupPicker()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func allTextFields() -> [UITextField]? { [onTextField, offTextField] }
|
override func allTextFields() -> [TextField]? { [onTextField, offTextField] }
|
||||||
|
|
||||||
func setupForm() {
|
func setupForm() {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user