refactored StateLabelModel/StateLabel to FormLabelModel/FormLabel
removed state (error/disabled/error) replace with enabled (model) / isEnabled (view) Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
95b32491d1
commit
8444ad15eb
@ -578,8 +578,8 @@
|
||||
EAA0CFAF275E7D8000D65EB0 /* FormFieldEffectProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA0CFAE275E7D8000D65EB0 /* FormFieldEffectProtocol.swift */; };
|
||||
EAA0CFB1275E823A00D65EB0 /* HideFormFieldEffectModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA0CFB0275E823A00D65EB0 /* HideFormFieldEffectModel.swift */; };
|
||||
EAA0CFB3275E831E00D65EB0 /* DisableFormFieldEffectModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA0CFB2275E831E00D65EB0 /* DisableFormFieldEffectModel.swift */; };
|
||||
EABFC1412763BB8D00E78B40 /* StateLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABFC1402763BB8D00E78B40 /* StateLabel.swift */; };
|
||||
EABFC152276913E800E78B40 /* StateLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABFC151276913E800E78B40 /* StateLabelModel.swift */; };
|
||||
EABFC1412763BB8D00E78B40 /* FormLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABFC1402763BB8D00E78B40 /* FormLabel.swift */; };
|
||||
EABFC152276913E800E78B40 /* FormLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABFC151276913E800E78B40 /* FormLabelModel.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@ -1157,8 +1157,8 @@
|
||||
EAA0CFAE275E7D8000D65EB0 /* FormFieldEffectProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormFieldEffectProtocol.swift; sourceTree = "<group>"; };
|
||||
EAA0CFB0275E823A00D65EB0 /* HideFormFieldEffectModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HideFormFieldEffectModel.swift; sourceTree = "<group>"; };
|
||||
EAA0CFB2275E831E00D65EB0 /* DisableFormFieldEffectModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisableFormFieldEffectModel.swift; sourceTree = "<group>"; };
|
||||
EABFC1402763BB8D00E78B40 /* StateLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateLabel.swift; sourceTree = "<group>"; };
|
||||
EABFC151276913E800E78B40 /* StateLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateLabelModel.swift; sourceTree = "<group>"; };
|
||||
EABFC1402763BB8D00E78B40 /* FormLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormLabel.swift; sourceTree = "<group>"; };
|
||||
EABFC151276913E800E78B40 /* FormLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormLabelModel.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -1449,8 +1449,8 @@
|
||||
94C2D9A823872E5E0006CF46 /* LabelAttributeImageModel.swift */,
|
||||
94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */,
|
||||
DB891E822253FA8500022516 /* Label.swift */,
|
||||
EABFC151276913E800E78B40 /* StateLabelModel.swift */,
|
||||
EABFC1402763BB8D00E78B40 /* StateLabel.swift */,
|
||||
EABFC151276913E800E78B40 /* FormLabelModel.swift */,
|
||||
EABFC1402763BB8D00E78B40 /* FormLabel.swift */,
|
||||
);
|
||||
path = Label;
|
||||
sourceTree = "<group>";
|
||||
@ -2573,7 +2573,7 @@
|
||||
324FB6AA249366F3002552C7 /* ListLeftVariableNumberedListBodyTextModel.swift in Sources */,
|
||||
5248BFED23F12E350059236A /* ListThreeColumnPlanDataDividerModel.swift in Sources */,
|
||||
AA0A257824766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift in Sources */,
|
||||
EABFC152276913E800E78B40 /* StateLabelModel.swift in Sources */,
|
||||
EABFC152276913E800E78B40 /* FormLabelModel.swift in Sources */,
|
||||
0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */,
|
||||
0AF60F0926B3316E00AC3DB4 /* MVMCoreUIUtility+Extension.swift in Sources */,
|
||||
8D070BB0241B56530099AC56 /* ListRightVariableTotalDataModel.swift in Sources */,
|
||||
@ -2998,7 +2998,7 @@
|
||||
013F801923FB4A8E00AD8013 /* UIContentMode+Extension.swift in Sources */,
|
||||
AA104AC724472DB0004D2810 /* HeadersH1Button.swift in Sources */,
|
||||
525239C22407BD1000454969 /* ListTwoColumnPriceDetails.swift in Sources */,
|
||||
EABFC1412763BB8D00E78B40 /* StateLabel.swift in Sources */,
|
||||
EABFC1412763BB8D00E78B40 /* FormLabel.swift in Sources */,
|
||||
AA997252247530B100FC7472 /* ListLeftVariableIconAllTextLinks.swift in Sources */,
|
||||
D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */,
|
||||
D23EA7FB2475F09800D60C34 /* CarouselItemProtocol.swift in Sources */,
|
||||
|
||||
@ -9,35 +9,31 @@
|
||||
import Foundation
|
||||
|
||||
/// Subclass of label that helps with different states
|
||||
public class StateLabel: Label {
|
||||
public class FormLabel: Label {
|
||||
//properties used in setting label
|
||||
private var delegateObject: MVMCoreUIDelegateObject?
|
||||
private var additionalData: [AnyHashable: Any]?
|
||||
|
||||
//models that drive the label UI
|
||||
private var stateModel: StateLabelModel!
|
||||
private var formModel: FormLabelModel!
|
||||
|
||||
//public properties
|
||||
public override var isEnabled: Bool {
|
||||
didSet{
|
||||
self.state = isEnabled ? .enabled : .disabled
|
||||
self.formModel.enabled = isEnabled
|
||||
self.set(with: isRequired ? formModel.model : formModel.requiredModel, delegateObject, additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
public var isRequired: Bool = true {
|
||||
didSet{
|
||||
self.set(with: isRequired ? formModel.model : formModel.requiredModel, delegateObject, additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
public override func reset(){
|
||||
super.reset()
|
||||
self.state = .enabled
|
||||
}
|
||||
|
||||
//current mode of label
|
||||
public var state: StateLabelModel.State {
|
||||
get {
|
||||
return self.stateModel.state
|
||||
}
|
||||
set {
|
||||
self.stateModel.state = newValue
|
||||
self.set(with: stateModel.model, delegateObject, additionalData)
|
||||
}
|
||||
self.isEnabled = true
|
||||
}
|
||||
|
||||
/// Used in setting up the Label for use
|
||||
@ -46,25 +42,18 @@ public class StateLabel: Label {
|
||||
/// - model: Model takes priority over a text value. The model has its own text value that will be looked at to draw the screen, this model is used for both enabled/disabled models
|
||||
/// - delegateObject: passed in from the creator
|
||||
/// - additionalData: passed in from the creator
|
||||
public func setup(model: StateLabelModel, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?){
|
||||
public func setup(model: FormLabelModel, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?){
|
||||
self.additionalData = additionalData
|
||||
self.delegateObject = delegateObject
|
||||
self.stateModel = model
|
||||
self.formModel = model
|
||||
|
||||
//default to enabled state
|
||||
self.reset()
|
||||
}
|
||||
|
||||
/// Use this to switch the label into a error state
|
||||
/// - Parameter message: message to show in the errorModel
|
||||
public func showError(message: String){
|
||||
self.stateModel.set(text: message, for: .error)
|
||||
self.state = .error
|
||||
}
|
||||
|
||||
/// Text change that will update both enabledModel and disabledModel text values
|
||||
/// - Parameter text: text you want to see
|
||||
public func set(text: String?){
|
||||
self.stateModel.set(text: text ?? "", for: .enabled)
|
||||
self.formModel.set(text: text ?? "")
|
||||
}
|
||||
}
|
||||
@ -8,37 +8,23 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public class StateLabelModel {
|
||||
public class FormLabelModel: EnableableModelProtocol {
|
||||
static let defaultFontStyle = Styler.Font.RegularMicro
|
||||
static let defaultEnabledTextColor = Color(uiColor: .mvmBlack)
|
||||
static let defaultDisabledTextColor = Color(uiColor: .mvmCoolGray3)
|
||||
static let defaultErrorTextColor = Color(uiColor: .mvmBlack)
|
||||
static let defaultRequiredTextColor = Color(uiColor: .mvmCoolGray6)
|
||||
|
||||
private var enabledModel: LabelModel
|
||||
private var disabledModel = LabelModel(fontStyle: StateLabelModel.defaultFontStyle, textColor: StateLabelModel.defaultDisabledTextColor)
|
||||
private var errorLabelModel = LabelModel(fontStyle: StateLabelModel.defaultFontStyle, textColor: StateLabelModel.defaultErrorTextColor)
|
||||
private var disabledModel = LabelModel(fontStyle: FormLabelModel.defaultFontStyle, textColor: FormLabelModel.defaultDisabledTextColor)
|
||||
|
||||
public enum State {
|
||||
case enabled
|
||||
case disabled
|
||||
case error
|
||||
}
|
||||
|
||||
//current state
|
||||
public var state: State = .enabled
|
||||
public var enabled: Bool = true
|
||||
|
||||
//model is based on current state
|
||||
public var model: LabelModel {
|
||||
switch state {
|
||||
case .enabled:
|
||||
return enabledModel
|
||||
case .disabled:
|
||||
return disabledModel
|
||||
case .error:
|
||||
return errorLabelModel
|
||||
}
|
||||
return enabled ? enabledModel: disabledModel
|
||||
}
|
||||
|
||||
|
||||
//init
|
||||
public init(model: LabelModel){
|
||||
|
||||
@ -48,13 +34,13 @@ public class StateLabelModel {
|
||||
if let modelFontStyle = model.fontStyle {
|
||||
self.disabledModel.fontStyle = modelFontStyle
|
||||
} else {
|
||||
model.fontStyle = StateLabelModel.defaultFontStyle
|
||||
model.fontStyle = FormLabelModel.defaultFontStyle
|
||||
}
|
||||
|
||||
//ensure the textColor is set
|
||||
//otherwise use the defaultEnabledTextColor
|
||||
if model.textColor == nil {
|
||||
model.textColor = StateLabelModel.defaultEnabledTextColor
|
||||
model.textColor = FormLabelModel.defaultEnabledTextColor
|
||||
}
|
||||
|
||||
//set the enabledModel to the model passed in
|
||||
@ -66,26 +52,30 @@ public class StateLabelModel {
|
||||
|
||||
public init(text: String){
|
||||
//create the enabled model
|
||||
self.enabledModel = LabelModel(fontStyle: StateLabelModel.defaultFontStyle, textColor: StateLabelModel.defaultEnabledTextColor)
|
||||
self.enabledModel = LabelModel(fontStyle: FormLabelModel.defaultFontStyle, textColor: FormLabelModel.defaultEnabledTextColor)
|
||||
self.enabledModel.text = text
|
||||
|
||||
//make sure the enabled & disabled text match
|
||||
self.disabledModel.text = self.enabledModel.text
|
||||
}
|
||||
|
||||
public var requiredModel: LabelModel {
|
||||
let required = LabelModel(fontStyle: model.fontStyle!, textColor: model.textColor!)
|
||||
if enabled {
|
||||
required.attributes = [LabelAttributeColorModel(FormLabelModel.defaultRequiredTextColor, model.text.count + 1, 8)]
|
||||
}
|
||||
required.text = "\(model.text) Optional"
|
||||
return required
|
||||
}
|
||||
|
||||
//methods
|
||||
public func reset(){
|
||||
self.state = .enabled
|
||||
self.enabled = true
|
||||
}
|
||||
|
||||
//set text for state
|
||||
public func set(text:String, for state: State){
|
||||
switch state {
|
||||
case .enabled, .disabled:
|
||||
self.enabledModel.text = text
|
||||
self.disabledModel.text = text
|
||||
case .error:
|
||||
self.errorLabelModel.text = text
|
||||
}
|
||||
public func set(text:String){
|
||||
self.enabledModel.text = text
|
||||
self.disabledModel.text = text
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user