form engtry.

This commit is contained in:
Kevin G Christiano 2019-10-28 09:12:38 -04:00
parent f14614514d
commit 8d1ac1e94a
2 changed files with 47 additions and 25 deletions

View File

@ -34,6 +34,8 @@ import UIKit
public var isValid = false public var isValid = false
public var fieldKey: String? public var fieldKey: String?
/// Determines if a border should be drawn.
public var hideBorder = false
public var showErrorMessage = false public var showErrorMessage = false
public var errorMessage: String? { 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? { public var descriptionText: String? {
get { return descriptionLabel?.text } get { return descriptionLabel?.text }
set { set {
@ -313,6 +299,47 @@ import UIKit
descriptionLabelTrailing?.constant = constant 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 // MARK: - Methods
//-------------------------------------------------- //--------------------------------------------------
@ -322,15 +349,10 @@ import UIKit
showErrorMessage = show showErrorMessage = show
if show { if show {
feedbackLabel?.text = errorMessage
}
}
open func resetEntryAppearance() {
borderStrokeColor = .mfSilver() feedbackLabel?.text = errorMessage
bottomBar?.backgroundColor = .black fieldAppearance(.error)
bottomBarHeightConstraint?.constant = 1 }
} }
open func showDashSeperatorView(_ dash: Bool) { open func showDashSeperatorView(_ dash: Bool) {

View File

@ -237,7 +237,7 @@ import UIKit
if isValid { if isValid {
clearError() clearError()
separatorView?.backgroundColor = .black bottomBar?.backgroundColor = .black
} else if let errMessage = errorMessage { } else if let errMessage = errorMessage {
feedback = errMessage feedback = errMessage
} }