From df1a2a0da00546855ac2d8f35aabb6260ef2d575 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 12 Nov 2019 11:06:43 -0500 Subject: [PATCH] latest changes for entry. --- MVMCoreUI.xcodeproj/project.pbxproj | 8 +-- MVMCoreUI/Atoms/TextFields/DigitBox.swift | 6 +-- .../Atoms/TextFields/DigitEntryField.swift | 47 ++++------------ .../Atoms/TextFields/DropdownEntryField.swift | 21 ++------ ...{FormEntryField.swift => EntryField.swift} | 54 +++++++++---------- .../Atoms/TextFields/MdnEntryField.swift | 17 +++--- .../Atoms/TextFields/TextEntryField.swift | 18 +------ MVMCoreUI/Atoms/Views/Checkbox.swift | 1 - 8 files changed, 56 insertions(+), 116 deletions(-) rename MVMCoreUI/Atoms/TextFields/{FormEntryField.swift => EntryField.swift} (92%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 90a8421f..6d76c854 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -25,7 +25,7 @@ 01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 0A1214A022C11A18007C7030 /* ActionDetailWithImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */; }; 0A1B4A96233BB18F005B3FB4 /* CheckboxWithLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */; }; - 0A21DB7F235DECC500C160A2 /* FormEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A21DB7E235DECC500C160A2 /* FormEntryField.swift */; }; + 0A21DB7F235DECC500C160A2 /* EntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A21DB7E235DECC500C160A2 /* EntryField.swift */; }; 0A21DB83235DFBC500C160A2 /* MdnEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A21DB82235DFBC500C160A2 /* MdnEntryField.swift */; }; 0A21DB84235E06EF00C160A2 /* MFTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF24C21E6A177003B2FB9 /* MFTextField.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0A21DB85235E06EF00C160A2 /* MFTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF24221E6A176003B2FB9 /* MFTextField.m */; }; @@ -225,7 +225,7 @@ 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = ""; }; 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = ""; }; 0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionDetailWithImage.swift; sourceTree = ""; }; - 0A21DB7E235DECC500C160A2 /* FormEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormEntryField.swift; sourceTree = ""; }; + 0A21DB7E235DECC500C160A2 /* EntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryField.swift; sourceTree = ""; }; 0A21DB82235DFBC500C160A2 /* MdnEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MdnEntryField.swift; sourceTree = ""; }; 0A21DB93235E24ED00C160A2 /* DigitEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DigitEntryField.swift; sourceTree = ""; }; 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransaction+Extension.swift"; sourceTree = ""; }; @@ -783,7 +783,7 @@ D29DF24A21E6A177003B2FB9 /* MFDigitTextField.xib */, 0A41BA7E23453A6400D4C0BC /* TextEntryField.swift */, 0A8321AE2355FE9500CB7F00 /* DigitBox.swift */, - 0A21DB7E235DECC500C160A2 /* FormEntryField.swift */, + 0A21DB7E235DECC500C160A2 /* EntryField.swift */, 0A21DB82235DFBC500C160A2 /* MdnEntryField.swift */, 0A21DB93235E24ED00C160A2 /* DigitEntryField.swift */, 0A6BF4712360C56C0028F841 /* DropdownEntryField.swift */, @@ -1078,7 +1078,7 @@ D29DF17C21E69E1F003B2FB9 /* MFTextButton.m in Sources */, D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */, D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */, - 0A21DB7F235DECC500C160A2 /* FormEntryField.swift in Sources */, + 0A21DB7F235DECC500C160A2 /* EntryField.swift in Sources */, D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */, D29DF12E21E6851E003B2FB9 /* MVMCoreUITopAlertView.m in Sources */, D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/DigitBox.swift b/MVMCoreUI/Atoms/TextFields/DigitBox.swift index b8f04db6..09ecee72 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitBox.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitBox.swift @@ -12,6 +12,7 @@ import UIKit @objc optional func textFieldDidDelete(_ textField: UITextField?) } + @objcMembers open class DigitBox: UITextField, MVMCoreViewProtocol { //-------------------------------------------------- // MARK: - Properties @@ -77,7 +78,6 @@ import UIKit backgroundColor = .white textAlignment = .center keyboardType = .numberPad -// layer.borderWidth = 1 showErrorState(false) widthConstraint = widthAnchor.constraint(equalToConstant: 39) @@ -157,8 +157,8 @@ import UIKit }) sizeObject?.performBlockBase(onSize: size) -// self.widthConstraint?.constant = digitWidth -// self.heightConstraint?.constant = digitHeight + self.widthConstraint?.constant = digitWidth + self.heightConstraint?.constant = digitHeight self.previousSize = size } diff --git a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift index a705587d..9417fc27 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift @@ -9,16 +9,9 @@ import UIKit /** - * Subclass of TextEntryField due to the conveniences provided. + * Subclass of TextEntryField as it is to use similar logic as a singular textField but appear separate.. */ @objcMembers open class DigitEntryField: TextEntryField, DigitBoxDelegate { - //-------------------------------------------------- - // MARK: - Outlets - //-------------------------------------------------- - - /// UI Container of digitFields - public private(set) var digitFieldsStack: UIStackView? - //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -122,8 +115,8 @@ import UIKit digitFields.forEach { $0.borderStrokeColor = .mfPumpkin() $0.bottomBar.backgroundColor = UIColor.mfPumpkin().cgColor + $0.showErrorState(true) } - self.digitFields.forEach { $0.showErrorState(true) } case .lock: digitFields.forEach { $0.isUserInteractionEnabled = false @@ -150,7 +143,6 @@ import UIKit public override init(frame: CGRect) { super.init(frame: frame) - setup() } public convenience init() { @@ -161,14 +153,11 @@ import UIKit super.init(frame: .zero) self.numberOfDigits = numberOfDigits - setup() } public init(numberOfDigits: Int, bothDelegates delegate: (UITextFieldDelegate & TextFieldDelegate)?, size: CGFloat? = nil) { - super.init(bothDelegates: delegate) - self.numberOfDigits = numberOfDigits - setup() + super.init(bothDelegates: delegate) } required public init?(coder: NSCoder) { @@ -180,7 +169,9 @@ import UIKit // MARK: - Setup //-------------------------------------------------- - open func setup() { + public override func setupFieldContainerContent(_ container: UIView) { + +// textField.removeFromSuperview() alignCenterHorizontal() isAccessibilityElement = false @@ -188,14 +179,8 @@ import UIKit bottomBar.backgroundColor = UIColor.clear.cgColor bottomBar.frame = CGRect(x: 0, y: fieldContainer.bounds.height, width: 0, height: 0) setupDigitFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth()) - } - - open override func setupFieldContainerContent(_ container: UIView) { - // Will not be using textField. - // TODO: May subclass from FormEntry if minimal overriding. textField.removeFromSuperview() - setupDigitFieldsView(size: MVMCoreUIUtility.getWidth()) } private func createDigitField() -> DigitBox { @@ -209,16 +194,8 @@ import UIKit func setupDigitFieldsView(size: CGFloat) { - self.digitFieldsStack?.subviews.forEach { $0.removeFromSuperview() } - digitFieldsStack?.removeFromSuperview() - var accessibleElements: [Any] = [titleLabel] - // Remove all current views in UI. - if let stackViews = digitFieldsStack?.subviews, !stackViews.isEmpty { - stackViews.forEach { $0.removeFromSuperview() } - } - if numberOfDigits > 0 { let digitFields = [DigitBox](repeating: createDigitField(), count: numberOfDigits) self.digitFields = digitFields @@ -227,25 +204,22 @@ import UIKit var prevBox: DigitBox? for (index, box) in digitFields.enumerated() { - // $0.updateView(size) accessibleElements.append(box) fieldContainer.addSubview(box) - - box.widthAnchor.constraint(equalToConstant: 39).isActive = true - box.heightAnchor.constraint(equalToConstant: 44).isActive = true - + box.topAnchor.constraint(equalTo: fieldContainer.topAnchor).isActive = true fieldContainer.bottomAnchor.constraint(equalTo: box.bottomAnchor).isActive = true + box.centerYAnchor.constraint(equalTo: fieldContainer.centerYAnchor).isActive = true if index == 0 { box.leadingAnchor.constraint(equalTo: fieldContainer.leadingAnchor).isActive = true } else if index == digitFields.count - 1 { - box.leadingAnchor.constraint(equalTo: prevBox!.trailingAnchor, constant: space).isActive = true fieldContainer.trailingAnchor.constraint(greaterThanOrEqualTo: box.trailingAnchor).isActive = true + } else { - box.leadingAnchor.constraint(equalTo: prevBox!.trailingAnchor).isActive = true + box.leadingAnchor.constraint(equalTo: prevBox!.trailingAnchor, constant: space).isActive = true } prevBox = box @@ -269,7 +243,6 @@ import UIKit if !self.digitFields.isEmpty { - self.digitFieldsStack?.subviews.forEach { $0.removeFromSuperview() } self.digitFields.forEach { $0.updateView(size) } self.layoutIfNeeded() } diff --git a/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift b/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift index 84f1d83f..7358d9f6 100644 --- a/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift @@ -53,7 +53,6 @@ import UIKit public override init(frame: CGRect) { super.init(frame: frame) - setup() } public convenience init() { @@ -64,7 +63,6 @@ import UIKit public override init(bothDelegates: (UITextFieldDelegate & TextFieldDelegate)?) { super.init(frame: .zero) - setup() MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: bothDelegates) setBothTextDelegates(to: bothDelegates) } @@ -78,17 +76,7 @@ import UIKit // MARK: - Setup //-------------------------------------------------- - private func setup() { - - let tapOnCaret = UITapGestureRecognizer(target: self, action: #selector(startEditing)) - dropDownCaretView.addGestureRecognizer(tapOnCaret) - } - - //-------------------------------------------------- - // MARK: - Lifecycle - //-------------------------------------------------- - - open override func setupFieldContainerContent(_ container: UIView) { + public override func setupFieldContainerContent(_ container: UIView) { super.setupFieldContainerContent(container) container.addSubview(dropDownCaretView) @@ -101,6 +89,9 @@ import UIKit container.bottomAnchor.constraint(greaterThanOrEqualTo: dropDownCaretView.bottomAnchor, constant: 13).isActive = true dropDownCaretView.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true + + let caretTap = UITapGestureRecognizer(target: self, action: #selector(startEditing)) + dropDownCaretView.addGestureRecognizer(caretTap) } //-------------------------------------------------- @@ -206,9 +197,7 @@ extension DropdownEntryField { override open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - guard let dictionary = json, - !dictionary.isEmpty - else { return } + guard let dictionary = json, !dictionary.isEmpty else { return } if let _ = dictionary[KeyType] as? String { dropDownCaretView.isHidden = false diff --git a/MVMCoreUI/Atoms/TextFields/FormEntryField.swift b/MVMCoreUI/Atoms/TextFields/EntryField.swift similarity index 92% rename from MVMCoreUI/Atoms/TextFields/FormEntryField.swift rename to MVMCoreUI/Atoms/TextFields/EntryField.swift index 22d971d8..9b437901 100644 --- a/MVMCoreUI/Atoms/TextFields/FormEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/EntryField.swift @@ -1,5 +1,5 @@ // -// FormEntryField.swift +// EntryField.swift // MVMCoreUI // // Created by Kevin Christiano on 10/21/19. @@ -14,7 +14,7 @@ import UIKit * * When subclassing, be sure to override setupFieldContainerContent(). In this method you will setup all the content bound to the field container. */ -@objcMembers open class FormEntryField: ViewConstrainingView { +@objcMembers open class EntryField: ViewConstrainingView { //-------------------------------------------------- // MARK: - Outlets //-------------------------------------------------- @@ -22,20 +22,9 @@ import UIKit public private(set) var titleLabel: Label = { let label = Label() label.font = MFStyler.fontB3() - label.textColor = UIColor.mfBattleshipGrey() + label.textColor = .mfBattleshipGrey() label.isAccessibilityElement = true label.setContentCompressionResistancePriority(.required, for: .vertical) - label.setContentCompressionResistancePriority(.required, for: .horizontal) - return label - }() - - public private(set) var feedbackLabel: Label = { - let label = Label() - label.font = MFStyler.fontForTextFieldUnderLabel() - label.textColor = .black - label.isAccessibilityElement = true - label.setContentCompressionResistancePriority(.required, for: .vertical) - label.setContentCompressionResistancePriority(.required, for: .horizontal) return label }() @@ -46,6 +35,15 @@ import UIKit return view }() + public private(set) var feedbackLabel: Label = { + let label = Label() + label.font = MFStyler.fontForTextFieldUnderLabel() + label.textColor = .black + label.isAccessibilityElement = true + label.setContentCompressionResistancePriority(.required, for: .vertical) + return label + }() + //-------------------------------------------------- // MARK: - Delegate //-------------------------------------------------- @@ -90,6 +88,7 @@ import UIKit } } + /// Sets the text of titleLabel public var title: String? { get { return titleLabel.text } set { @@ -101,7 +100,7 @@ import UIKit /// Override this to conveniently get/set the textfield(s). public var text: String? { get { return nil } - set { fatalError("You need to override FormEntryField's 'text' variable in your subclass.") } + set { fatalError("You need to override EntryField's 'text' variable in your subclass.") } } /// Sets feedback text in the textField. @@ -149,7 +148,6 @@ import UIKit /// This must be overriden by a subclass. public override init(frame: CGRect) { super.init(frame: frame) - setupView() } public convenience init() { @@ -158,13 +156,13 @@ import UIKit public init(title: String) { super.init(frame: .zero) - setupView() + titleLabel.text = title } required public init?(coder: NSCoder) { super.init(coder: coder) - fatalError("FormEntryField does not support xib.") + fatalError("EntryField does not support xib.") } //-------------------------------------------------- @@ -225,7 +223,7 @@ import UIKit super.updateView(size) titleLabel.updateView(size) - feedbackLabel.font = MFStyler.fontForTextFieldUnderLabel() + feedbackLabel.updateView(size) refreshBorderUI() } @@ -250,7 +248,7 @@ import UIKit let size: CGFloat = appearance == .error ? 4 : 1 bottomBar.frame = CGRect(x: 0, y: fieldContainer.bounds.height - size, width: fieldContainer.bounds.width, height: size) - self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self) + delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self) setNeedsDisplay() layoutIfNeeded() } @@ -353,21 +351,19 @@ import UIKit } // MARK: - Molecular -extension FormEntryField { +extension EntryField { override open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) self.delegateObject = delegateObject - guard let dictionary = json, - !dictionary.isEmpty - else { return } + guard let dictionary = json, !dictionary.isEmpty else { return } - if let formText = dictionary[KeyLabel] as? String { - title = formText + if let titleText = dictionary["title"] as? String { + title = titleText } - if let text = dictionary[KeyDisable] as? String, text.isEqual(StringY) || dictionary.boolForKey(KeyDisable) { + if let disable = dictionary[KeyDisable] as? String, disable.isEqual(StringY) || dictionary.boolForKey(KeyDisable) { isEnabled = false } @@ -395,7 +391,7 @@ extension FormEntryField { } // MARK: - Form Validation -extension FormEntryField: FormValidationProtocol { +extension EntryField: FormValidationProtocol { public func isValidField() -> Bool { return isValid @@ -411,7 +407,7 @@ extension FormEntryField: FormValidationProtocol { } // MARK: - Accessibility -extension FormEntryField { +extension EntryField { @objc open func pushAccessibilityNotification() { // To Be Overriden diff --git a/MVMCoreUI/Atoms/TextFields/MdnEntryField.swift b/MVMCoreUI/Atoms/TextFields/MdnEntryField.swift index 6ca54314..ab4155bd 100644 --- a/MVMCoreUI/Atoms/TextFields/MdnEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/MdnEntryField.swift @@ -17,7 +17,7 @@ import MVMCore // MARK: - Properties //-------------------------------------------------- - public var isNationalMdn = true + public var isNationalMDN = true public var shouldValidateMDN = false private weak var outsiderTextDelegate: UITextFieldDelegate? @@ -45,7 +45,6 @@ import MVMCore public override init(frame: CGRect) { super.init(frame: .zero) - setup() } public convenience init() { @@ -55,7 +54,6 @@ import MVMCore /// - parameter bothDelegates: Sets both MF/UI Text Field Delegates. public override init(bothDelegates: (UITextFieldDelegate & TextFieldDelegate)?) { super.init(frame: .zero) - setup() setBothTextDelegates(to: bothDelegates) } @@ -68,7 +66,8 @@ import MVMCore // MARK: - Setup //-------------------------------------------------- - private func setup() { + public override func setupFieldContainerContent(_ container: UIView) { + super.setupFieldContainerContent(container) textField.keyboardType = .numberPad @@ -86,11 +85,9 @@ import MVMCore public func hasValidMDN() -> Bool { - guard let MDN = mdn, - !MDN.isEmpty - else { return true } + guard let MDN = mdn, !MDN.isEmpty else { return true } - if isNationalMdn { + if isNationalMDN { return MVMCoreUIUtility.validateMDNString(MDN) } @@ -137,7 +134,7 @@ import MVMCore var unformattedMDN = MVMCoreUIUtility.removeMdnFormat(MDN) // Sometimes user add extra 1 in front of mdn in their address book - if isNationalMdn, + if isNationalMDN, let unformedMDN = unformattedMDN, unformedMDN.count == 11, unformedMDN[(unformedMDN.index(unformedMDN.startIndex, offsetBy: 0))] == "1" { @@ -181,7 +178,7 @@ import MVMCore outsiderTextDelegate?.textFieldDidEndEditing?(textField) - if validateAndColor() && isNationalMdn { + if validateAndColor() && isNationalMDN { textField.text = MVMCoreUIUtility.formatMdn(textField.text) } } diff --git a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift index 275a2925..63d3d0e1 100644 --- a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift @@ -19,7 +19,7 @@ import UIKit } -@objcMembers open class TextEntryField: FormEntryField, UITextFieldDelegate { +@objcMembers open class TextEntryField: EntryField, UITextFieldDelegate { //-------------------------------------------------- // MARK: - Outlets //-------------------------------------------------- @@ -55,7 +55,7 @@ import UIKit } } - // The text of this textField. + /// The text of this textField. public override var text: String? { get { return textField.text } set { @@ -173,20 +173,6 @@ import UIKit open func clearErrorState() { - /* - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - self.separatorHeightConstraint.constant = 1; - self.separatorView.backgroundColor = [UIColor blackColor]; - [self layoutIfNeeded]; - self.errorShowing = NO; - self.label.textColor = [UIColor blackColor]; - self.label.text = @""; - self.textField.accessibilityValue = nil; - [self setNeedsDisplay]; - [self layoutIfNeeded]; - }]; - */ - textField.accessibilityValue = nil updateUI(appearance: .original) } diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index e5a82b1d..aadfba64 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -396,7 +396,6 @@ import MVMCore } public func updateView(_ size: CGFloat) { - layoutIfNeeded() }