Files
Woka_Native_iOS/WOKA/Authentication/Controller/OTPVC.swift
Bilal 32f9ddaa7d - Made the forget password UI.
- Made login view.
- Continue the flow from onboarding.
- added the flow from login-> create account and forget password.
2024-05-03 20:27:54 +05:30

95 lines
3.1 KiB
Swift

//
// OTPVC.swift
// WOKA
//
// Created by MacBook Pro on 29/04/24.
//
import UIKit
enum NavigateToVC{
case newPass
case registeration
}
class OTPVC : UIViewController{
@IBOutlet weak var wokaLogoTopConstriant: NSLayoutConstraint!
@IBOutlet weak var tf1: UITextField!
@IBOutlet weak var tf2: UITextField!
@IBOutlet weak var tf3: UITextField!
@IBOutlet weak var tf4: UITextField!
@IBOutlet weak var nextBtn: LocalisedElementsButton!
@IBOutlet weak var codeSentLabel: UILabel!
@IBOutlet weak var enterCodeLabel: UILabel!
@IBOutlet weak var requestThemLabel: LocalisedElementsLabel!
var vm = OTPVM()
var navigateCheck = NavigateToVC.registeration
override func viewDidLoad() {
super.viewDidLoad()
vm.vc = self
vm.initView()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
// MARK: - Button Tap Handler
@IBAction func nextBtnTapped(_ sender: LocalisedElementsButton) {
switch self.navigateCheck{
case .newPass:
let sb = UIStoryboard(name: K.StoryBoard.authenticationSB, bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Authentication.newPasswordVC) as! NewPasswordVC
self.navigationController?.pushViewController(vc, animated: true)
case .registeration:
let sb = UIStoryboard(name: K.StoryBoard.authenticationSB, bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Authentication.userDetailsRegisterVC) as! UserDetailsRegisterVC
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
// MARK: - TextField Delegate
extension OTPVC : UITextFieldDelegate{
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool{
// Check if the input text contains only numbers
if !string.onlyNumber(){return false}
// If user pastes text into the text field, check the count and process accordingly
if string.count == 4{
self.vm.textFieldDidChange(textField, otpCode: string)
return false
}
// Limit the input to one character
let maxLength = 1
let currentString = (textField.text ?? "") as NSString
let newString = currentString.replacingCharacters(in: range, with: string)
return newString.count <= maxLength
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
// Check if the pasted text contains the content of the general pasteboard
if text.contains(UIPasteboard.general.string ?? "") {
return false
}
return true
}
}