From 8d1ac1e94a2e5062c4b1819a42db5840ffd25f4b Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 28 Oct 2019 09:12:38 -0400 Subject: [PATCH] form engtry. --- .../Atoms/TextFields/FormEntryField.swift | 70 ++++++++++++------- .../Atoms/TextFields/TextEntryField.swift | 2 +- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/MVMCoreUI/Atoms/TextFields/FormEntryField.swift b/MVMCoreUI/Atoms/TextFields/FormEntryField.swift index 182c895d..90cf03bd 100644 --- a/MVMCoreUI/Atoms/TextFields/FormEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/FormEntryField.swift @@ -34,6 +34,8 @@ import UIKit public var isValid = false public var fieldKey: String? + /// Determines if a border should be drawn. + public var hideBorder = false public var showErrorMessage = false public var errorMessage: String? { @@ -60,22 +62,6 @@ import UIKit } } - /// Determines if a border should be drawn. - public var hideBorder = false { - didSet { setNeedsDisplay() } - } - - public var isLocked = false { - didSet { - isUserInteractionEnabled = isLocked - borderStrokeColor = isLocked ? .clear : UIColor.mfSilver() - bottomBar?.backgroundColor = isLocked ? .clear : .black - bottomBarHeightConstraint?.constant = 1 - - fieldContainer?.setNeedsDisplay() - } - } - public var descriptionText: String? { get { return descriptionLabel?.text } set { @@ -313,6 +299,47 @@ import UIKit descriptionLabelTrailing?.constant = constant } + //-------------------------------------------------- + // MARK: - Form Appearance + //-------------------------------------------------- + + public enum Appearance { + case original + case error + case locked + case selected + } + + public func fieldAppearance(_ state: Appearance) { + + switch state { + case .original: + isUserInteractionEnabled = true + borderStrokeColor = .mfSilver() + bottomBar?.backgroundColor = .black + bottomBarHeightConstraint?.constant = 1 + + case .error: + isUserInteractionEnabled = true + bottomBarHeightConstraint?.constant = 4 + + case .locked: + isUserInteractionEnabled = false + hideBorder = true + bottomBar?.backgroundColor = .clear + bottomBarHeightConstraint?.constant = 1 + + case .selected: + isUserInteractionEnabled = true + borderStrokeColor = .mfSilver() + bottomBar?.backgroundColor = .black + bottomBarHeightConstraint?.constant = 1 + } + + fieldContainer?.setNeedsDisplay() + layoutIfNeeded() + } + //-------------------------------------------------- // MARK: - Methods //-------------------------------------------------- @@ -322,15 +349,10 @@ import UIKit showErrorMessage = show if show { - feedbackLabel?.text = errorMessage - } - } - - open func resetEntryAppearance() { - borderStrokeColor = .mfSilver() - bottomBar?.backgroundColor = .black - bottomBarHeightConstraint?.constant = 1 + feedbackLabel?.text = errorMessage + fieldAppearance(.error) + } } open func showDashSeperatorView(_ dash: Bool) { diff --git a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift index e5da5006..0eb61015 100644 --- a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift @@ -237,7 +237,7 @@ import UIKit if isValid { clearError() - separatorView?.backgroundColor = .black + bottomBar?.backgroundColor = .black } else if let errMessage = errorMessage { feedback = errMessage }