-
Notifications
You must be signed in to change notification settings - Fork 14
/
VitaminTextField+Configuration.swift
95 lines (84 loc) · 3.3 KB
/
VitaminTextField+Configuration.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Vitamin iOS
// Apache License 2.0
//
import UIKit
import VitaminCore
// MARK: - configuration structs
/// Protocol that can be implemented to be noticed of events on the text field icon
public protocol VitaminTextFieldIconActionDelegate: AnyObject {
/// Method that is called when the user clicks on the icon in VitaminTextField
func vitaminTextFieldDidClickOnIcon(_ vitaminTextField: VitaminTextField)
}
public extension VitaminTextField {
/// Struct that can be provided to the initializer of `VitaminTextField`
/// that groups all validation configuration
struct ValidationConfiguration {
public var liveValidation: VitaminTextFieldValidation?
public var liveValidationTimeInterval: TimeInterval = 0.5
public var endEditingValidation: VitaminTextFieldValidation?
public init(
liveValidation: VitaminTextFieldValidation? = nil,
liveValidationTimeInterval: TimeInterval = 0.5,
endEditingValidation: VitaminTextFieldValidation? = nil
) {
self.liveValidation = liveValidation
self.liveValidationTimeInterval = liveValidationTimeInterval
self.endEditingValidation = endEditingValidation
}
}
/// Struct that can be provided to the initializer of `VitaminTextField`
/// that groups all text configuration
struct TextConfiguration {
public var labelText: String
public var fieldValue: String?
public var placeholderText: String?
public var helperText: String?
public var secureText: Bool? = false
public init(
labelText: String,
fieldValue: String? = nil,
placeholderText: String? = nil,
helperText: String? = nil,
secureText: Bool? = false
) {
self.labelText = labelText
self.fieldValue = fieldValue
self.placeholderText = placeholderText
self.helperText = helperText
self.secureText = secureText
}
}
/// Struct that can be provided to the initializer of `VitaminTextField`
/// that groups all state configuration
struct StateConfiguration {
public var initialState: VitaminTextFieldState
public var activeOnEditing = false
public var horizontalPadding = true
public init(
initialState: VitaminTextFieldState,
activeOnEditing: Bool = false,
horizontalPadding: Bool = true
) {
self.initialState = initialState
self.activeOnEditing = activeOnEditing
self.horizontalPadding = horizontalPadding
}
}
/// Struct that can be provided to the initializer of `VitaminTextField`
/// that groups all icon configuration
struct IconConfiguration {
public var initialIcon: UIImage?
public var iconAction: VitaminTextFieldIconAction?
public weak var iconActionDelegate: VitaminTextFieldIconActionDelegate?
public init(
initialIcon: UIImage?,
iconAction: VitaminTextFieldIconAction? = nil,
iconActionDelegate: VitaminTextFieldIconActionDelegate? = nil
) {
self.initialIcon = initialIcon
self.iconAction = iconAction
self.iconActionDelegate = iconActionDelegate
}
}
}