diff --git a/VDS/Components/TextFields/InputField/FieldTypes/CreditCard.swift b/VDS/Components/TextFields/InputField/FieldTypes/CreditCard.swift
index 5c6c9a30..42441574 100644
--- a/VDS/Components/TextFields/InputField/FieldTypes/CreditCard.swift
+++ b/VDS/Components/TextFields/InputField/FieldTypes/CreditCard.swift
@@ -10,7 +10,7 @@ import UIKit
extension InputField {
- enum CreditCardType: CaseIterable {
+ public enum CreditCardType: CaseIterable {
case generic
case visa
case mastercard
@@ -18,23 +18,25 @@ extension InputField {
case discover
case dinersClub
case jcb
- case chinaUnionPay
+ case unionPay
- var imageName: String {
- var imageName: String = "generic"
- switch self {
- case .visa: imageName = "visa"
- case .mastercard: imageName = "mastercard"
- case .amex: imageName = "amex"
- case .discover: imageName = "discover"
- case .dinersClub: imageName = "dinersClub"
- case .jcb: imageName = "jcb"
- default: imageName = "generic"
+ func imageName(surface: Surface) -> String {
+ func getImageName(_ surface: Surface, name: String) -> String {
+ return surface == .light ? name : "\(name)-inverted"
+ }
+ switch self {
+ case .visa: return getImageName(surface, name: "visa")
+ case .mastercard: return "mastercard"
+ case .amex: return "amex"
+ case .discover: return "discover"
+ case .dinersClub: return "dinersClub"//getImageName(surface, name: "dinersClub")
+ case .jcb: return "jcb"
+ case .unionPay: return getImageName(surface, name: "unionPay")
+ default: return getImageName(surface, name: "generic")
}
- return imageName
}
- internal var separatorIndices: [Int] {
+ var separatorIndices: [Int] {
switch self {
case .dinersClub:
return [4, 10]
@@ -43,7 +45,7 @@ extension InputField {
}
}
- internal var maxLength: Int {
+ var maxLength: Int {
switch self {
case .dinersClub: return 14
default: return 16
@@ -65,7 +67,7 @@ extension InputField {
case 3528...3589:
return .jcb
case 6200...6299, 6000...6010, 8100...8199:
- return .chinaUnionPay
+ return .unionPay
default:
return nil
}
@@ -75,8 +77,6 @@ extension InputField {
class CreditCardHandler: FieldTypeHandler {
static let shared = CreditCardHandler()
- var creditCardType: CreditCardType = .generic
-
private override init() {
super.init()
self.keyboardType = .numberPad
@@ -84,7 +84,7 @@ extension InputField {
override func updateView(_ inputField: InputField) {
minWidth = 288.0
- leftImageName = creditCardType.imageName
+ leftImageName = inputField.cardType.imageName(surface: inputField.surface)
super.updateView(inputField)
}
@@ -92,7 +92,7 @@ extension InputField {
override func appendRules(_ inputField: InputField) {
if let text = inputField.textField.text, text.count > 0 {
let rule = CharacterCountRule().copyWith {
- $0.maxLength = creditCardType.maxLength
+ $0.maxLength = inputField.cardType.maxLength
$0.compareType = .equals
$0.errorMessage = "Enter a valid credit card."
}
@@ -101,14 +101,15 @@ extension InputField {
}
override func textFieldDidBeginEditing(_ inputField: InputField, textField: UITextField) {
- if let value {
- textField.text = formatCreditCardNumber(value)
- }
+ //reset the textField when you start editing
+ value = nil
+ inputField.cardType = .generic
+ textField.text = ""
}
override func textFieldDidEndEditing(_ inputField: InputField, textField: UITextField) {
if let value {
- textField.text = maskCreditCardNumber(value)
+ textField.text = maskCreditCardNumber(inputField.cardType, number: value)
}
}
@@ -127,18 +128,18 @@ extension InputField {
// Remove any existing formatting
let rawNumber = newText.filter { $0.isNumber }
- if rawNumber.count > creditCardType.maxLength {
+ if rawNumber.count > inputField.cardType.maxLength {
return false
}
// Format the number with spaces
- let formattedNumber = formatCreditCardNumber(rawNumber)
+ let formattedNumber = formatCreditCardNumber(inputField.cardType, number: rawNumber)
// Update the icon based on the first four digits
updateCardTypeIcon(inputField, rawNumber: rawNumber)
// Check again
- if rawNumber.count > creditCardType.maxLength {
+ if rawNumber.count > inputField.cardType.maxLength {
return false
}
@@ -161,9 +162,9 @@ extension InputField {
}
/// Private
- internal func formatCreditCardNumber(_ number: String) -> String {
+ internal func formatCreditCardNumber(_ cardType: CreditCardType, number: String) -> String {
let formattedInput = number.filter { $0.isNumber } // Remove any existing slashes
- return String.format(formattedInput, indices: creditCardType.separatorIndices, with: " ")
+ return String.format(formattedInput, indices: cardType.separatorIndices, with: " ")
}
internal func updateCardTypeIcon(_ inputField: InputField, rawNumber: String) {
@@ -172,20 +173,20 @@ extension InputField {
guard rawNumber.count >= 4,
let firstFourDigits = Int(String(rawNumber.prefix(4))),
let creditCardType = CreditCardType.from(iin: firstFourDigits) else {
- creditCardType = .generic
+ inputField.cardType = .generic
return
}
- self.creditCardType = creditCardType
+ inputField.cardType = creditCardType
}
- internal func maskCreditCardNumber(_ number: String) -> String {
+ internal func maskCreditCardNumber(_ cardType: CreditCardType, number: String) -> String {
// Mask the first 12 characters if the length is 16
let rawNumber = number.filter { $0.isNumber }
- guard rawNumber.count == creditCardType.maxLength else { return formatCreditCardNumber(number) }
+ guard rawNumber.count == cardType.maxLength else { return formatCreditCardNumber(cardType, number: number) }
let lastFourDigits = rawNumber.suffix(4)
let maskedSection = String(repeating: "•", count: 12)
- let formattedMaskSection = String.format(maskedSection, indices: creditCardType.separatorIndices, with: " ")
+ let formattedMaskSection = String.format(maskedSection, indices: cardType.separatorIndices, with: " ")
return formattedMaskSection + " " + lastFourDigits
}
}
diff --git a/VDS/Components/TextFields/InputField/FieldTypes/FieldType.swift b/VDS/Components/TextFields/InputField/FieldTypes/FieldType.swift
index 3fa3e652..ed5f7e30 100644
--- a/VDS/Components/TextFields/InputField/FieldTypes/FieldType.swift
+++ b/VDS/Components/TextFields/InputField/FieldTypes/FieldType.swift
@@ -58,7 +58,7 @@ extension InputField {
//leftIcon
if let leftImageName {
- inputField.leftImageView.image = BundleManager.shared.image(for: leftImageName)?.withTintColor(inputField.iconColorConfiguration.getColor(inputField))
+ inputField.leftImageView.image = BundleManager.shared.image(for: leftImageName)
}
inputField.leftImageView.isHidden = leftImageName == nil
diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift
index bebeec13..6307898f 100644
--- a/VDS/Components/TextFields/InputField/InputField.swift
+++ b/VDS/Components/TextFields/InputField/InputField.swift
@@ -45,6 +45,32 @@ open class InputField: EntryFieldBase {
internal var minWidthConstraint: NSLayoutConstraint?
+ //--------------------------------------------------
+ // MARK: - Public FieldType Properties
+ //--------------------------------------------------
+ /// Representing the type of input.
+ open var fieldType: FieldType = .text { didSet { setNeedsUpdate() } }
+
+ //--------------------------------------------------
+ // MARK: - CreditCard/SecurityCode
+ //--------------------------------------------------
+ open var cardType: CreditCardType = .generic { didSet { setNeedsUpdate() } }
+ //--------------------------------------------------
+ // MARK: - Password
+ //--------------------------------------------------
+
+ /// This is the text that will be displayed when the password is unmasked.
+ open var hidePasswordButtonText: String = "Hide" { didSet { setNeedsUpdate() } }
+
+ /// This is the text that will be displayed when the password is masked.
+ open var showPasswordButtonText: String = "Show" { didSet { setNeedsUpdate() } }
+
+ //--------------------------------------------------
+ // MARK: - Date
+ //--------------------------------------------------
+ /// Date Format used when using the FieldType 'Date'.
+ open var dateFormat: DateFormat = .mmddyy { didSet { setNeedsUpdate() } }
+
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
@@ -66,10 +92,14 @@ open class InputField: EntryFieldBase {
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
}.eraseToAnyColorable()
- /// Representing the type of input.
- open var fieldType: FieldType = .text { didSet { setNeedsUpdate() } }
-
- open var leftImageView = UIImageView().with { $0.height(21); $0.width(32) }
+ open var leftImageView = UIImageView().with {
+ $0.height(21)
+ $0.width(32)
+ $0.isAccessibilityElement = false
+ $0.translatesAutoresizingMaskIntoConstraints = false
+ $0.contentMode = .scaleAspectFill
+ $0.clipsToBounds = true
+ }
open var actionTextLink = TextLink().with { $0.contentEdgeInsets = .top(-2) }
@@ -297,22 +327,6 @@ open class InputField: EntryFieldBase {
}
return super.resignFirstResponder()
}
-
- //--------------------------------------------------
- // MARK: - Public FieldType Properties
- //--------------------------------------------------
-
- //--------------------------------------------------
- // MARK: - Password
- //--------------------------------------------------
- open var hidePasswordButtonText: String = "Hide" { didSet { setNeedsUpdate() } }
- open var showPasswordButtonText: String = "Show" { didSet { setNeedsUpdate() } }
-
- //--------------------------------------------------
- // MARK: - Date
- //--------------------------------------------------
- open var dateFormat: DateFormat = .mmddyy { didSet { setNeedsUpdate() } }
-
}
extension InputField: UITextFieldDelegate {
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/credit-card.imageset/credit-card.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/credit-card.imageset/credit-card.svg
deleted file mode 100644
index a5975ebf..00000000
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/credit-card.imageset/credit-card.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/Contents.json b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/Contents.json
index 01c460d2..6c8a6fee 100644
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/Contents.json
+++ b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/Contents.json
@@ -1,7 +1,7 @@
{
"images" : [
{
- "filename" : "dinersClub-inverted.svg",
+ "filename" : "DCI_Horizontal-2_onlight.svg",
"idiom" : "universal"
}
],
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/DCI_Horizontal-2_onlight.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/DCI_Horizontal-2_onlight.svg
new file mode 100644
index 00000000..569a32c0
--- /dev/null
+++ b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/DCI_Horizontal-2_onlight.svg
@@ -0,0 +1,819 @@
+
+
+
+
+
+
+
+
+
+
+]>
+
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/dinersClub-inverted.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/dinersClub-inverted.svg
deleted file mode 100644
index 1c8b4ccc..00000000
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub-inverted.imageset/dinersClub-inverted.svg
+++ /dev/null
@@ -1,196 +0,0 @@
-
\ No newline at end of file
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/Contents.json b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/Contents.json
index 32adfd39..52f90f68 100644
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/Contents.json
+++ b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/Contents.json
@@ -1,7 +1,7 @@
{
"images" : [
{
- "filename" : "dinersClub.svg",
+ "filename" : "DCI_Horizontal-2_ondark.svg",
"idiom" : "universal"
}
],
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/DCI_Horizontal-2_ondark.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/DCI_Horizontal-2_ondark.svg
new file mode 100644
index 00000000..98d7569b
--- /dev/null
+++ b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/DCI_Horizontal-2_ondark.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/dinersClub.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/dinersClub.svg
deleted file mode 100644
index 083ed5af..00000000
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/dinersClub.imageset/dinersClub.svg
+++ /dev/null
@@ -1,196 +0,0 @@
-
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder-inverted.imageset/placeholder-inverted.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder-inverted.imageset/placeholder-inverted.svg
deleted file mode 100644
index 06f4891e..00000000
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder-inverted.imageset/placeholder-inverted.svg
+++ /dev/null
@@ -1,7 +0,0 @@
-
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder.imageset/Contents.json b/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder.imageset/Contents.json
deleted file mode 100644
index 9b2b69ae..00000000
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder.imageset/Contents.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "images" : [
- {
- "filename" : "placeholder.svg",
- "idiom" : "universal"
- }
- ],
- "info" : {
- "author" : "xcode",
- "version" : 1
- },
- "properties" : {
- "preserves-vector-representation" : true
- }
-}
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder.imageset/placeholder.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder.imageset/placeholder.svg
deleted file mode 100644
index 842da557..00000000
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder.imageset/placeholder.svg
+++ /dev/null
@@ -1,18 +0,0 @@
-
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/credit-card.imageset/Contents.json b/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay-inverted.imageset/Contents.json
similarity index 80%
rename from VDS/SupportingFiles/Icons.xcassets/CreditCard/credit-card.imageset/Contents.json
rename to VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay-inverted.imageset/Contents.json
index 24a71037..72aa17d1 100644
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/credit-card.imageset/Contents.json
+++ b/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay-inverted.imageset/Contents.json
@@ -1,7 +1,7 @@
{
"images" : [
{
- "filename" : "credit-card.svg",
+ "filename" : "UnionPay-logo-onDark.svg",
"idiom" : "universal"
}
],
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay-inverted.imageset/UnionPay-logo-onDark.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay-inverted.imageset/UnionPay-logo-onDark.svg
new file mode 100644
index 00000000..56a83382
--- /dev/null
+++ b/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay-inverted.imageset/UnionPay-logo-onDark.svg
@@ -0,0 +1,7 @@
+
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder-inverted.imageset/Contents.json b/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay.imageset/Contents.json
similarity index 80%
rename from VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder-inverted.imageset/Contents.json
rename to VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay.imageset/Contents.json
index 5b516479..3bf829c6 100644
--- a/VDS/SupportingFiles/Icons.xcassets/CreditCard/placeholder-inverted.imageset/Contents.json
+++ b/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay.imageset/Contents.json
@@ -1,7 +1,7 @@
{
"images" : [
{
- "filename" : "placeholder-inverted.svg",
+ "filename" : "UnionPay-logo-onLight.svg",
"idiom" : "universal"
}
],
diff --git a/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay.imageset/UnionPay-logo-onLight.svg b/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay.imageset/UnionPay-logo-onLight.svg
new file mode 100644
index 00000000..47bdbd1b
--- /dev/null
+++ b/VDS/SupportingFiles/Icons.xcassets/CreditCard/unionPay.imageset/UnionPay-logo-onLight.svg
@@ -0,0 +1,6 @@
+