initial rework for inputField
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
87389d02cc
commit
63de916555
@ -42,7 +42,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
internal var inputFieldStackView: UIStackView = {
|
||||
internal var inputFieldStackView: UIStackView = {
|
||||
return UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.axis = .horizontal
|
||||
@ -77,9 +77,11 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
||||
/// Representing the type of input.
|
||||
open var fieldType: FieldType = .text { didSet { setNeedsUpdate() } }
|
||||
|
||||
internal var actionTextLink = TextLink().with { $0.contentEdgeInsets = .top(-2) }
|
||||
open var leftIcon: Icon = Icon().with { $0.size = .medium }
|
||||
|
||||
internal var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } }
|
||||
open var actionTextLink = TextLink().with { $0.contentEdgeInsets = .top(-2) }
|
||||
|
||||
open var actionTextLinkModel: TextLinkModel? { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// The text of this TextField.
|
||||
private var _text: String?
|
||||
@ -155,13 +157,18 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
||||
minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 0)
|
||||
minWidthConstraint?.isActive = true
|
||||
|
||||
controlContainerView.addSubview(textField)
|
||||
textField
|
||||
.pinTop()
|
||||
.pinLeading()
|
||||
.pinTrailingLessThanOrEqualTo(nil, 0, .defaultHigh)
|
||||
.pinBottom(0, .defaultHigh)
|
||||
// stackview for controls in EntryFieldBase.controlContainerView
|
||||
let controlStackView = UIStackView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.axis = .horizontal
|
||||
$0.spacing = VDSLayout.space3X
|
||||
}
|
||||
controlContainerView.addSubview(controlStackView)
|
||||
controlStackView.pinToSuperView()
|
||||
|
||||
controlStackView.addArrangedSubview(leftIcon)
|
||||
controlStackView.addArrangedSubview(textField)
|
||||
|
||||
textField.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
||||
textField
|
||||
.textPublisher
|
||||
@ -210,16 +217,8 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
||||
|
||||
textField.isEnabled = isEnabled
|
||||
textField.textColor = textFieldTextColorConfiguration.getColor(self)
|
||||
|
||||
if let actionTextLinkModel {
|
||||
actionTextLink.text = actionTextLinkModel.text
|
||||
actionTextLink.onClick = actionTextLinkModel.onClick
|
||||
actionTextLink.isHidden = false
|
||||
containerStackView.setCustomSpacing(VDSLayout.space2X, after: icon)
|
||||
} else {
|
||||
actionTextLink.isHidden = true
|
||||
containerStackView.setCustomSpacing(0, after: icon)
|
||||
}
|
||||
|
||||
updateFieldType()
|
||||
|
||||
//show error or success
|
||||
if showError, let _ = errorText {
|
||||
@ -231,25 +230,14 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
||||
successLabel.isEnabled = isEnabled
|
||||
successLabel.isHidden = false
|
||||
errorLabel.isHidden = true
|
||||
icon.name = .checkmarkAlt
|
||||
icon.color = VDSColor.paletteBlack
|
||||
icon.surface = surface
|
||||
icon.isHidden = !isEnabled
|
||||
statusIcon.name = .checkmarkAlt
|
||||
statusIcon.color = VDSColor.paletteBlack
|
||||
statusIcon.surface = surface
|
||||
statusIcon.isHidden = !isEnabled
|
||||
} else {
|
||||
icon.isHidden = true
|
||||
statusIcon.isHidden = true
|
||||
successLabel.isHidden = true
|
||||
}
|
||||
|
||||
//set the width constraints
|
||||
if let width, width > fieldType.width {
|
||||
widthConstraint?.constant = width
|
||||
widthConstraint?.isActive = true
|
||||
minWidthConstraint?.isActive = false
|
||||
} else {
|
||||
minWidthConstraint?.constant = fieldType.width
|
||||
widthConstraint?.isActive = false
|
||||
minWidthConstraint?.isActive = true
|
||||
}
|
||||
}
|
||||
|
||||
open override func updateHelperLabel(){
|
||||
@ -272,25 +260,75 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension InputField.FieldType {
|
||||
var width: CGFloat {
|
||||
switch self {
|
||||
open func updateFieldType() {
|
||||
textField.isSecureTextEntry = false
|
||||
|
||||
var minWidth: CGFloat = 40.0
|
||||
var iconName: Icon.Name?
|
||||
var actionLinkModel: InputField.TextLinkModel?
|
||||
var toolTipModel: Tooltip.TooltipModel?
|
||||
|
||||
switch fieldType {
|
||||
case .text:
|
||||
break
|
||||
|
||||
case .number:
|
||||
break
|
||||
|
||||
case .calendar:
|
||||
break
|
||||
|
||||
case .inlineAction:
|
||||
return 102
|
||||
minWidth = 102.0
|
||||
|
||||
case .password:
|
||||
return 62.0
|
||||
textField.isSecureTextEntry = true
|
||||
minWidth = 62.0
|
||||
|
||||
case .creditCard:
|
||||
return 288.0
|
||||
minWidth = 288.0
|
||||
|
||||
case .tel:
|
||||
return 176.0
|
||||
minWidth = 176.0
|
||||
|
||||
case .date:
|
||||
return 114.0
|
||||
minWidth = 114.0
|
||||
|
||||
case .securityCode:
|
||||
return 88.0
|
||||
default:
|
||||
return 40.0
|
||||
minWidth = 88.0
|
||||
|
||||
}
|
||||
|
||||
//leftIcon
|
||||
leftIcon.surface = surface
|
||||
leftIcon.color = iconColorConfiguration.getColor(self)
|
||||
leftIcon.name = iconName
|
||||
leftIcon.isHidden = iconName == nil
|
||||
|
||||
//actionLink
|
||||
actionTextLink.surface = surface
|
||||
if let actionTextLinkModel = actionLinkModel {
|
||||
actionTextLink.text = actionTextLinkModel.text
|
||||
actionTextLink.accessibilityLabel = actionTextLinkModel.accessibleText
|
||||
actionTextLink.isHidden = false
|
||||
containerStackView.setCustomSpacing(VDSLayout.space2X, after: statusIcon)
|
||||
} else {
|
||||
actionTextLink.isHidden = true
|
||||
containerStackView.setCustomSpacing(0, after: statusIcon)
|
||||
}
|
||||
|
||||
//set the width constraints
|
||||
if let width, width > minWidth {
|
||||
widthConstraint?.constant = width
|
||||
widthConstraint?.isActive = true
|
||||
minWidthConstraint?.isActive = false
|
||||
} else {
|
||||
minWidthConstraint?.constant = minWidth
|
||||
widthConstraint?.isActive = false
|
||||
minWidthConstraint?.isActive = true
|
||||
}
|
||||
|
||||
//tooltip
|
||||
self.tooltipModel = toolTipModel
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user