diff --git a/LeadKitAdditions.podspec b/LeadKitAdditions.podspec index 07379bb..53d9390 100644 --- a/LeadKitAdditions.podspec +++ b/LeadKitAdditions.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKitAdditions" - s.version = "0.0.20" + s.version = "0.0.21" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKitAdditions" s.license = "Apache License, Version 2.0" diff --git a/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj b/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj index fa859bb..cc11ade 100644 --- a/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj +++ b/LeadKitAdditions/LeadKitAdditions.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0A08E37F1F2A13BF00F9AB62 /* CellTextFieldToolBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A08E37E1F2A13BF00F9AB62 /* CellTextFieldToolBar.swift */; }; 248389A288C0A6D7914F0546 /* Pods_LeadKitAdditions_LeadKitAdditions_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0ED4A1B793EAA73C9E95969F /* Pods_LeadKitAdditions_LeadKitAdditions_iOS.framework */; }; B326804BA6CC8B8BB136A46A /* Pods_LeadKitAdditions_LeadKitAdditions_iOS_Extensions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CFD5627139CAB27705F75C07 /* Pods_LeadKitAdditions_LeadKitAdditions_iOS_Extensions.framework */; }; CAE698E81E968820000394B0 /* LeadKitAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = CAE698E61E968820000394B0 /* LeadKitAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -83,6 +84,7 @@ /* Begin PBXFileReference section */ 01605ECA03749D49C27FA3DD /* Pods-LeadKitAdditions-LeadKitAdditions iOS Extensions.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKitAdditions-LeadKitAdditions iOS Extensions.release.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKitAdditions-LeadKitAdditions iOS Extensions/Pods-LeadKitAdditions-LeadKitAdditions iOS Extensions.release.xcconfig"; sourceTree = ""; }; + 0A08E37E1F2A13BF00F9AB62 /* CellTextFieldToolBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellTextFieldToolBar.swift; sourceTree = ""; }; 0ED4A1B793EAA73C9E95969F /* Pods_LeadKitAdditions_LeadKitAdditions_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKitAdditions_LeadKitAdditions_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 49738551AC648B0AFA74E57F /* Pods-LeadKitAdditions-LeadKitAdditions iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKitAdditions-LeadKitAdditions iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKitAdditions-LeadKitAdditions iOS/Pods-LeadKitAdditions-LeadKitAdditions iOS.debug.xcconfig"; sourceTree = ""; }; 7B7F57C5E5275C4D8DC71992 /* Pods_LeadKitAdditions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKitAdditions.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -323,6 +325,7 @@ ED0C33FF1F2906EC00FAE9FD /* Views */ = { isa = PBXGroup; children = ( + 0A08E37E1F2A13BF00F9AB62 /* CellTextFieldToolBar.swift */, ED0C34001F2906EC00FAE9FD /* CellTextField */, ); path = Views; @@ -585,6 +588,7 @@ ED0C34451F2906EC00FAE9FD /* CellTextField.swift in Sources */, ED0C34271F2906EC00FAE9FD /* CellFieldsToolBarProtocol.swift in Sources */, ED0C34291F2906EC00FAE9FD /* CellFieldValidationProtocol.swift in Sources */, + 0A08E37F1F2A13BF00F9AB62 /* CellTextFieldToolBar.swift in Sources */, ED0C34031F2906EC00FAE9FD /* ApiResponse.swift in Sources */, ED0C34071F2906EC00FAE9FD /* LoadingBarButton.swift in Sources */, ED0C34251F2906EC00FAE9FD /* CellFieldMaskProtocol.swift in Sources */, diff --git a/LeadKitAdditions/Sources/Services/CellFieldsJumpingService.swift b/LeadKitAdditions/Sources/Services/CellFieldsJumpingService.swift index 6406c78..692ff28 100644 --- a/LeadKitAdditions/Sources/Services/CellFieldsJumpingService.swift +++ b/LeadKitAdditions/Sources/Services/CellFieldsJumpingService.swift @@ -77,36 +77,33 @@ class CellFieldsJumpingService { } private func toolBar(for field: CellFieldJumpingProtocol, with index: Int) -> UIToolbar { - // hotfix for project builing - // todo: @GrigoryUlanov - return UIToolbar() -// let toolBar = CellTextFieldToolBar() -// toolBar.canGoForward = cellFields.nextActive(from: index) != nil -// toolBar.canGoBackward = cellFields.previousActive(from: index) != nil -// -// toolBar.needArrows = config.toolBarNeedArrows -// -// toolBar.shouldGoForward.asObservable() -// .subscribe(onNext: { [weak self] in -// self?.shouldGoForwardAction(from: index) -// }) -// .addDisposableTo(disposeBag) -// -// toolBar.shouldGoBackward.asObservable() -// .subscribe(onNext: { [weak self] in -// if let previousActive = self?.cellFields.previousActive(from: index) { -// previousActive.shouldBecomeFirstResponder.onNext() -// } -// }) -// .addDisposableTo(disposeBag) -// -// toolBar.shouldEndEditing.asObservable() -// .subscribe(onNext: { -// field.shouldResignFirstResponder.onNext() -// }) -// .addDisposableTo(disposeBag) -// -// return toolBar + let toolBar = CellTextFieldToolBar() + toolBar.canGoForward = cellFields.nextActive(from: index) != nil + toolBar.canGoBackward = cellFields.previousActive(from: index) != nil + + toolBar.needArrows = config.toolBarNeedArrows + + toolBar.shouldGoForward.asObservable() + .subscribe(onNext: { [weak self] in + self?.shouldGoForwardAction(from: index) + }) + .addDisposableTo(disposeBag) + + toolBar.shouldGoBackward.asObservable() + .subscribe(onNext: { [weak self] in + if let previousActive = self?.cellFields.previousActive(from: index) { + previousActive.shouldBecomeFirstResponder.onNext() + } + }) + .addDisposableTo(disposeBag) + + toolBar.shouldEndEditing.asObservable() + .subscribe(onNext: { + field.shouldResignFirstResponder.onNext() + }) + .addDisposableTo(disposeBag) + + return toolBar } private func shouldGoForwardAction(from index: Int) { diff --git a/LeadKitAdditions/Sources/Views/CellTextFieldToolBar.swift b/LeadKitAdditions/Sources/Views/CellTextFieldToolBar.swift new file mode 100644 index 0000000..108b913 --- /dev/null +++ b/LeadKitAdditions/Sources/Views/CellTextFieldToolBar.swift @@ -0,0 +1,96 @@ +import UIKit +import RxSwift +import RxCocoa +import LeadKit + +class CellTextFieldToolBar: UIToolbar, CellFieldsToolBarProtocol { + + private let buttonSpace: CGFloat = 20 + private let customSkyColor = UIColor(hex6: 0x0A84DF) + + // MARK: - CellFieldsToolBarProtocol + + var needArrows: Bool = true + + var canGoForward: Bool = false { + didSet { + forwardButton.isEnabled = canGoForward + } + } + var canGoBackward: Bool = false { + didSet { + backButton.isEnabled = canGoBackward + } + } + + var shouldGoForward = PublishSubject() + var shouldGoBackward = PublishSubject() + var shouldEndEditing = PublishSubject() + + // MARK: - UIBarButtonItems + + private(set) lazy var backButton: UIBarButtonItem = { + let backButton = UIBarButtonItem(image: #imageLiteral(resourceName: "keyboard_back"), + style: .plain, + target: self, + action: #selector(backAction)) + return backButton + }() + + private(set) lazy var forwardButton: UIBarButtonItem = { + let forwardButton = UIBarButtonItem(image: #imageLiteral(resourceName: "keyboard_forward"), + style: .plain, + target: self, + action: #selector(forwardAction)) + return forwardButton + }() + + private(set) lazy var closeButton: UIBarButtonItem = { + let doneButton = UIBarButtonItem(barButtonSystemItem: .done, + target: self, + action: #selector(doneAction)) + return doneButton + }() + + // MARK: - Initialization + + override init(frame: CGRect) { + super.init(frame: frame) + initialization() + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + initialization() + } + + private func initialization() { + barStyle = .default + isTranslucent = true + sizeToFit() + + let leftSpacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) + let buttonsSpacer1 = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil) + buttonsSpacer1.width = buttonSpace + let buttonsSpacer2 = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil) + buttonsSpacer2.width = buttonSpace + + setItems([leftSpacer, backButton, buttonsSpacer1, forwardButton, buttonsSpacer2, closeButton], animated: true) + items?.forEach { $0.tintColor = customSkyColor } + } + + // MARK: - Actions + + @objc private func backAction() { + shouldGoBackward.onNext() + } + + @objc private func forwardAction() { + shouldGoForward.onNext() + } + + @objc private func doneAction() { + shouldEndEditing.onNext() + } + +}