updated field types
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
e70d160619
commit
3bc2b18962
@ -20,7 +20,7 @@ extension InputField {
|
||||
case jcb
|
||||
case unionPay
|
||||
|
||||
func imageName(surface: Surface) -> String {
|
||||
public func imageName(surface: Surface) -> String {
|
||||
func getImageName(_ surface: Surface, name: String) -> String {
|
||||
return surface == .light ? name : "\(name)-inverted"
|
||||
}
|
||||
@ -98,12 +98,35 @@ extension InputField {
|
||||
self.keyboardType = .numberPad
|
||||
}
|
||||
|
||||
override func updateView(_ inputField: InputField) {
|
||||
minWidth = 288.0
|
||||
leftImageName = inputField.cardType.imageName(surface: inputField.surface)
|
||||
super.updateView(inputField)
|
||||
fileprivate func updateLeftImage(_ inputField: InputField) {
|
||||
let imageName = inputField.cardType.imageName(surface: inputField.surface)
|
||||
creditCardImageView.image = BundleManager.shared.image(for: imageName)
|
||||
}
|
||||
|
||||
override func updateView(_ inputField: InputField) {
|
||||
minWidth = 288.0
|
||||
super.updateView(inputField)
|
||||
|
||||
// Set the UIImageView as the left view of the UITextField
|
||||
let iconContainerView: UIView = UIView()
|
||||
iconContainerView.addSubview(creditCardImageView)
|
||||
creditCardImageView.pinToSuperView(.init(top: 0, left: 0, bottom: 0, right: 10))
|
||||
|
||||
inputField.textField.leftView = iconContainerView
|
||||
inputField.textField.leftViewMode = .always
|
||||
|
||||
updateLeftImage(inputField)
|
||||
}
|
||||
|
||||
internal var creditCardImageView = UIImageView().with {
|
||||
$0.height(20)
|
||||
$0.width(32)
|
||||
$0.isAccessibilityElement = false
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.contentMode = .scaleAspectFill
|
||||
$0.clipsToBounds = true
|
||||
}
|
||||
|
||||
override func appendRules(_ inputField: InputField) {
|
||||
if let text = inputField.textField.text, text.count > 0 {
|
||||
let rule = CharacterCountRule().copyWith {
|
||||
@ -120,6 +143,8 @@ extension InputField {
|
||||
value = nil
|
||||
inputField.cardType = .generic
|
||||
textField.text = ""
|
||||
inputField.validate()
|
||||
updateLeftImage(inputField)
|
||||
}
|
||||
|
||||
override func textFieldDidEndEditing(_ inputField: InputField, textField: UITextField) {
|
||||
@ -183,14 +208,12 @@ extension InputField {
|
||||
}
|
||||
|
||||
internal func updateCardTypeIcon(_ inputField: InputField, rawNumber: String) {
|
||||
defer { inputField.setNeedsUpdate() }
|
||||
|
||||
guard rawNumber.count >= 4 else {
|
||||
if rawNumber.count >= 4 {
|
||||
inputField.cardType = CreditCardType.from(cardNumber: rawNumber)
|
||||
} else {
|
||||
inputField.cardType = .generic
|
||||
return
|
||||
}
|
||||
|
||||
inputField.cardType = CreditCardType.from(cardNumber: rawNumber)
|
||||
updateLeftImage(inputField)
|
||||
}
|
||||
|
||||
internal func maskCreditCardNumber(_ cardType: CreditCardType, number: String) -> String {
|
||||
|
||||
@ -39,7 +39,6 @@ extension InputField {
|
||||
class FieldTypeHandler: NSObject {
|
||||
var keyboardType: UIKeyboardType
|
||||
var minWidth: CGFloat = 40.0
|
||||
var leftImageName: String?
|
||||
var actionModel: TextLinkModel?
|
||||
var toolTipModel: Tooltip.TooltipModel?
|
||||
var isSecureTextEntry = false
|
||||
@ -51,7 +50,7 @@ extension InputField {
|
||||
keyboardType = .default
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
||||
func updateView(_ inputField: InputField) {
|
||||
|
||||
//keyboard
|
||||
@ -59,15 +58,10 @@ extension InputField {
|
||||
|
||||
//textField
|
||||
inputField.textField.isSecureTextEntry = isSecureTextEntry
|
||||
|
||||
//leftIcon
|
||||
if let leftImageName {
|
||||
inputField.leftImageView.image = BundleManager.shared.image(for: leftImageName)
|
||||
}
|
||||
inputField.leftImageView.isHidden = leftImageName == nil
|
||||
|
||||
//actionLink
|
||||
inputField.actionTextLink.surface = inputField.surface
|
||||
inputField.actionTextLink.isEnabled = inputField.isEnabled
|
||||
if let actionModel {
|
||||
inputField.actionTextLink.text = actionModel.text
|
||||
inputField.actionTextLink.onClick = { _ in
|
||||
@ -88,6 +82,8 @@ extension InputField {
|
||||
if let toolTipModel {
|
||||
inputField.tooltipModel = toolTipModel
|
||||
}
|
||||
|
||||
inputField.textField.leftView = nil
|
||||
}
|
||||
|
||||
func appendRules(_ inputField: InputField) {}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user