refactored tooltip for securityCode
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
4a337c6fcb
commit
84314040d9
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import VDSTokens
|
||||||
|
|
||||||
extension InputField {
|
extension InputField {
|
||||||
|
|
||||||
@ -32,14 +33,73 @@ extension InputField {
|
|||||||
override func updateView(_ inputField: InputField) {
|
override func updateView(_ inputField: InputField) {
|
||||||
minWidth = 88.0
|
minWidth = 88.0
|
||||||
isSecureTextEntry = true
|
isSecureTextEntry = true
|
||||||
|
toolTipModel = getToolTip(inputField)
|
||||||
let title: String = inputField.cardType.rawValue
|
|
||||||
let content: String = "looking for \(inputField.cardType.securityCodeLength) digits"
|
|
||||||
toolTipModel = .init(title: title, content: content)
|
|
||||||
|
|
||||||
super.updateView(inputField)
|
super.updateView(inputField)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getToolTip(_ inputField: InputField) -> Tooltip.TooltipModel {
|
||||||
|
|
||||||
|
let surface = inputField.surface
|
||||||
|
|
||||||
|
var contentView: UIView
|
||||||
|
var code3Label = Label().with {
|
||||||
|
$0.text = "Most credit or debit cards have a 3-digit security code on the back."
|
||||||
|
$0.isEnabled = true
|
||||||
|
$0.surface = surface
|
||||||
|
}
|
||||||
|
var code4Label = Label().with {
|
||||||
|
$0.text = "American Express cards have a 4-digit code on the front."
|
||||||
|
$0.isEnabled = true
|
||||||
|
$0.surface = surface
|
||||||
|
}
|
||||||
|
|
||||||
|
var code3ImageView = UIImageView().with {
|
||||||
|
$0.image = BundleManager.shared.image(for: "securityCode\(surface == .dark ? "-inverted": "")")
|
||||||
|
}
|
||||||
|
var code4ImageView = UIImageView().with {
|
||||||
|
$0.image = BundleManager.shared.image(for: "securityCodeAmex\(surface == .dark ? "-inverted": "")")
|
||||||
|
}
|
||||||
|
|
||||||
|
func stack(_ axis: NSLayoutConstraint.Axis = .vertical) -> UIStackView {
|
||||||
|
UIStackView().with {
|
||||||
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
$0.axis = axis
|
||||||
|
$0.distribution = .fill
|
||||||
|
$0.alignment = .leading
|
||||||
|
$0.spacing = VDSLayout.space2X
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func view3() -> UIView {
|
||||||
|
stack().with {
|
||||||
|
$0.addArrangedSubview(code3ImageView)
|
||||||
|
$0.addArrangedSubview(code3Label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func view4() -> UIView {
|
||||||
|
stack().with {
|
||||||
|
$0.addArrangedSubview(code4ImageView)
|
||||||
|
$0.addArrangedSubview(code4Label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let title: String = inputField.cardType.rawValue
|
||||||
|
switch inputField.cardType {
|
||||||
|
case .amex:
|
||||||
|
contentView = view4()
|
||||||
|
case .generic:
|
||||||
|
contentView = stack(.horizontal).with {
|
||||||
|
$0.addArrangedSubview(view3())
|
||||||
|
$0.addArrangedSubview(view4())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
contentView = view3()
|
||||||
|
}
|
||||||
|
|
||||||
|
return .init(contentView: contentView)
|
||||||
|
}
|
||||||
|
|
||||||
override func textField(_ inputField: InputField, textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
override func textField(_ inputField: InputField, textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||||
// Allow only numbers and limit the length of text.
|
// Allow only numbers and limit the length of text.
|
||||||
let allowedCharacters = CharacterSet.decimalDigits
|
let allowedCharacters = CharacterSet.decimalDigits
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user