Code corresction

This commit is contained in:
Vlad 2020-08-23 23:47:56 +03:00
parent bb125aa428
commit cba4833d46
3 changed files with 9 additions and 10 deletions

View File

@ -23,5 +23,6 @@
import UIKit
public typealias Spacing = [Int: CGFloat]
public typealias ValueClosure<T> = ((T) -> Void)
public typealias VoidClosure = (() -> Void)
public typealias ValidationClosure<T> = ((T) -> Bool)

View File

@ -32,7 +32,7 @@ open class OTPSwiftView<View: OTPView>: BaseInitializableControl {
public private(set) var codeStackView = UIStackView()
public private(set) var textFieldsCollection: [View] = []
public var onTextEnter: ((String) -> Void)?
public var onTextEnter: ValueClosure<String>?
public var code: String {
get {
@ -99,28 +99,24 @@ private extension OTPSwiftView {
}
customSpacing.forEach { [weak self] viewIndex, spacing in
guard viewIndex < stackView.arrangedSubviews.count, viewIndex >= 0 else {
guard viewIndex < stackView.arrangedSubviews.count, viewIndex >= .zero else {
return
}
self?.set(spacing: spacing,
after: stackView.arrangedSubviews[viewIndex],
at: viewIndex,
for: stackView)
}
}
func set(spacing: CGFloat,
after view: UIView,
at index: Int,
for stackView: UIStackView) {
func set(spacing: CGFloat, after view: UIView, for stackView: UIStackView) {
stackView.setCustomSpacing(spacing, after: view)
}
func createTextFields(numberOfFields: Int) -> [View] {
var textFieldsCollection: [View] = []
(0..<numberOfFields).forEach { _ in
(.zero..<numberOfFields).forEach { _ in
let textField = View()
textField.codeTextField.previousTextField = textFieldsCollection.last?.codeTextField
textFieldsCollection.last?.codeTextField.nextTextField = textField.codeTextField
@ -132,7 +128,9 @@ private extension OTPSwiftView {
func bindTextFields(with config: OTPCodeConfig) {
let onTextChangedSignal: VoidClosure = { [weak self] in
guard let code = self?.code else { return }
guard let code = self?.code else {
return
}
let correctedCode = code.prefix(config.codeSymbolsCount).string
self?.onTextEnter?(correctedCode)

View File

@ -6,5 +6,5 @@ This repository contains the following additional frameworks:
- [TIUIKitCore](TIUIKitCore) - core ui elements and protocols from LeadKit.
- [TITransitions](TITransitions) - set of custom transitions to present controller.
- [TIUIElements](TIUIElements) - bunch of of useful protocols and views.
- [OTPSwiftView](OTPSwiftView) - a fully customizable OTP view..
- [OTPSwiftView](OTPSwiftView) - a fully customizable OTP view.