diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 8260a8c5..dcc6ccd0 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; }; + 01DF560621F8FB2500CC099B /* test123.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF560521F8FB2500CC099B /* test123.swift */; }; D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */; }; D29770C921F7C4AE00B2F0D0 /* TopLabelsView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770EE21F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m */; }; @@ -142,6 +144,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = ""; }; + 01DF560521F8FB2500CC099B /* test123.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = test123.swift; sourceTree = ""; }; D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopLabelsView.m; sourceTree = ""; }; D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopLabelsView.h; sourceTree = ""; }; D29770EE21F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopLabelsAndBottomButtonsTableViewController.m; sourceTree = ""; }; @@ -495,6 +499,7 @@ D29DF17D21E69E26003B2FB9 /* Views */ = { isa = PBXGroup; children = ( + 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */, D29DF17E21E69E2E003B2FB9 /* MFView.h */, D29DF17F21E69E2E003B2FB9 /* MFView.m */, D29DF28521E7AC2B003B2FB9 /* MFLabel.h */, @@ -524,6 +529,7 @@ D29DF32221ED0DA2003B2FB9 /* TextButtonView.m */, D29770FB21F7C77400B2F0D0 /* TextFieldView.h */, D29770FA21F7C77400B2F0D0 /* TextFieldView.m */, + 01DF560521F8FB2500CC099B /* test123.swift */, ); path = Views; sourceTree = ""; @@ -810,6 +816,7 @@ D29DF2EF21ECEAE1003B2FB9 /* MFFonts.m in Sources */, D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */, D29DF18121E69E50003B2FB9 /* MFView.m in Sources */, + 01DF560621F8FB2500CC099B /* test123.swift in Sources */, D29DF18321E69E54003B2FB9 /* SeparatorView.m in Sources */, D29DF17A21E69E1F003B2FB9 /* MFCustomButton.m in Sources */, D29DF26121E6A985003B2FB9 /* MFLoadImageView.m in Sources */, @@ -817,6 +824,7 @@ D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, D29DF28A21E7AC2B003B2FB9 /* MFLabel.m in Sources */, D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */, + 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */, D29DF2A521E7B2A0003B2FB9 /* MFCaretView.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/MFTextFieldListView.swift b/MVMCoreUI/Atoms/Views/MFTextFieldListView.swift new file mode 100644 index 00000000..fe38bd64 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/MFTextFieldListView.swift @@ -0,0 +1,122 @@ +// +// MFTextFieldListView.swift +// MobileFirstFramework +// +// Created by Suresh, Kamlesh on 9/21/18. +// Copyright © 2018 Verizon Wireless. All rights reserved. +// + +import UIKit +import MVMCore + +public class MFTextFieldListView: MFView { + + public var textFieldMapList: [[String: Any]]? + public var parentViewContoller: MFViewController? + public var textFieldsToValidate: [MFTextField] = [] + public var textFields: [MFTextField] = [] + public var primaryButton: PrimaryButton? + + public init(textFieldMapList: [[String: Any]], parentViewContoller: MFViewController, primaryButton: PrimaryButton?) { + self.textFieldMapList = textFieldMapList + self.parentViewContoller = parentViewContoller + self.primaryButton = primaryButton + super.init(frame: .zero) + } + + public required init?(coder decoder: NSCoder) { + super.init(coder: decoder) + } + + public override func updateView(_ size: CGFloat) { + super.updateView(size) + for textField in textFields { + textField.updateView(size) + } + } + + public override func setupView() { + super.setupView() + self.translatesAutoresizingMaskIntoConstraints = false + + guard let textFieldMapList = textFieldMapList else { + return + } + var viewList: [UIView] = [] + + for textFieldMap in textFieldMapList { + if let textField = MFTextField(map: textFieldMap, bothDelegates: self) { + +// if textFieldMap.boolForKey("required") { +// textFieldsToValidate.append(textField) +// } + + textFields.append(textField) + if let fieldKey = textField.fieldKey { + parentViewContoller?.register(textField, forErrorKey: fieldKey as String) + } + viewList.append(textField) + } + } + + StackableViewController.populateView(self, withUIArray: viewList) { (viewObject) -> UIEdgeInsets in + var edgeInsets = StackableViewController.standardSpaceAroundUIObject() + edgeInsets.left = 0 + edgeInsets.right = 0 + edgeInsets.top = 0 + return edgeInsets + } + + primaryButton?.handleEnabling(with: textFieldsToValidate) + } + + public func addParams(requestParameters: MVMCoreRequestParameters) { + requestParameters.add(getTextParamsList()) + } + + public func getTextParamsList() -> [String: Any] { + var extraParam: [String: Any] = [:] + for textField in textFields { + if let fieldKey = textField.fieldKey { + extraParam[fieldKey as String] = textField.text ?? "" + } + } + return extraParam + } +} + +extension MFTextFieldListView: UITextFieldDelegate, UITextViewDelegate, MFTextFieldDelegate { + @objc open func textFieldDidEndEditing(_ textField: UITextField) { + parentViewContoller?.textFieldDidEndEditing(textField) + primaryButton?.handleEnabling(with: textFieldsToValidate) + } + + @objc open func dismissFieldInput(_ sender: Any?) { + parentViewContoller?.dismissFieldInput(sender) + } + + @objc open func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() + return true + } + + @objc open func textFieldDidBeginEditing(_ textField: UITextField) { + parentViewContoller?.textFieldDidBeginEditing(textField) + } + + @objc open func entryIsValid(_ textfield: MFTextField?) { + DispatchQueue.main.async { + if self.parentViewContoller?.responds(to: #selector(MFTextFieldDelegate.entryIsValid(_:))) ?? false { + self.parentViewContoller?.entryIsValid(textfield) + } + } + } + + @objc open func entryIsInvalid(_ textfield: MFTextField?) { + DispatchQueue.main.async { + if self.parentViewContoller?.responds(to: #selector(MFTextFieldDelegate.entryIsInvalid(_:))) ?? false { + self.parentViewContoller?.entryIsInvalid(textfield) + } + } + } +} diff --git a/MVMCoreUI/Atoms/Views/test123.swift b/MVMCoreUI/Atoms/Views/test123.swift new file mode 100644 index 00000000..120000cd --- /dev/null +++ b/MVMCoreUI/Atoms/Views/test123.swift @@ -0,0 +1,13 @@ +// +// test123.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 1/23/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +class test123: NSObject { + +}