Commit 88b9a88004d37fe44f8b9dc64725e96b47c9dfa4

Authored by Dmitriy Tymofyeyev
1 parent 9a6c5c0e

add OneTimePassword Screen

@@ -8,11 +8,11 @@ @@ -8,11 +8,11 @@
8 import UIKit 8 import UIKit
9 9
10 class CodeVerificationView: UIView { 10 class CodeVerificationView: UIView {
11 -  
12 var containerView: UIView = { 11 var containerView: UIView = {
13 var obj = UIView() 12 var obj = UIView()
14 return obj 13 return obj
15 }() 14 }()
  15 +
16 var backButton: UIButton = { 16 var backButton: UIButton = {
17 var obj = UIButton() 17 var obj = UIButton()
18 obj.setImage(UIImage(named: "BackPointer"), for: .normal) 18 obj.setImage(UIImage(named: "BackPointer"), for: .normal)
@@ -22,16 +22,19 @@ class CodeVerificationView: UIView { @@ -22,16 +22,19 @@ class CodeVerificationView: UIView {
22 obj.layer.borderWidth = 1 22 obj.layer.borderWidth = 1
23 return obj 23 return obj
24 }() 24 }()
  25 +
25 var logoImage: UIImageView = { 26 var logoImage: UIImageView = {
26 var obj = UIImageView() 27 var obj = UIImageView()
27 obj.image = UIImage(named: "InterQR") 28 obj.image = UIImage(named: "InterQR")
28 return obj 29 return obj
29 }() 30 }()
  31 +
30 var shieldImage: UIImageView = { 32 var shieldImage: UIImageView = {
31 var obj = UIImageView() 33 var obj = UIImageView()
32 obj.image = UIImage(named: "Lock") 34 obj.image = UIImage(named: "Lock")
33 return obj 35 return obj
34 }() 36 }()
  37 +
35 var descriptionLabel: UILabel = { 38 var descriptionLabel: UILabel = {
36 var obj = UILabel() 39 var obj = UILabel()
37 obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 35) 40 obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 35)
@@ -101,11 +104,13 @@ class CodeVerificationView: UIView { @@ -101,11 +104,13 @@ class CodeVerificationView: UIView {
101 obj.isHidden = true 104 obj.isHidden = true
102 return obj 105 return obj
103 }() 106 }()
  107 +
104 var verifyButton: UIButton = { 108 var verifyButton: UIButton = {
105 var obj = UIButton() 109 var obj = UIButton()
106 obj.setImage(UIImage(named: "RectangleWithShadow"), for: .normal) 110 obj.setImage(UIImage(named: "RectangleWithShadow"), for: .normal)
107 return obj 111 return obj
108 }() 112 }()
  113 +
109 var verifyLabel: UILabel = { 114 var verifyLabel: UILabel = {
110 var obj = UILabel() 115 var obj = UILabel()
111 obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16) 116 obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16)
@@ -113,11 +118,13 @@ class CodeVerificationView: UIView { @@ -113,11 +118,13 @@ class CodeVerificationView: UIView {
113 obj.text = "Verify" 118 obj.text = "Verify"
114 return obj 119 return obj
115 }() 120 }()
  121 +
116 var tickImage: UIImageView = { 122 var tickImage: UIImageView = {
117 var obj = UIImageView() 123 var obj = UIImageView()
118 obj.image = UIImage(named: "Tick") 124 obj.image = UIImage(named: "Tick")
119 return obj 125 return obj
120 }() 126 }()
  127 +
121 override init(frame: CGRect) { 128 override init(frame: CGRect) {
122 super.init(frame: frame) 129 super.init(frame: frame)
123 layout() 130 layout()
@@ -128,12 +135,13 @@ class CodeVerificationView: UIView { @@ -128,12 +135,13 @@ class CodeVerificationView: UIView {
128 } 135 }
129 136
130 func layout() { 137 func layout() {
131 - addSubview(textField)  
132 -  
133 backgroundColor = .white 138 backgroundColor = .white
  139 +
  140 + addSubview(textField)
134 addSubview(backButton) 141 addSubview(backButton)
135 addSubview(logoImage) 142 addSubview(logoImage)
136 addSubview(shieldImage) 143 addSubview(shieldImage)
  144 +
137 addSubview(containerView) 145 addSubview(containerView)
138 containerView.addSubview(descriptionLabel) 146 containerView.addSubview(descriptionLabel)
139 containerView.addSubview(firstDigitLabel) 147 containerView.addSubview(firstDigitLabel)
@@ -141,6 +149,7 @@ class CodeVerificationView: UIView { @@ -141,6 +149,7 @@ class CodeVerificationView: UIView {
141 containerView.addSubview(thirdDigitLabel) 149 containerView.addSubview(thirdDigitLabel)
142 containerView.addSubview(fourthDigitLabel) 150 containerView.addSubview(fourthDigitLabel)
143 containerView.addSubview(errorAlertLabel) 151 containerView.addSubview(errorAlertLabel)
  152 +
144 containerView.addSubview(verifyButton) 153 containerView.addSubview(verifyButton)
145 verifyButton.addSubview(verifyLabel) 154 verifyButton.addSubview(verifyLabel)
146 verifyButton.addSubview(tickImage) 155 verifyButton.addSubview(tickImage)
@@ -150,40 +159,48 @@ class CodeVerificationView: UIView { @@ -150,40 +159,48 @@ class CodeVerificationView: UIView {
150 $0.leading.equalTo(snp.leading).offset(22) 159 $0.leading.equalTo(snp.leading).offset(22)
151 $0.height.width.equalTo(45) 160 $0.height.width.equalTo(45)
152 } 161 }
  162 +
153 logoImage.snp.makeConstraints { 163 logoImage.snp.makeConstraints {
154 $0.leading.equalTo(backButton.snp.trailing).offset(20) 164 $0.leading.equalTo(backButton.snp.trailing).offset(20)
155 $0.centerY.equalTo(backButton) 165 $0.centerY.equalTo(backButton)
156 } 166 }
  167 +
157 shieldImage.snp.makeConstraints { 168 shieldImage.snp.makeConstraints {
158 $0.top.equalTo(backButton.snp.bottom).offset(25) 169 $0.top.equalTo(backButton.snp.bottom).offset(25)
159 $0.right.equalTo(snp.right).offset(-101) 170 $0.right.equalTo(snp.right).offset(-101)
160 } 171 }
  172 +
161 containerView.snp.makeConstraints { 173 containerView.snp.makeConstraints {
162 $0.top.equalTo(backButton.snp.bottom).offset(227) 174 $0.top.equalTo(backButton.snp.bottom).offset(227)
163 $0.leading.trailing.equalToSuperview() 175 $0.leading.trailing.equalToSuperview()
164 $0.height.equalTo(300) 176 $0.height.equalTo(300)
165 } 177 }
  178 +
166 descriptionLabel.snp.makeConstraints { 179 descriptionLabel.snp.makeConstraints {
167 $0.leading.equalTo(containerView.snp.leading).offset(20) 180 $0.leading.equalTo(containerView.snp.leading).offset(20)
168 $0.top.equalTo(containerView.snp.top) 181 $0.top.equalTo(containerView.snp.top)
169 } 182 }
  183 +
170 firstDigitLabel.snp.makeConstraints { 184 firstDigitLabel.snp.makeConstraints {
171 $0.leading.equalTo(containerView.snp.leading).offset(25) 185 $0.leading.equalTo(containerView.snp.leading).offset(25)
172 $0.top.equalTo(descriptionLabel.snp.bottom).offset(28) 186 $0.top.equalTo(descriptionLabel.snp.bottom).offset(28)
173 $0.height.equalTo(55) 187 $0.height.equalTo(55)
174 } 188 }
  189 +
175 secondDigitLabel.snp.makeConstraints { 190 secondDigitLabel.snp.makeConstraints {
176 $0.leading.equalTo(firstDigitLabel.snp.trailing).offset(12) 191 $0.leading.equalTo(firstDigitLabel.snp.trailing).offset(12)
177 $0.centerY.equalTo(firstDigitLabel) 192 $0.centerY.equalTo(firstDigitLabel)
178 $0.width.equalTo(firstDigitLabel.snp.width) 193 $0.width.equalTo(firstDigitLabel.snp.width)
179 $0.height.equalTo(55) 194 $0.height.equalTo(55)
180 } 195 }
  196 +
181 thirdDigitLabel.snp.makeConstraints { 197 thirdDigitLabel.snp.makeConstraints {
182 $0.leading.equalTo(secondDigitLabel.snp.trailing).offset(12) 198 $0.leading.equalTo(secondDigitLabel.snp.trailing).offset(12)
183 $0.centerY.equalTo(firstDigitLabel) 199 $0.centerY.equalTo(firstDigitLabel)
184 $0.width.equalTo(firstDigitLabel.snp.width) 200 $0.width.equalTo(firstDigitLabel.snp.width)
185 $0.height.equalTo(55) 201 $0.height.equalTo(55)
186 } 202 }
  203 +
187 fourthDigitLabel.snp.makeConstraints { 204 fourthDigitLabel.snp.makeConstraints {
188 $0.leading.equalTo(thirdDigitLabel.snp.trailing).offset(12) 205 $0.leading.equalTo(thirdDigitLabel.snp.trailing).offset(12)
189 $0.centerY.equalTo(firstDigitLabel) 206 $0.centerY.equalTo(firstDigitLabel)
@@ -191,18 +208,22 @@ class CodeVerificationView: UIView { @@ -191,18 +208,22 @@ class CodeVerificationView: UIView {
191 $0.width.equalTo(firstDigitLabel.snp.width) 208 $0.width.equalTo(firstDigitLabel.snp.width)
192 $0.height.equalTo(55) 209 $0.height.equalTo(55)
193 } 210 }
  211 +
194 errorAlertLabel.snp.makeConstraints { 212 errorAlertLabel.snp.makeConstraints {
195 $0.top.equalTo(firstDigitLabel.snp.bottom).offset(8) 213 $0.top.equalTo(firstDigitLabel.snp.bottom).offset(8)
196 $0.leading.equalTo(firstDigitLabel.snp.leading) 214 $0.leading.equalTo(firstDigitLabel.snp.leading)
197 } 215 }
  216 +
198 verifyButton.snp.makeConstraints { 217 verifyButton.snp.makeConstraints {
199 $0.top.equalTo(firstDigitLabel.snp.bottom).offset(67) 218 $0.top.equalTo(firstDigitLabel.snp.bottom).offset(67)
200 $0.left.right.equalToSuperview() 219 $0.left.right.equalToSuperview()
201 } 220 }
  221 +
202 verifyLabel.snp.makeConstraints { 222 verifyLabel.snp.makeConstraints {
203 $0.left.equalToSuperview().offset(49) 223 $0.left.equalToSuperview().offset(49)
204 $0.top.equalToSuperview().offset(22) 224 $0.top.equalToSuperview().offset(22)
205 } 225 }
  226 +
206 tickImage.snp.makeConstraints { 227 tickImage.snp.makeConstraints {
207 $0.right.equalToSuperview().offset(-47) 228 $0.right.equalToSuperview().offset(-47)
208 $0.centerY.equalTo(verifyLabel) 229 $0.centerY.equalTo(verifyLabel)
@@ -8,9 +8,10 @@ @@ -8,9 +8,10 @@
8 import UIKit 8 import UIKit
9 9
10 class CodeVerificationViewController: UIViewController { 10 class CodeVerificationViewController: UIViewController {
11 -  
12 var otp: String = "" 11 var otp: String = ""
  12 +
13 var isKeyboardAppear = false 13 var isKeyboardAppear = false
  14 +
14 private let mainView = CodeVerificationView() 15 private let mainView = CodeVerificationView()
15 16
16 override func loadView() { 17 override func loadView() {
@@ -23,8 +24,10 @@ class CodeVerificationViewController: UIViewController { @@ -23,8 +24,10 @@ class CodeVerificationViewController: UIViewController {
23 24
24 private func initViewController() { 25 private func initViewController() {
25 mainView.textField.delegate = self 26 mainView.textField.delegate = self
  27 +
26 mainView.backButton.addTarget(self, action: #selector(didDismissVC), for: .touchUpInside) 28 mainView.backButton.addTarget(self, action: #selector(didDismissVC), for: .touchUpInside)
27 mainView.verifyButton.addTarget(self, action: #selector(didVerifyCode), for: .touchUpInside) 29 mainView.verifyButton.addTarget(self, action: #selector(didVerifyCode), for: .touchUpInside)
  30 +
28 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil) 31 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
29 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) 32 NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
30 } 33 }
@@ -34,32 +37,32 @@ class CodeVerificationViewController: UIViewController { @@ -34,32 +37,32 @@ class CodeVerificationViewController: UIViewController {
34 NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil) 37 NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
35 } 38 }
36 } 39 }
37 - 40 +//MARK: - Targets
38 extension CodeVerificationViewController { 41 extension CodeVerificationViewController {
39 42
40 - @objc func didDismissVC() { 43 + @objc private func didDismissVC() {
41 navigationController?.popViewController(animated: true) 44 navigationController?.popViewController(animated: true)
42 } 45 }
43 46
44 - @objc func didVerifyCode() { 47 + @objc private func didVerifyCode() {
45 if mainView.fourthDigitLabel.text == nil { 48 if mainView.fourthDigitLabel.text == nil {
46 let alert = UIAlertController(title: "❌❌❌", message: "Some fields are empty, please fill in all", preferredStyle: .alert) 49 let alert = UIAlertController(title: "❌❌❌", message: "Some fields are empty, please fill in all", preferredStyle: .alert)
47 let _: Void = alert.addAction(UIAlertAction(title: "Close", style: .cancel, handler: nil)) 50 let _: Void = alert.addAction(UIAlertAction(title: "Close", style: .cancel, handler: nil))
48 present(alert, animated: true, completion: nil) 51 present(alert, animated: true, completion: nil)
49 52
50 } else { 53 } else {
51 - mainView.firstDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)  
52 - mainView.firstDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)  
53 -  
54 - mainView.secondDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)  
55 - mainView.secondDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)  
56 -  
57 - mainView.thirdDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)  
58 - mainView.thirdDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)  
59 -  
60 - mainView.fourthDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)  
61 - mainView.fourthDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)  
62 - mainView.errorAlertLabel.isHidden = false 54 + mainView.firstDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)
  55 + mainView.firstDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)
  56 +
  57 + mainView.secondDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)
  58 + mainView.secondDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)
  59 +
  60 + mainView.thirdDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)
  61 + mainView.thirdDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)
  62 +
  63 + mainView.fourthDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1)
  64 + mainView.fourthDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1)
  65 + mainView.errorAlertLabel.isHidden = false
63 66
64 DispatchQueue.main.asyncAfter(deadline: .now() + 3) { 67 DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
65 let vc = HomeViewController() 68 let vc = HomeViewController()
@@ -69,12 +72,10 @@ extension CodeVerificationViewController { @@ -69,12 +72,10 @@ extension CodeVerificationViewController {
69 } 72 }
70 } 73 }
71 74
72 -  
73 - @objc func keyboardWillShow(notification: NSNotification) { 75 + @objc private func keyboardWillShow(notification: NSNotification) {
74 let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double 76 let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
75 - 77 +
76 if !isKeyboardAppear { 78 if !isKeyboardAppear {
77 -  
78 UIView.animate(withDuration: duration ?? 0) { 79 UIView.animate(withDuration: duration ?? 0) {
79 self.mainView.containerView.snp.updateConstraints { make in 80 self.mainView.containerView.snp.updateConstraints { make in
80 make.top.equalTo(self.mainView.backButton.snp.bottom).offset(97) 81 make.top.equalTo(self.mainView.backButton.snp.bottom).offset(97)
@@ -84,16 +85,14 @@ extension CodeVerificationViewController { @@ -84,16 +85,14 @@ extension CodeVerificationViewController {
84 } 85 }
85 self.mainView.layoutIfNeeded() 86 self.mainView.layoutIfNeeded()
86 } 87 }
87 -  
88 isKeyboardAppear = true 88 isKeyboardAppear = true
89 } 89 }
90 } 90 }
91 91
92 - @objc func keyboardWillHide(notification: NSNotification) { 92 + @objc private func keyboardWillHide(notification: NSNotification) {
93 let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double 93 let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
94 - 94 +
95 if isKeyboardAppear { 95 if isKeyboardAppear {
96 -  
97 UIView.animate(withDuration: duration ?? 0) { 96 UIView.animate(withDuration: duration ?? 0) {
98 self.mainView.containerView.snp.updateConstraints { make in 97 self.mainView.containerView.snp.updateConstraints { make in
99 make.top.equalTo(self.mainView.backButton.snp.bottom).offset(227) 98 make.top.equalTo(self.mainView.backButton.snp.bottom).offset(227)
@@ -103,13 +102,12 @@ extension CodeVerificationViewController { @@ -103,13 +102,12 @@ extension CodeVerificationViewController {
103 } 102 }
104 self.mainView.layoutIfNeeded() 103 self.mainView.layoutIfNeeded()
105 } 104 }
106 -  
107 isKeyboardAppear = false 105 isKeyboardAppear = false
108 } 106 }
109 } 107 }
110 -  
111 } 108 }
112 109
  110 +//MARK: - TextField delegate
113 extension CodeVerificationViewController: UITextFieldDelegate { 111 extension CodeVerificationViewController: UITextFieldDelegate {
114 112
115 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { 113 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
@@ -130,8 +128,6 @@ extension CodeVerificationViewController: UITextFieldDelegate { @@ -130,8 +128,6 @@ extension CodeVerificationViewController: UITextFieldDelegate {
130 mainView.textField.endEditing(true) 128 mainView.textField.endEditing(true)
131 } 129 }
132 } 130 }
133 -  
134 return true 131 return true
135 } 132 }
136 -  
137 } 133 }
Please register or login to post a comment