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
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal var inputFieldStackView: UIStackView = {
|
internal var inputFieldStackView: UIStackView = {
|
||||||
return UIStackView().with {
|
return UIStackView().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.axis = .horizontal
|
$0.axis = .horizontal
|
||||||
@ -77,9 +77,11 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
/// Representing the type of input.
|
/// Representing the type of input.
|
||||||
open var fieldType: FieldType = .text { didSet { setNeedsUpdate() } }
|
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.
|
/// The text of this TextField.
|
||||||
private var _text: String?
|
private var _text: String?
|
||||||
@ -155,12 +157,17 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 0)
|
minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 0)
|
||||||
minWidthConstraint?.isActive = true
|
minWidthConstraint?.isActive = true
|
||||||
|
|
||||||
controlContainerView.addSubview(textField)
|
// stackview for controls in EntryFieldBase.controlContainerView
|
||||||
textField
|
let controlStackView = UIStackView().with {
|
||||||
.pinTop()
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
.pinLeading()
|
$0.axis = .horizontal
|
||||||
.pinTrailingLessThanOrEqualTo(nil, 0, .defaultHigh)
|
$0.spacing = VDSLayout.space3X
|
||||||
.pinBottom(0, .defaultHigh)
|
}
|
||||||
|
controlContainerView.addSubview(controlStackView)
|
||||||
|
controlStackView.pinToSuperView()
|
||||||
|
|
||||||
|
controlStackView.addArrangedSubview(leftIcon)
|
||||||
|
controlStackView.addArrangedSubview(textField)
|
||||||
|
|
||||||
textField.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
textField.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
||||||
textField
|
textField
|
||||||
@ -211,15 +218,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
textField.isEnabled = isEnabled
|
textField.isEnabled = isEnabled
|
||||||
textField.textColor = textFieldTextColorConfiguration.getColor(self)
|
textField.textColor = textFieldTextColorConfiguration.getColor(self)
|
||||||
|
|
||||||
if let actionTextLinkModel {
|
updateFieldType()
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
//show error or success
|
//show error or success
|
||||||
if showError, let _ = errorText {
|
if showError, let _ = errorText {
|
||||||
@ -231,25 +230,14 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
successLabel.isEnabled = isEnabled
|
successLabel.isEnabled = isEnabled
|
||||||
successLabel.isHidden = false
|
successLabel.isHidden = false
|
||||||
errorLabel.isHidden = true
|
errorLabel.isHidden = true
|
||||||
icon.name = .checkmarkAlt
|
statusIcon.name = .checkmarkAlt
|
||||||
icon.color = VDSColor.paletteBlack
|
statusIcon.color = VDSColor.paletteBlack
|
||||||
icon.surface = surface
|
statusIcon.surface = surface
|
||||||
icon.isHidden = !isEnabled
|
statusIcon.isHidden = !isEnabled
|
||||||
} else {
|
} else {
|
||||||
icon.isHidden = true
|
statusIcon.isHidden = true
|
||||||
successLabel.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(){
|
open override func updateHelperLabel(){
|
||||||
@ -272,25 +260,75 @@ open class InputField: EntryFieldBase, UITextFieldDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
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
|
||||||
|
|
||||||
extension InputField.FieldType {
|
|
||||||
var width: CGFloat {
|
|
||||||
switch self {
|
|
||||||
case .inlineAction:
|
case .inlineAction:
|
||||||
return 102
|
minWidth = 102.0
|
||||||
|
|
||||||
case .password:
|
case .password:
|
||||||
return 62.0
|
textField.isSecureTextEntry = true
|
||||||
|
minWidth = 62.0
|
||||||
|
|
||||||
case .creditCard:
|
case .creditCard:
|
||||||
return 288.0
|
minWidth = 288.0
|
||||||
|
|
||||||
case .tel:
|
case .tel:
|
||||||
return 176.0
|
minWidth = 176.0
|
||||||
|
|
||||||
case .date:
|
case .date:
|
||||||
return 114.0
|
minWidth = 114.0
|
||||||
|
|
||||||
case .securityCode:
|
case .securityCode:
|
||||||
return 88.0
|
minWidth = 88.0
|
||||||
default:
|
|
||||||
return 40.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