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 jcb
|
||||||
case unionPay
|
case unionPay
|
||||||
|
|
||||||
func imageName(surface: Surface) -> String {
|
public func imageName(surface: Surface) -> String {
|
||||||
func getImageName(_ surface: Surface, name: String) -> String {
|
func getImageName(_ surface: Surface, name: String) -> String {
|
||||||
return surface == .light ? name : "\(name)-inverted"
|
return surface == .light ? name : "\(name)-inverted"
|
||||||
}
|
}
|
||||||
@ -98,12 +98,35 @@ extension InputField {
|
|||||||
self.keyboardType = .numberPad
|
self.keyboardType = .numberPad
|
||||||
}
|
}
|
||||||
|
|
||||||
override func updateView(_ inputField: InputField) {
|
fileprivate func updateLeftImage(_ inputField: InputField) {
|
||||||
minWidth = 288.0
|
let imageName = inputField.cardType.imageName(surface: inputField.surface)
|
||||||
leftImageName = inputField.cardType.imageName(surface: inputField.surface)
|
creditCardImageView.image = BundleManager.shared.image(for: imageName)
|
||||||
super.updateView(inputField)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
override func appendRules(_ inputField: InputField) {
|
||||||
if let text = inputField.textField.text, text.count > 0 {
|
if let text = inputField.textField.text, text.count > 0 {
|
||||||
let rule = CharacterCountRule().copyWith {
|
let rule = CharacterCountRule().copyWith {
|
||||||
@ -120,6 +143,8 @@ extension InputField {
|
|||||||
value = nil
|
value = nil
|
||||||
inputField.cardType = .generic
|
inputField.cardType = .generic
|
||||||
textField.text = ""
|
textField.text = ""
|
||||||
|
inputField.validate()
|
||||||
|
updateLeftImage(inputField)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func textFieldDidEndEditing(_ inputField: InputField, textField: UITextField) {
|
override func textFieldDidEndEditing(_ inputField: InputField, textField: UITextField) {
|
||||||
@ -183,14 +208,12 @@ extension InputField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal func updateCardTypeIcon(_ inputField: InputField, rawNumber: String) {
|
internal func updateCardTypeIcon(_ inputField: InputField, rawNumber: String) {
|
||||||
defer { inputField.setNeedsUpdate() }
|
if rawNumber.count >= 4 {
|
||||||
|
inputField.cardType = CreditCardType.from(cardNumber: rawNumber)
|
||||||
guard rawNumber.count >= 4 else {
|
} else {
|
||||||
inputField.cardType = .generic
|
inputField.cardType = .generic
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
updateLeftImage(inputField)
|
||||||
inputField.cardType = CreditCardType.from(cardNumber: rawNumber)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func maskCreditCardNumber(_ cardType: CreditCardType, number: String) -> String {
|
internal func maskCreditCardNumber(_ cardType: CreditCardType, number: String) -> String {
|
||||||
|
|||||||
@ -39,7 +39,6 @@ extension InputField {
|
|||||||
class FieldTypeHandler: NSObject {
|
class FieldTypeHandler: NSObject {
|
||||||
var keyboardType: UIKeyboardType
|
var keyboardType: UIKeyboardType
|
||||||
var minWidth: CGFloat = 40.0
|
var minWidth: CGFloat = 40.0
|
||||||
var leftImageName: String?
|
|
||||||
var actionModel: TextLinkModel?
|
var actionModel: TextLinkModel?
|
||||||
var toolTipModel: Tooltip.TooltipModel?
|
var toolTipModel: Tooltip.TooltipModel?
|
||||||
var isSecureTextEntry = false
|
var isSecureTextEntry = false
|
||||||
@ -51,7 +50,7 @@ extension InputField {
|
|||||||
keyboardType = .default
|
keyboardType = .default
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateView(_ inputField: InputField) {
|
func updateView(_ inputField: InputField) {
|
||||||
|
|
||||||
//keyboard
|
//keyboard
|
||||||
@ -59,15 +58,10 @@ extension InputField {
|
|||||||
|
|
||||||
//textField
|
//textField
|
||||||
inputField.textField.isSecureTextEntry = isSecureTextEntry
|
inputField.textField.isSecureTextEntry = isSecureTextEntry
|
||||||
|
|
||||||
//leftIcon
|
|
||||||
if let leftImageName {
|
|
||||||
inputField.leftImageView.image = BundleManager.shared.image(for: leftImageName)
|
|
||||||
}
|
|
||||||
inputField.leftImageView.isHidden = leftImageName == nil
|
|
||||||
|
|
||||||
//actionLink
|
//actionLink
|
||||||
inputField.actionTextLink.surface = inputField.surface
|
inputField.actionTextLink.surface = inputField.surface
|
||||||
|
inputField.actionTextLink.isEnabled = inputField.isEnabled
|
||||||
if let actionModel {
|
if let actionModel {
|
||||||
inputField.actionTextLink.text = actionModel.text
|
inputField.actionTextLink.text = actionModel.text
|
||||||
inputField.actionTextLink.onClick = { _ in
|
inputField.actionTextLink.onClick = { _ in
|
||||||
@ -88,6 +82,8 @@ extension InputField {
|
|||||||
if let toolTipModel {
|
if let toolTipModel {
|
||||||
inputField.tooltipModel = toolTipModel
|
inputField.tooltipModel = toolTipModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputField.textField.leftView = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendRules(_ inputField: InputField) {}
|
func appendRules(_ inputField: InputField) {}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user