refactored StateLabel to FormLabel
add errorLabel removed all constraints and replaced with UIStackView show/hide errorLabel within showError Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
083d767740
commit
d3f4f21b02
@ -17,8 +17,8 @@ import UIKit
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Outlets
|
// MARK: - Outlets
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public private(set) var titleLabel: StateLabel = {
|
public private(set) var titleLabel: FormLabel = {
|
||||||
let label = StateLabel()
|
let label = FormLabel()
|
||||||
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
return label
|
return label
|
||||||
}()
|
}()
|
||||||
@ -26,12 +26,33 @@ import UIKit
|
|||||||
public private(set) var entryFieldContainer = EntryFieldContainer()
|
public private(set) var entryFieldContainer = EntryFieldContainer()
|
||||||
|
|
||||||
/// Provides contextual information on the TextField.
|
/// Provides contextual information on the TextField.
|
||||||
public private(set) var feedbackLabel: StateLabel = {
|
public private(set) var feedbackLabel: FormLabel = {
|
||||||
let label = StateLabel()
|
let label = FormLabel()
|
||||||
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
return label
|
return label
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
public private(set) var errorLabel: Label = {
|
||||||
|
let label = Label()
|
||||||
|
label.setFontStyle(.RegularMicro)
|
||||||
|
label.textColor = .mvmBlack
|
||||||
|
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
|
return label
|
||||||
|
}()
|
||||||
|
|
||||||
|
public lazy var stack: UIStackView = {
|
||||||
|
errorLabel.isHidden = true
|
||||||
|
let s = UIStackView(arrangedSubviews: [titleLabel, entryFieldContainer, errorLabel, feedbackLabel])
|
||||||
|
s.axis = .vertical
|
||||||
|
s.alignment = .fill
|
||||||
|
s.distribution = .fill
|
||||||
|
s.setCustomSpacing(Padding.One, after: titleLabel)
|
||||||
|
s.setCustomSpacing(Padding.Two, after: entryFieldContainer)
|
||||||
|
s.setCustomSpacing(Padding.One, after: errorLabel)
|
||||||
|
s.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
return s
|
||||||
|
}()
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Delegate
|
// MARK: - Delegate
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -59,13 +80,17 @@ import UIKit
|
|||||||
feedbackLabel.isEnabled = enabled
|
feedbackLabel.isEnabled = enabled
|
||||||
entryFieldContainer.isEnabled = enabled
|
entryFieldContainer.isEnabled = enabled
|
||||||
entryFieldModel?.enabled = enabled
|
entryFieldModel?.enabled = enabled
|
||||||
if !enabled {
|
|
||||||
self.text = defaultText
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Toggles enabled (original) or disabled UI.
|
||||||
|
public var isRequired: Bool = true {
|
||||||
|
didSet{
|
||||||
|
titleLabel.isRequired = isRequired
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Toggles readOnly (original) or disabled UI.
|
/// Toggles readOnly (original) or disabled UI.
|
||||||
public var isReadOnly: Bool {
|
public var isReadOnly: Bool {
|
||||||
get { entryFieldContainer.isReadOnly }
|
get { entryFieldContainer.isReadOnly }
|
||||||
@ -82,9 +107,10 @@ import UIKit
|
|||||||
get { entryFieldContainer.showError }
|
get { entryFieldContainer.showError }
|
||||||
set (error) {
|
set (error) {
|
||||||
if error {
|
if error {
|
||||||
feedbackLabel.showError(message: self.errorMessage ?? "")
|
errorLabel.text = self.errorMessage ?? ""
|
||||||
|
errorLabel.isHidden = false
|
||||||
} else {
|
} else {
|
||||||
feedbackLabel.reset()
|
errorLabel.isHidden = true
|
||||||
}
|
}
|
||||||
entryFieldContainer.showError = error
|
entryFieldContainer.showError = error
|
||||||
entryFieldModel?.showError = error
|
entryFieldModel?.showError = error
|
||||||
@ -141,25 +167,6 @@ import UIKit
|
|||||||
model as? EntryFieldModel
|
model as? EntryFieldModel
|
||||||
}
|
}
|
||||||
|
|
||||||
///This is the value of the entryFieldModel.text on set
|
|
||||||
///This is used to update the text value on a reset or when enabled is set to false
|
|
||||||
private var defaultText: String = ""
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Constraints
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
public var entryFieldContainerLeading: NSLayoutConstraint?
|
|
||||||
public var entryFieldContainerTrailing: NSLayoutConstraint?
|
|
||||||
|
|
||||||
public var feedbackLabelTrailing: NSLayoutConstraint?
|
|
||||||
public var feedbackLabelLeading: NSLayoutConstraint?
|
|
||||||
|
|
||||||
public var titleLabelLeading: NSLayoutConstraint?
|
|
||||||
public var titleLabelTrailing: NSLayoutConstraint?
|
|
||||||
|
|
||||||
public var titleContainerDistance: NSLayoutConstraint?
|
|
||||||
public var feedbackContainerDistance: NSLayoutConstraint?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -199,37 +206,18 @@ import UIKit
|
|||||||
|
|
||||||
isAccessibilityElement = false
|
isAccessibilityElement = false
|
||||||
setContentCompressionResistancePriority(.required, for: .vertical)
|
setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
accessibilityElements = [titleLabel, feedbackLabel]
|
accessibilityElements = [titleLabel, errorLabel, feedbackLabel]
|
||||||
backgroundColor = .mvmWhite
|
backgroundColor = .mvmWhite
|
||||||
|
|
||||||
addSubview(titleLabel)
|
addSubview(stack)
|
||||||
|
|
||||||
titleLabel.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
|
||||||
titleLabelLeading = titleLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
|
||||||
titleLabelLeading?.isActive = true
|
|
||||||
titleLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: titleLabel.trailingAnchor)
|
|
||||||
titleLabelLeading?.isActive = true
|
|
||||||
|
|
||||||
addSubview(entryFieldContainer)
|
|
||||||
entryFieldContainer.setContentCompressionResistancePriority(.required, for: .vertical)
|
entryFieldContainer.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
setupFieldContainerContent(entryFieldContainer)
|
setupFieldContainerContent(entryFieldContainer)
|
||||||
|
|
||||||
titleContainerDistance = entryFieldContainer.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: Padding.One)
|
stack.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
||||||
titleContainerDistance?.isActive = true
|
stack.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
||||||
entryFieldContainerLeading = entryFieldContainer.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
stack.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor).isActive = true
|
||||||
entryFieldContainerLeading?.isActive = true
|
stack.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
|
||||||
entryFieldContainerTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: entryFieldContainer.trailingAnchor)
|
|
||||||
entryFieldContainerTrailing?.isActive = true
|
|
||||||
|
|
||||||
addSubview(feedbackLabel)
|
|
||||||
|
|
||||||
feedbackContainerDistance = feedbackLabel.topAnchor.constraint(equalTo: entryFieldContainer.bottomAnchor, constant: Padding.Two)
|
|
||||||
feedbackContainerDistance?.isActive = true
|
|
||||||
feedbackLabelLeading = feedbackLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
|
||||||
feedbackLabelLeading?.isActive = true
|
|
||||||
feedbackLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: feedbackLabel.trailingAnchor)
|
|
||||||
feedbackLabelTrailing?.isActive = true
|
|
||||||
layoutMarginsGuide.bottomAnchor.constraint(equalTo: feedbackLabel.bottomAnchor).isActive = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc open override func layoutSubviews() {
|
@objc open override func layoutSubviews() {
|
||||||
@ -247,8 +235,10 @@ import UIKit
|
|||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
|
|
||||||
titleLabel.updateView(size)
|
titleLabel.updateView(size)
|
||||||
|
errorLabel.updateView(size)
|
||||||
feedbackLabel.updateView(size)
|
feedbackLabel.updateView(size)
|
||||||
entryFieldContainer.updateView(size)
|
entryFieldContainer.updateView(size)
|
||||||
|
stack.updateView(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -306,6 +296,9 @@ import UIKit
|
|||||||
titleLabel.textColor = .mvmBlack
|
titleLabel.textColor = .mvmBlack
|
||||||
feedbackLabel.font = Styler.Font.RegularMicro.getFont()
|
feedbackLabel.font = Styler.Font.RegularMicro.getFont()
|
||||||
feedbackLabel.textColor = .mvmBlack
|
feedbackLabel.textColor = .mvmBlack
|
||||||
|
errorLabel.font = Styler.Font.RegularMicro.getFont()
|
||||||
|
errorLabel.textColor = .mvmBlack
|
||||||
|
errorLabel.text = nil
|
||||||
entryFieldContainer.disableAllBorders = false
|
entryFieldContainer.disableAllBorders = false
|
||||||
feedbackLabel.text = nil
|
feedbackLabel.text = nil
|
||||||
entryFieldContainer.reset()
|
entryFieldContainer.reset()
|
||||||
@ -324,9 +317,9 @@ import UIKit
|
|||||||
titleLabel.setup(model: model.titleStateLabel, delegateObject, additionalData)
|
titleLabel.setup(model: model.titleStateLabel, delegateObject, additionalData)
|
||||||
feedbackLabel.setup(model: model.feedbackStateLabel, delegateObject, additionalData)
|
feedbackLabel.setup(model: model.feedbackStateLabel, delegateObject, additionalData)
|
||||||
|
|
||||||
defaultText = model.text ?? ""
|
|
||||||
isEnabled = model.enabled
|
isEnabled = model.enabled
|
||||||
isReadOnly = model.readOnly
|
isReadOnly = model.readOnly
|
||||||
|
isRequired = model.required
|
||||||
model.updateUI = { [weak self] in
|
model.updateUI = { [weak self] in
|
||||||
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
@ -338,6 +331,7 @@ import UIKit
|
|||||||
self.showError = false
|
self.showError = false
|
||||||
}
|
}
|
||||||
self.isEnabled = model.enabled
|
self.isEnabled = model.enabled
|
||||||
|
self.text = model.text
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,8 +382,8 @@ extension EntryField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension LabelModel {
|
extension LabelModel {
|
||||||
public convenience init(fontStyle: Styler.Font, textColor: Color) {
|
public convenience init(text: String = "", fontStyle: Styler.Font, textColor: Color) {
|
||||||
self.init(text: "")
|
self.init(text: text)
|
||||||
self.fontStyle = fontStyle
|
self.fontStyle = fontStyle
|
||||||
self.textColor = textColor
|
self.textColor = textColor
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user