more code refactoring

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-05-09 10:09:08 -05:00
parent a71e391050
commit bef02f6b38
4 changed files with 69 additions and 67 deletions

View File

@ -9,6 +9,7 @@ import Foundation
import UIKit
extension InputField {
enum CreditCardType: CaseIterable {
case generic
case visa
@ -19,10 +20,6 @@ extension InputField {
case jcb
case chinaUnionPay
var image: UIImage {
return BundleManager.shared.image(for: imageName)!
}
var imageName: String {
var imageName: String = "generic"
switch self {
@ -192,4 +189,5 @@ extension InputField {
return formattedMaskSection + " " + lastFourDigits
}
}
}

View File

@ -10,6 +10,44 @@ import UIKit
extension InputField {
public enum DateFormat: String, CaseIterable {
case mmyy
case mmddyy
case mmddyyyy
public var placeholderText: String {
switch self {
case .mmyy: "MM/YY"
case .mmddyy: "MM/DD/YY"
case .mmddyyyy: "MM/DD/YYYY"
}
}
public var formatString: String {
switch self {
case .mmyy: "MM/yy"
case .mmddyy: "MM/dd/yy"
case .mmddyyyy: "MM/dd/yyyy"
}
}
public var maxLength: Int {
switch self {
case .mmyy: 5
case .mmddyy: 8
case .mmddyyyy: 10
}
}
internal var separatorIndices: [Int] {
switch self {
case .mmyy: [2]
case .mmddyy: [2,4]
case .mmddyyyy: [2,4]
}
}
}
class DateHandler: FieldTypeHandler {
static let shared = DateHandler()
@ -58,42 +96,4 @@ extension InputField {
}
}
public enum DateFormat: String, CaseIterable {
case mmyy
case mmddyy
case mmddyyyy
public var placeholderText: String {
switch self {
case .mmyy: "MM/YY"
case .mmddyy: "MM/DD/YY"
case .mmddyyyy: "MM/DD/YYYY"
}
}
public var formatString: String {
switch self {
case .mmyy: "MM/yy"
case .mmddyy: "MM/dd/yy"
case .mmddyyyy: "MM/dd/yyyy"
}
}
public var maxLength: Int {
switch self {
case .mmyy: 5
case .mmddyy: 8
case .mmddyyyy: 10
}
}
internal var separatorIndices: [Int] {
switch self {
case .mmyy: [2]
case .mmddyy: [2,4]
case .mmddyyyy: [2,4]
}
}
}
}

View File

@ -10,6 +10,32 @@ import UIKit
import VDSTokens
extension InputField {
public enum FieldType: String, CaseIterable {
case text, number, inlineAction, password, creditCard, telephone, date, securityCode
func handler() -> FieldTypeHandler {
switch self {
case .text:
return TextHandler.shared
case .number:
return NumberHandler.shared
case .inlineAction:
return InlineActionHandler.shared
case .password:
return PasswordHandler.shared
case .creditCard:
return CreditCardHandler.shared
case .telephone:
return TelephoneHandler.shared
case .date:
return DateHandler.shared
case .securityCode:
return SecurityCodeHandler.shared
}
}
}
class FieldTypeHandler: NSObject {
var keyboardType: UIKeyboardType
var minWidth: CGFloat = 40.0
@ -79,29 +105,5 @@ extension InputField {
}
}
public enum FieldType: String, CaseIterable {
case text, number, inlineAction, password, creditCard, telephone, date, securityCode
func handler() -> FieldTypeHandler {
switch self {
case .text:
return TextHandler.shared
case .number:
return NumberHandler.shared
case .inlineAction:
return InlineActionHandler.shared
case .password:
return PasswordHandler.shared
case .creditCard:
return CreditCardHandler.shared
case .telephone:
return TelephoneHandler.shared
case .date:
return DateHandler.shared
case .securityCode:
return SecurityCodeHandler.shared
}
}
}
}

View File

@ -9,6 +9,7 @@ import Foundation
import UIKit
extension InputField {
class TextHandler: FieldTypeHandler {
static let shared = TextHandler()
@ -16,4 +17,5 @@ extension InputField {
super.init()
}
}
}