From d1d453a45576183fc913e4bd6f43eea709619f82 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 08:58:18 +0530 Subject: [PATCH 01/18] Added support to attributed placeholder text to textfield --- KPassCode/KPassCode/KPin/PinConfig.swift | 1 + KPassCode/KPassCode/KPin/PinView.swift | 3 +++ KPassCode/KPassCode/ViewController.swift | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/KPassCode/KPassCode/KPin/PinConfig.swift b/KPassCode/KPassCode/KPin/PinConfig.swift index fc48a1a..183593f 100644 --- a/KPassCode/KPassCode/KPin/PinConfig.swift +++ b/KPassCode/KPassCode/KPin/PinConfig.swift @@ -16,6 +16,7 @@ public struct PinConfig { public var spacing: CGFloat? public var isSecureTextEntry: Bool? public var placeHolderText: String? + public var placeHolderAttributedText: NSAttributedString? public var showPlaceHolder: Bool? init(numberOfFields:OTPLength = .four, dotColor:UIColor = UIColor.black, lineColor:UIColor = .clear, viewMain:UIView = UIView(), spacing:CGFloat = 8.0, secureTextEntry: Bool = true, placeHolderText: String = "*", showPlaceHolder: Bool = true) { self.otpLength = numberOfFields diff --git a/KPassCode/KPassCode/KPin/PinView.swift b/KPassCode/KPassCode/KPin/PinView.swift index 9e68248..f6b741a 100644 --- a/KPassCode/KPassCode/KPin/PinView.swift +++ b/KPassCode/KPassCode/KPin/PinView.swift @@ -83,6 +83,9 @@ class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { textField.delegate = self textField.isSecureTextEntry = config.isSecureTextEntry! textField.placeholder = config.showPlaceHolder! ? config.placeHolderText : "" + if let attributedPH = config.placeHolderAttributedText { + textField.attributedPlaceholder = attributedPH + } textField.backgroundColor = .white textField.textAlignment = .center textField.borderStyle = .none diff --git a/KPassCode/KPassCode/ViewController.swift b/KPassCode/KPassCode/ViewController.swift index 9a2d2d9..0191fcd 100644 --- a/KPassCode/KPassCode/ViewController.swift +++ b/KPassCode/KPassCode/ViewController.swift @@ -22,7 +22,11 @@ class ViewController: UIViewController { config.lineColor = #colorLiteral(red: 0.8265652657, green: 0.8502194881, blue: 0.9000532627, alpha: 1) config.spacing = 20 config.isSecureTextEntry = false - config.showPlaceHolder = false + config.showPlaceHolder = true + config.placeHolderAttributedText = NSAttributedString(string: "-", attributes: [NSAttributedString.Key.foregroundColor:UIColor.black, NSAttributedString.Key.font: UIFont(name: "Avenir-Light", size: 24.0)!]) + + + config.lineColor = .clear viewOTP.config = config viewOTP.setUpView() From 8cd4aa81d64e357705fc1445c120a7024bc57db8 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 08:58:44 +0530 Subject: [PATCH 02/18] Added support to paste OTP on textfield --- KPassCode/KPassCode/KPin/PinView.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/KPassCode/KPassCode/KPin/PinView.swift b/KPassCode/KPassCode/KPin/PinView.swift index f6b741a..5e93566 100644 --- a/KPassCode/KPassCode/KPin/PinView.swift +++ b/KPassCode/KPassCode/KPin/PinView.swift @@ -110,13 +110,19 @@ class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { } func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { - if string.characters.count == 0 { - if textField.text?.characters.count == 0 { + if string.count == 0 { + if textField.text?.count == 0 { if let previousTextField = self.viewWithTag(textField.tag-1) { previousTextField.becomeFirstResponder() } } - } else { + } else if string.count == self.config.otpLength?.value { + for (idx,textField) in textFields.enumerated() { + let txt = String(string[string.index(string.startIndex, offsetBy: idx)]) + textField.text = txt + } + return false + } else if string.count == 1 { if let currentTextField = self.viewWithTag(textField.tag+1) { currentTextField.becomeFirstResponder() } else { @@ -124,6 +130,8 @@ class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { return false } } + } else { + return false } textField.text = string return false From daa3ec0b471e310234fda31b54fdbe97b773386a Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:07:50 +0530 Subject: [PATCH 03/18] Added swift package --- KPassCode/KPassCode.xcodeproj/project.pbxproj | 4 ++++ KPassCode/KPassCode/Package.swift | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 KPassCode/KPassCode/Package.swift diff --git a/KPassCode/KPassCode.xcodeproj/project.pbxproj b/KPassCode/KPassCode.xcodeproj/project.pbxproj index 5b38376..e803a34 100644 --- a/KPassCode/KPassCode.xcodeproj/project.pbxproj +++ b/KPassCode/KPassCode.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 182B39F822CB5CFC00D79C5D /* PinTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F522CB5CFC00D79C5D /* PinTextField.swift */; }; 182B39F922CB5CFC00D79C5D /* PinConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F622CB5CFC00D79C5D /* PinConfig.swift */; }; 182B39FA22CB5CFC00D79C5D /* PinView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F722CB5CFC00D79C5D /* PinView.swift */; }; + 3B1E1195295407A20058D81F /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B1E1194295407A20058D81F /* Package.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -28,6 +29,7 @@ 182B39F522CB5CFC00D79C5D /* PinTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinTextField.swift; sourceTree = ""; }; 182B39F622CB5CFC00D79C5D /* PinConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinConfig.swift; sourceTree = ""; }; 182B39F722CB5CFC00D79C5D /* PinView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinView.swift; sourceTree = ""; }; + 3B1E1194295407A20058D81F /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -67,6 +69,7 @@ 182B39EA22CB5CD700D79C5D /* Assets.xcassets */, 182B39EC22CB5CD700D79C5D /* LaunchScreen.storyboard */, 182B39EF22CB5CD700D79C5D /* Info.plist */, + 3B1E1194295407A20058D81F /* Package.swift */, ); path = KPassCode; sourceTree = ""; @@ -152,6 +155,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 3B1E1195295407A20058D81F /* Package.swift in Sources */, 182B39FA22CB5CFC00D79C5D /* PinView.swift in Sources */, 182B39E622CB5CD600D79C5D /* ViewController.swift in Sources */, 182B39F822CB5CFC00D79C5D /* PinTextField.swift in Sources */, diff --git a/KPassCode/KPassCode/Package.swift b/KPassCode/KPassCode/Package.swift new file mode 100644 index 0000000..6883135 --- /dev/null +++ b/KPassCode/KPassCode/Package.swift @@ -0,0 +1,21 @@ +// +// Package.swift +// KPassCode +// +// Created by Harshit Daftary on 22/12/22. +// Copyright © 2022 Konstant info Solutions Pvt. Ltd. All rights reserved. +// +// swift-tools-version:4.0 + +import PackageDescription + +let package = Package(name: "KPin", + platforms: [.iOS(.v11)], + products: [.library(name: "KPin", + targets: ["KPin"])], + targets: [.target(name: "KPin", + path: "KPassCode/KPin", + exclude: ["Info.plist"], + linkerSettings: [])], + swiftLanguageVersions: [.v5]) + From 6e3ed9162da26d59bb1ebc8da2a2f8a698c59092 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:11:23 +0530 Subject: [PATCH 04/18] repositioned package file --- KPassCode/KPassCode.xcodeproj/project.pbxproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/KPassCode/KPassCode.xcodeproj/project.pbxproj b/KPassCode/KPassCode.xcodeproj/project.pbxproj index e803a34..5b38376 100644 --- a/KPassCode/KPassCode.xcodeproj/project.pbxproj +++ b/KPassCode/KPassCode.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ 182B39F822CB5CFC00D79C5D /* PinTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F522CB5CFC00D79C5D /* PinTextField.swift */; }; 182B39F922CB5CFC00D79C5D /* PinConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F622CB5CFC00D79C5D /* PinConfig.swift */; }; 182B39FA22CB5CFC00D79C5D /* PinView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F722CB5CFC00D79C5D /* PinView.swift */; }; - 3B1E1195295407A20058D81F /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B1E1194295407A20058D81F /* Package.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -29,7 +28,6 @@ 182B39F522CB5CFC00D79C5D /* PinTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinTextField.swift; sourceTree = ""; }; 182B39F622CB5CFC00D79C5D /* PinConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinConfig.swift; sourceTree = ""; }; 182B39F722CB5CFC00D79C5D /* PinView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinView.swift; sourceTree = ""; }; - 3B1E1194295407A20058D81F /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -69,7 +67,6 @@ 182B39EA22CB5CD700D79C5D /* Assets.xcassets */, 182B39EC22CB5CD700D79C5D /* LaunchScreen.storyboard */, 182B39EF22CB5CD700D79C5D /* Info.plist */, - 3B1E1194295407A20058D81F /* Package.swift */, ); path = KPassCode; sourceTree = ""; @@ -155,7 +152,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 3B1E1195295407A20058D81F /* Package.swift in Sources */, 182B39FA22CB5CFC00D79C5D /* PinView.swift in Sources */, 182B39E622CB5CD600D79C5D /* ViewController.swift in Sources */, 182B39F822CB5CFC00D79C5D /* PinTextField.swift in Sources */, From b0c8e168bf829281fdc0021c6a14f460e5031c43 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:12:01 +0530 Subject: [PATCH 05/18] Add package file --- Package.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Package.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..6883135 --- /dev/null +++ b/Package.swift @@ -0,0 +1,21 @@ +// +// Package.swift +// KPassCode +// +// Created by Harshit Daftary on 22/12/22. +// Copyright © 2022 Konstant info Solutions Pvt. Ltd. All rights reserved. +// +// swift-tools-version:4.0 + +import PackageDescription + +let package = Package(name: "KPin", + platforms: [.iOS(.v11)], + products: [.library(name: "KPin", + targets: ["KPin"])], + targets: [.target(name: "KPin", + path: "KPassCode/KPin", + exclude: ["Info.plist"], + linkerSettings: [])], + swiftLanguageVersions: [.v5]) + From e1cad42d15c8b785c02a0c5f0be162a99cf070d7 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:14:00 +0530 Subject: [PATCH 06/18] Fixed linting issue in package file --- KPassCode/KPassCode/Package.swift | 21 --------------------- Package.swift | 7 ------- 2 files changed, 28 deletions(-) delete mode 100644 KPassCode/KPassCode/Package.swift diff --git a/KPassCode/KPassCode/Package.swift b/KPassCode/KPassCode/Package.swift deleted file mode 100644 index 6883135..0000000 --- a/KPassCode/KPassCode/Package.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// Package.swift -// KPassCode -// -// Created by Harshit Daftary on 22/12/22. -// Copyright © 2022 Konstant info Solutions Pvt. Ltd. All rights reserved. -// -// swift-tools-version:4.0 - -import PackageDescription - -let package = Package(name: "KPin", - platforms: [.iOS(.v11)], - products: [.library(name: "KPin", - targets: ["KPin"])], - targets: [.target(name: "KPin", - path: "KPassCode/KPin", - exclude: ["Info.plist"], - linkerSettings: [])], - swiftLanguageVersions: [.v5]) - diff --git a/Package.swift b/Package.swift index 6883135..1f8764f 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,3 @@ -// -// Package.swift -// KPassCode -// -// Created by Harshit Daftary on 22/12/22. -// Copyright © 2022 Konstant info Solutions Pvt. Ltd. All rights reserved. -// // swift-tools-version:4.0 import PackageDescription From 970fe174f5ae8675a003f3138beea07d289b81d4 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:16:31 +0530 Subject: [PATCH 07/18] Fixed path error --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 1f8764f..dbfc246 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ let package = Package(name: "KPin", products: [.library(name: "KPin", targets: ["KPin"])], targets: [.target(name: "KPin", - path: "KPassCode/KPin", + path: "KPassCode/KPassCode/KPin", exclude: ["Info.plist"], linkerSettings: [])], swiftLanguageVersions: [.v5]) From 68b6b8515f6ef864e5d983415c596bc46ef746e2 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:19:44 +0530 Subject: [PATCH 08/18] Fixed path error --- Package.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index dbfc246..c95bc73 100644 --- a/Package.swift +++ b/Package.swift @@ -2,11 +2,11 @@ import PackageDescription -let package = Package(name: "KPin", +let package = Package(name: "KPassCode", platforms: [.iOS(.v11)], - products: [.library(name: "KPin", - targets: ["KPin"])], - targets: [.target(name: "KPin", + products: [.library(name: "KPassCode", + targets: ["KPassCode"])], + targets: [.target(name: "KPassCode", path: "KPassCode/KPassCode/KPin", exclude: ["Info.plist"], linkerSettings: [])], From 67a886a49759dae9485794e582018ea4b5b9e759 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:33:34 +0530 Subject: [PATCH 09/18] Fixed path error --- Package.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index c95bc73..dc317e1 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:5.0 import PackageDescription @@ -8,7 +8,6 @@ let package = Package(name: "KPassCode", targets: ["KPassCode"])], targets: [.target(name: "KPassCode", path: "KPassCode/KPassCode/KPin", - exclude: ["Info.plist"], linkerSettings: [])], swiftLanguageVersions: [.v5]) From bc100e8328b23d7bf6e4710693dbb8700babb974 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:44:30 +0530 Subject: [PATCH 10/18] Fixed path error --- KPassCode/Source/PinConfig.swift | 31 ++++++ KPassCode/Source/PinTextField.swift | 26 +++++ KPassCode/Source/PinView.swift | 157 ++++++++++++++++++++++++++++ Package.swift | 2 +- 4 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 KPassCode/Source/PinConfig.swift create mode 100644 KPassCode/Source/PinTextField.swift create mode 100644 KPassCode/Source/PinView.swift diff --git a/KPassCode/Source/PinConfig.swift b/KPassCode/Source/PinConfig.swift new file mode 100644 index 0000000..183593f --- /dev/null +++ b/KPassCode/Source/PinConfig.swift @@ -0,0 +1,31 @@ +// +// OTPVerifyConfig.swift +// +// Created by Krishna on 24/04/17. +// Copyright © 2017 Konstant. All rights reserved. +// + +import Foundation +import UIKit + +public struct PinConfig { + public var otpLength: OTPLength? + public var dotColor: UIColor? + public var lineColor: UIColor? + public var viewMain: UIView? + public var spacing: CGFloat? + public var isSecureTextEntry: Bool? + public var placeHolderText: String? + public var placeHolderAttributedText: NSAttributedString? + public var showPlaceHolder: Bool? + init(numberOfFields:OTPLength = .four, dotColor:UIColor = UIColor.black, lineColor:UIColor = .clear, viewMain:UIView = UIView(), spacing:CGFloat = 8.0, secureTextEntry: Bool = true, placeHolderText: String = "*", showPlaceHolder: Bool = true) { + self.otpLength = numberOfFields + self.dotColor = dotColor + self.lineColor = lineColor + self.viewMain = viewMain + self.spacing = spacing + self.isSecureTextEntry = secureTextEntry + self.placeHolderText = placeHolderText + self.showPlaceHolder = showPlaceHolder + } +} diff --git a/KPassCode/Source/PinTextField.swift b/KPassCode/Source/PinTextField.swift new file mode 100644 index 0000000..7ad6b58 --- /dev/null +++ b/KPassCode/Source/PinTextField.swift @@ -0,0 +1,26 @@ +// +// OTPTextField.swift +// +// Created by Krishna on 24/04/17. +// Copyright © 2017 Konstant. All rights reserved. +// + +import UIKit + +protocol OTPTextFieldDelegate { + func OTPTextFieldDidPressBackspace(textfield: PinTextField) +} + +class PinTextField: UITextField { + + var delegateOTP:OTPTextFieldDelegate! + + override func deleteBackward() { + super.deleteBackward() + + if delegateOTP != nil { + delegateOTP.OTPTextFieldDidPressBackspace(textfield: self) + } + } + +} diff --git a/KPassCode/Source/PinView.swift b/KPassCode/Source/PinView.swift new file mode 100644 index 0000000..5e93566 --- /dev/null +++ b/KPassCode/Source/PinView.swift @@ -0,0 +1,157 @@ +// +// OTPVerifyView.swift +// +// Created by Krishna on 24/04/17. +// Copyright © 2017 Konstant. All rights reserved. +// + +import UIKit + +public enum OTPError: Error { + case inCompleteOTPEntry + + public var localizedDescription: String { + switch self { + case .inCompleteOTPEntry: return "Incomplete OTP Entry" + } + } +} + +public enum OTPLength { + case four + case six + case custom(Int) + var value: Int { + switch self { + case .four: return 4 + case .six: return 6 + case .custom(let num): return num + } + } + + var lineLength: Int? { + switch self { + case .four: return 40 + case .six: return 30 + case .custom: return nil + } + } +} + +class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { + + lazy public var config:PinConfig! = PinConfig() + var textFields = [UITextField]() + + // MARK: Initialization + + override init(frame: CGRect) { + super.init(frame: frame) + } + + required init(coder: NSCoder) { + super.init(coder: coder) + } + + convenience init(config:PinConfig = PinConfig()) { + self.init() + self.config = config + self.spacing = config.spacing! + self.axis = .horizontal + self.alignment = .fill + self.distribution = .fillProportionally + // setUpView() + } + + public func setUpView() { + + for _ in 0.. Bool { + if string.count == 0 { + if textField.text?.count == 0 { + if let previousTextField = self.viewWithTag(textField.tag-1) { + previousTextField.becomeFirstResponder() + } + } + } else if string.count == self.config.otpLength?.value { + for (idx,textField) in textFields.enumerated() { + let txt = String(string[string.index(string.startIndex, offsetBy: idx)]) + textField.text = txt + } + return false + } else if string.count == 1 { + if let currentTextField = self.viewWithTag(textField.tag+1) { + currentTextField.becomeFirstResponder() + } else { + if !textField.text!.isEmpty { + return false + } + } + } else { + return false + } + textField.text = string + return false + } + + func getOTP() throws -> String { + var otpCode:String = "" + for textField in textFields { + if textField.text == "" { + throw OTPError.inCompleteOTPEntry + } + otpCode += textField.text! + } + return otpCode + } + + func OTPTextFieldDidPressBackspace(textfield: PinTextField) { + if let previousTextField: PinTextField = self.viewWithTag(textfield.tag-1) as? PinTextField { + previousTextField.text = "" + previousTextField.becomeFirstResponder() + } + } +} diff --git a/Package.swift b/Package.swift index dc317e1..d3eb82b 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ let package = Package(name: "KPassCode", products: [.library(name: "KPassCode", targets: ["KPassCode"])], targets: [.target(name: "KPassCode", - path: "KPassCode/KPassCode/KPin", + path: "KPassCode/Source", linkerSettings: [])], swiftLanguageVersions: [.v5]) From 8bb971bfb8ea20922cd84ae51eb0dbf616cd55e6 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:45:58 +0530 Subject: [PATCH 11/18] Fixed Path --- KPassCode/KPassCode.xcodeproj/project.pbxproj | 30 ++-- KPassCode/KPassCode/KPin/PinConfig.swift | 31 ---- KPassCode/KPassCode/KPin/PinTextField.swift | 26 --- KPassCode/KPassCode/KPin/PinView.swift | 157 ------------------ 4 files changed, 15 insertions(+), 229 deletions(-) delete mode 100644 KPassCode/KPassCode/KPin/PinConfig.swift delete mode 100644 KPassCode/KPassCode/KPin/PinTextField.swift delete mode 100644 KPassCode/KPassCode/KPin/PinView.swift diff --git a/KPassCode/KPassCode.xcodeproj/project.pbxproj b/KPassCode/KPassCode.xcodeproj/project.pbxproj index 5b38376..5ea5192 100644 --- a/KPassCode/KPassCode.xcodeproj/project.pbxproj +++ b/KPassCode/KPassCode.xcodeproj/project.pbxproj @@ -12,9 +12,9 @@ 182B39E922CB5CD600D79C5D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 182B39E722CB5CD600D79C5D /* Main.storyboard */; }; 182B39EB22CB5CD700D79C5D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 182B39EA22CB5CD700D79C5D /* Assets.xcassets */; }; 182B39EE22CB5CD700D79C5D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 182B39EC22CB5CD700D79C5D /* LaunchScreen.storyboard */; }; - 182B39F822CB5CFC00D79C5D /* PinTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F522CB5CFC00D79C5D /* PinTextField.swift */; }; - 182B39F922CB5CFC00D79C5D /* PinConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F622CB5CFC00D79C5D /* PinConfig.swift */; }; - 182B39FA22CB5CFC00D79C5D /* PinView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 182B39F722CB5CFC00D79C5D /* PinView.swift */; }; + 3B1E119E29540F1B0058D81F /* PinTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B1E119B29540F1B0058D81F /* PinTextField.swift */; }; + 3B1E119F29540F1B0058D81F /* PinConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B1E119C29540F1B0058D81F /* PinConfig.swift */; }; + 3B1E11A029540F1B0058D81F /* PinView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B1E119D29540F1B0058D81F /* PinView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -25,9 +25,9 @@ 182B39EA22CB5CD700D79C5D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 182B39ED22CB5CD700D79C5D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 182B39EF22CB5CD700D79C5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 182B39F522CB5CFC00D79C5D /* PinTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinTextField.swift; sourceTree = ""; }; - 182B39F622CB5CFC00D79C5D /* PinConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinConfig.swift; sourceTree = ""; }; - 182B39F722CB5CFC00D79C5D /* PinView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinView.swift; sourceTree = ""; }; + 3B1E119B29540F1B0058D81F /* PinTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinTextField.swift; sourceTree = ""; }; + 3B1E119C29540F1B0058D81F /* PinConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinConfig.swift; sourceTree = ""; }; + 3B1E119D29540F1B0058D81F /* PinView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -44,6 +44,7 @@ 182B39D722CB5CD600D79C5D = { isa = PBXGroup; children = ( + 3B1E119A29540F1B0058D81F /* Source */, 182B39E222CB5CD600D79C5D /* KPassCode */, 182B39E122CB5CD600D79C5D /* Products */, ); @@ -60,7 +61,6 @@ 182B39E222CB5CD600D79C5D /* KPassCode */ = { isa = PBXGroup; children = ( - 182B39FB22CB5D1100D79C5D /* KPin */, 182B39E322CB5CD600D79C5D /* AppDelegate.swift */, 182B39E522CB5CD600D79C5D /* ViewController.swift */, 182B39E722CB5CD600D79C5D /* Main.storyboard */, @@ -71,14 +71,14 @@ path = KPassCode; sourceTree = ""; }; - 182B39FB22CB5D1100D79C5D /* KPin */ = { + 3B1E119A29540F1B0058D81F /* Source */ = { isa = PBXGroup; children = ( - 182B39F622CB5CFC00D79C5D /* PinConfig.swift */, - 182B39F522CB5CFC00D79C5D /* PinTextField.swift */, - 182B39F722CB5CFC00D79C5D /* PinView.swift */, + 3B1E119B29540F1B0058D81F /* PinTextField.swift */, + 3B1E119C29540F1B0058D81F /* PinConfig.swift */, + 3B1E119D29540F1B0058D81F /* PinView.swift */, ); - path = KPin; + path = Source; sourceTree = ""; }; /* End PBXGroup section */ @@ -152,11 +152,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 182B39FA22CB5CFC00D79C5D /* PinView.swift in Sources */, + 3B1E11A029540F1B0058D81F /* PinView.swift in Sources */, 182B39E622CB5CD600D79C5D /* ViewController.swift in Sources */, - 182B39F822CB5CFC00D79C5D /* PinTextField.swift in Sources */, + 3B1E119E29540F1B0058D81F /* PinTextField.swift in Sources */, 182B39E422CB5CD600D79C5D /* AppDelegate.swift in Sources */, - 182B39F922CB5CFC00D79C5D /* PinConfig.swift in Sources */, + 3B1E119F29540F1B0058D81F /* PinConfig.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/KPassCode/KPassCode/KPin/PinConfig.swift b/KPassCode/KPassCode/KPin/PinConfig.swift deleted file mode 100644 index 183593f..0000000 --- a/KPassCode/KPassCode/KPin/PinConfig.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// OTPVerifyConfig.swift -// -// Created by Krishna on 24/04/17. -// Copyright © 2017 Konstant. All rights reserved. -// - -import Foundation -import UIKit - -public struct PinConfig { - public var otpLength: OTPLength? - public var dotColor: UIColor? - public var lineColor: UIColor? - public var viewMain: UIView? - public var spacing: CGFloat? - public var isSecureTextEntry: Bool? - public var placeHolderText: String? - public var placeHolderAttributedText: NSAttributedString? - public var showPlaceHolder: Bool? - init(numberOfFields:OTPLength = .four, dotColor:UIColor = UIColor.black, lineColor:UIColor = .clear, viewMain:UIView = UIView(), spacing:CGFloat = 8.0, secureTextEntry: Bool = true, placeHolderText: String = "*", showPlaceHolder: Bool = true) { - self.otpLength = numberOfFields - self.dotColor = dotColor - self.lineColor = lineColor - self.viewMain = viewMain - self.spacing = spacing - self.isSecureTextEntry = secureTextEntry - self.placeHolderText = placeHolderText - self.showPlaceHolder = showPlaceHolder - } -} diff --git a/KPassCode/KPassCode/KPin/PinTextField.swift b/KPassCode/KPassCode/KPin/PinTextField.swift deleted file mode 100644 index 7ad6b58..0000000 --- a/KPassCode/KPassCode/KPin/PinTextField.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// OTPTextField.swift -// -// Created by Krishna on 24/04/17. -// Copyright © 2017 Konstant. All rights reserved. -// - -import UIKit - -protocol OTPTextFieldDelegate { - func OTPTextFieldDidPressBackspace(textfield: PinTextField) -} - -class PinTextField: UITextField { - - var delegateOTP:OTPTextFieldDelegate! - - override func deleteBackward() { - super.deleteBackward() - - if delegateOTP != nil { - delegateOTP.OTPTextFieldDidPressBackspace(textfield: self) - } - } - -} diff --git a/KPassCode/KPassCode/KPin/PinView.swift b/KPassCode/KPassCode/KPin/PinView.swift deleted file mode 100644 index 5e93566..0000000 --- a/KPassCode/KPassCode/KPin/PinView.swift +++ /dev/null @@ -1,157 +0,0 @@ -// -// OTPVerifyView.swift -// -// Created by Krishna on 24/04/17. -// Copyright © 2017 Konstant. All rights reserved. -// - -import UIKit - -public enum OTPError: Error { - case inCompleteOTPEntry - - public var localizedDescription: String { - switch self { - case .inCompleteOTPEntry: return "Incomplete OTP Entry" - } - } -} - -public enum OTPLength { - case four - case six - case custom(Int) - var value: Int { - switch self { - case .four: return 4 - case .six: return 6 - case .custom(let num): return num - } - } - - var lineLength: Int? { - switch self { - case .four: return 40 - case .six: return 30 - case .custom: return nil - } - } -} - -class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { - - lazy public var config:PinConfig! = PinConfig() - var textFields = [UITextField]() - - // MARK: Initialization - - override init(frame: CGRect) { - super.init(frame: frame) - } - - required init(coder: NSCoder) { - super.init(coder: coder) - } - - convenience init(config:PinConfig = PinConfig()) { - self.init() - self.config = config - self.spacing = config.spacing! - self.axis = .horizontal - self.alignment = .fill - self.distribution = .fillProportionally - // setUpView() - } - - public func setUpView() { - - for _ in 0.. Bool { - if string.count == 0 { - if textField.text?.count == 0 { - if let previousTextField = self.viewWithTag(textField.tag-1) { - previousTextField.becomeFirstResponder() - } - } - } else if string.count == self.config.otpLength?.value { - for (idx,textField) in textFields.enumerated() { - let txt = String(string[string.index(string.startIndex, offsetBy: idx)]) - textField.text = txt - } - return false - } else if string.count == 1 { - if let currentTextField = self.viewWithTag(textField.tag+1) { - currentTextField.becomeFirstResponder() - } else { - if !textField.text!.isEmpty { - return false - } - } - } else { - return false - } - textField.text = string - return false - } - - func getOTP() throws -> String { - var otpCode:String = "" - for textField in textFields { - if textField.text == "" { - throw OTPError.inCompleteOTPEntry - } - otpCode += textField.text! - } - return otpCode - } - - func OTPTextFieldDidPressBackspace(textfield: PinTextField) { - if let previousTextField: PinTextField = self.viewWithTag(textfield.tag-1) as? PinTextField { - previousTextField.text = "" - previousTextField.becomeFirstResponder() - } - } -} From 91d4bec234300fe2d544c36bb3ceb5404063af8f Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:52:04 +0530 Subject: [PATCH 12/18] updated path --- KPassCode/{ => KPassCode}/Source/PinConfig.swift | 0 KPassCode/{ => KPassCode}/Source/PinTextField.swift | 0 KPassCode/{ => KPassCode}/Source/PinView.swift | 0 Package.swift | 2 +- 4 files changed, 1 insertion(+), 1 deletion(-) rename KPassCode/{ => KPassCode}/Source/PinConfig.swift (100%) rename KPassCode/{ => KPassCode}/Source/PinTextField.swift (100%) rename KPassCode/{ => KPassCode}/Source/PinView.swift (100%) diff --git a/KPassCode/Source/PinConfig.swift b/KPassCode/KPassCode/Source/PinConfig.swift similarity index 100% rename from KPassCode/Source/PinConfig.swift rename to KPassCode/KPassCode/Source/PinConfig.swift diff --git a/KPassCode/Source/PinTextField.swift b/KPassCode/KPassCode/Source/PinTextField.swift similarity index 100% rename from KPassCode/Source/PinTextField.swift rename to KPassCode/KPassCode/Source/PinTextField.swift diff --git a/KPassCode/Source/PinView.swift b/KPassCode/KPassCode/Source/PinView.swift similarity index 100% rename from KPassCode/Source/PinView.swift rename to KPassCode/KPassCode/Source/PinView.swift diff --git a/Package.swift b/Package.swift index d3eb82b..a851f8f 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ let package = Package(name: "KPassCode", products: [.library(name: "KPassCode", targets: ["KPassCode"])], targets: [.target(name: "KPassCode", - path: "KPassCode/Source", + path: "KPassCode/KPassCode/Source", linkerSettings: [])], swiftLanguageVersions: [.v5]) From e2d6326a131bc161bbd89e44d9bef776a5ea8ff2 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 09:53:49 +0530 Subject: [PATCH 13/18] Updated paths --- KPassCode/KPassCode.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPassCode/KPassCode.xcodeproj/project.pbxproj b/KPassCode/KPassCode.xcodeproj/project.pbxproj index 5ea5192..75d8cdb 100644 --- a/KPassCode/KPassCode.xcodeproj/project.pbxproj +++ b/KPassCode/KPassCode.xcodeproj/project.pbxproj @@ -44,7 +44,6 @@ 182B39D722CB5CD600D79C5D = { isa = PBXGroup; children = ( - 3B1E119A29540F1B0058D81F /* Source */, 182B39E222CB5CD600D79C5D /* KPassCode */, 182B39E122CB5CD600D79C5D /* Products */, ); @@ -61,6 +60,7 @@ 182B39E222CB5CD600D79C5D /* KPassCode */ = { isa = PBXGroup; children = ( + 3B1E119A29540F1B0058D81F /* Source */, 182B39E322CB5CD600D79C5D /* AppDelegate.swift */, 182B39E522CB5CD600D79C5D /* ViewController.swift */, 182B39E722CB5CD600D79C5D /* Main.storyboard */, From 35543b0fcf861b87fffe392d5ec5ab3c53cec0a2 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 21:48:54 +0530 Subject: [PATCH 14/18] Made necessary methods public --- KPassCode/KPassCode/Source/PinConfig.swift | 2 +- KPassCode/KPassCode/Source/PinView.swift | 2 +- Package.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/KPassCode/KPassCode/Source/PinConfig.swift b/KPassCode/KPassCode/Source/PinConfig.swift index 183593f..5d7a7ab 100644 --- a/KPassCode/KPassCode/Source/PinConfig.swift +++ b/KPassCode/KPassCode/Source/PinConfig.swift @@ -18,7 +18,7 @@ public struct PinConfig { public var placeHolderText: String? public var placeHolderAttributedText: NSAttributedString? public var showPlaceHolder: Bool? - init(numberOfFields:OTPLength = .four, dotColor:UIColor = UIColor.black, lineColor:UIColor = .clear, viewMain:UIView = UIView(), spacing:CGFloat = 8.0, secureTextEntry: Bool = true, placeHolderText: String = "*", showPlaceHolder: Bool = true) { + public init(numberOfFields:OTPLength = .four, dotColor:UIColor = UIColor.black, lineColor:UIColor = .clear, viewMain:UIView = UIView(), spacing:CGFloat = 8.0, secureTextEntry: Bool = true, placeHolderText: String = "*", showPlaceHolder: Bool = true) { self.otpLength = numberOfFields self.dotColor = dotColor self.lineColor = lineColor diff --git a/KPassCode/KPassCode/Source/PinView.swift b/KPassCode/KPassCode/Source/PinView.swift index 5e93566..c254d0d 100644 --- a/KPassCode/KPassCode/Source/PinView.swift +++ b/KPassCode/KPassCode/Source/PinView.swift @@ -38,7 +38,7 @@ public enum OTPLength { } } -class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { +public class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { lazy public var config:PinConfig! = PinConfig() var textFields = [UITextField]() diff --git a/Package.swift b/Package.swift index a851f8f..20ca68c 100644 --- a/Package.swift +++ b/Package.swift @@ -8,6 +8,6 @@ let package = Package(name: "KPassCode", targets: ["KPassCode"])], targets: [.target(name: "KPassCode", path: "KPassCode/KPassCode/Source", - linkerSettings: [])], + linkerSettings: [])] swiftLanguageVersions: [.v5]) From 3c7e398c206a28f2c7b0b487bca5baffe0d6ae56 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 22:06:01 +0530 Subject: [PATCH 15/18] made necessary methods public --- KPassCode/KPassCode/Source/PinView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPassCode/KPassCode/Source/PinView.swift b/KPassCode/KPassCode/Source/PinView.swift index c254d0d..fef8817 100644 --- a/KPassCode/KPassCode/Source/PinView.swift +++ b/KPassCode/KPassCode/Source/PinView.swift @@ -137,7 +137,7 @@ public class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { return false } - func getOTP() throws -> String { + public func getOTP() throws -> String { var otpCode:String = "" for textField in textFields { if textField.text == "" { From a4e62a737bff6f9f8745ad01d289933bd1234033 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 22:49:19 +0530 Subject: [PATCH 16/18] fixed package file error --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 20ca68c..a851f8f 100644 --- a/Package.swift +++ b/Package.swift @@ -8,6 +8,6 @@ let package = Package(name: "KPassCode", targets: ["KPassCode"])], targets: [.target(name: "KPassCode", path: "KPassCode/KPassCode/Source", - linkerSettings: [])] + linkerSettings: [])], swiftLanguageVersions: [.v5]) From 2c77a4a9fd0bd362f00bdbbb76ad6f2f1e580a61 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 22:55:08 +0530 Subject: [PATCH 17/18] Made delegate method as public --- KPassCode/KPassCode/Source/PinView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPassCode/KPassCode/Source/PinView.swift b/KPassCode/KPassCode/Source/PinView.swift index fef8817..0be9144 100644 --- a/KPassCode/KPassCode/Source/PinView.swift +++ b/KPassCode/KPassCode/Source/PinView.swift @@ -109,7 +109,7 @@ public class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { } } - func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { if string.count == 0 { if textField.text?.count == 0 { if let previousTextField = self.viewWithTag(textField.tag-1) { From 068505be2df4352ad9552c6584738eb892d4e179 Mon Sep 17 00:00:00 2001 From: Harshit Daftary Date: Thu, 22 Dec 2022 22:57:04 +0530 Subject: [PATCH 18/18] Made necessary variable as public --- KPassCode/KPassCode/Source/PinView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KPassCode/KPassCode/Source/PinView.swift b/KPassCode/KPassCode/Source/PinView.swift index 0be9144..36170a6 100644 --- a/KPassCode/KPassCode/Source/PinView.swift +++ b/KPassCode/KPassCode/Source/PinView.swift @@ -41,7 +41,7 @@ public enum OTPLength { public class PinView: UIStackView, UITextFieldDelegate, OTPTextFieldDelegate { lazy public var config:PinConfig! = PinConfig() - var textFields = [UITextField]() + public var textFields = [UITextField]() // MARK: Initialization