diff --git a/LeadKitAdditions/Sources/Controllers/PassCode/Model/PassCodeConfiguration.swift b/LeadKitAdditions/Sources/Controllers/PassCode/Model/PassCodeConfiguration.swift index d48d8e5..a8b5931 100644 --- a/LeadKitAdditions/Sources/Controllers/PassCode/Model/PassCodeConfiguration.swift +++ b/LeadKitAdditions/Sources/Controllers/PassCode/Model/PassCodeConfiguration.swift @@ -24,26 +24,22 @@ public struct PassCodeConfiguration { /// Pass code length - public var passCodeCharactersNumber: UInt = 4 + public let passCodeLength: Int + /// Incorrect pass code attempts count - public var maxAttemptsLoginNumber: UInt = 5 + public let maxAttemptsNumber: Int /// Clear input progress when application goes to background - public var shouldResetWhenGoBackground: Bool = true + public let shouldResetWhenGoBackground: Bool - private init() {} - - init?(passCodeCharactersNumber: UInt) { - guard passCodeCharactersNumber > 0 else { - assertionFailure("passCodeCharactersNumber must be greater then 0") - return nil - } - self.passCodeCharactersNumber = passCodeCharactersNumber + public init(passCodeLength: Int = 4, maxAttemptsNumber: Int = 5, shouldResetWhenGoBackground: Bool = true) { + self.passCodeLength = passCodeLength + self.maxAttemptsNumber = maxAttemptsNumber + self.shouldResetWhenGoBackground = shouldResetWhenGoBackground } /// Returns configuration with default values public static var defaultConfiguration: PassCodeConfiguration { return PassCodeConfiguration() } - } diff --git a/LeadKitAdditions/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift b/LeadKitAdditions/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift index ca8aacc..21d7877 100644 --- a/LeadKitAdditions/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift +++ b/LeadKitAdditions/Sources/Controllers/PassCode/View/BasePassCodeViewController.swift @@ -102,7 +102,7 @@ open class BasePassCodeViewController: UIViewController, ConfigurableController private func initialDotNumberConfiguration() { dotStackView.arrangedSubviews.forEach { dotStackView.removeArrangedSubview($0) } - for _ in 0..(nil) + private let validationResultHolder = Variable(nil) var validationResult: Driver { return validationResultHolder.asDriver() } - fileprivate let passCodeControllerStateHolder = Variable(.enter) + private let passCodeControllerStateHolder = Variable(.enter) public var passCodeControllerState: Driver { return passCodeControllerStateHolder.asDriver() } private let passCodeText = Variable(nil) - fileprivate var attemptsNumber = 0 + private var attemptsNumber = 0 - fileprivate lazy var passCodeHolder: PassCodeHolderProtocol = { - return PassCodeHolderBuilder.build(with: self.controllerType) - }() + private lazy var passCodeHolder: PassCodeHolderProtocol = PassCodeHolderBuilder.build(with: self.controllerType) public init(controllerType: PassCodeControllerType, passCodeConfiguration: PassCodeConfiguration, @@ -76,7 +75,7 @@ open class BasePassCodeViewModel: BaseViewModel { .distinctUntilChanged { $0 == $1 } .drive(onNext: { [weak self] passCode in if let passCode = passCode, - passCode.characters.count == Int(self?.passCodeConfiguration.passCodeCharactersNumber ?? 0) { + passCode.characters.count == Int(self?.passCodeConfiguration.passCodeLength ?? 0) { self?.set(passCode: passCode) } }) @@ -184,8 +183,8 @@ extension BasePassCodeViewModel { validationResult = .inValid(.wrongCode) } - if (!validationResult.isValid && attemptsNumber == Int(passCodeConfiguration.maxAttemptsLoginNumber)) || - attemptsNumber > Int(passCodeConfiguration.maxAttemptsLoginNumber) { + if (!validationResult.isValid && attemptsNumber == Int(passCodeConfiguration.maxAttemptsNumber)) || + attemptsNumber > Int(passCodeConfiguration.maxAttemptsNumber) { validationResult = .inValid(.tooManyAttempts) } }