checkbox modeling. Strange issue with EntryFieldContainer. To be observed.
This commit is contained in:
parent
611246cb14
commit
4cc5a15db9
@ -84,9 +84,9 @@
|
|||||||
0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; };
|
0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; };
|
||||||
0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; };
|
0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; };
|
||||||
0AA33B3A2398524F0067DD0F /* Toggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B392398524F0067DD0F /* Toggle.swift */; };
|
0AA33B3A2398524F0067DD0F /* Toggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA33B392398524F0067DD0F /* Toggle.swift */; };
|
||||||
0ABD136B237B193A0081388D /* EntryFieldContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136A237B193A0081388D /* EntryFieldContainer.swift */; };
|
|
||||||
0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; };
|
0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; };
|
||||||
0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; };
|
0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; };
|
||||||
|
0ACDF26B23DA0AC2002044B2 /* EntryFieldContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ACDF26A23DA0AC2002044B2 /* EntryFieldContainer.swift */; };
|
||||||
0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; };
|
0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; };
|
||||||
31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; };
|
31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; };
|
||||||
31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; };
|
31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; };
|
||||||
@ -381,9 +381,9 @@
|
|||||||
0A8321AE2355FE9500CB7F00 /* DigitBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DigitBox.swift; sourceTree = "<group>"; };
|
0A8321AE2355FE9500CB7F00 /* DigitBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DigitBox.swift; sourceTree = "<group>"; };
|
||||||
0AA33B33239813C50067DD0F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = "<group>"; };
|
0AA33B33239813C50067DD0F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = "<group>"; };
|
||||||
0AA33B392398524F0067DD0F /* Toggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toggle.swift; sourceTree = "<group>"; };
|
0AA33B392398524F0067DD0F /* Toggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toggle.swift; sourceTree = "<group>"; };
|
||||||
0ABD136A237B193A0081388D /* EntryFieldContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryFieldContainer.swift; sourceTree = "<group>"; };
|
|
||||||
0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryField.swift; sourceTree = "<group>"; };
|
0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryField.swift; sourceTree = "<group>"; };
|
||||||
0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemDropdownEntryField.swift; sourceTree = "<group>"; };
|
0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemDropdownEntryField.swift; sourceTree = "<group>"; };
|
||||||
|
0ACDF26A23DA0AC2002044B2 /* EntryFieldContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EntryFieldContainer.swift; sourceTree = "<group>"; };
|
||||||
0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
|
0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
|
||||||
31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = "<group>"; };
|
31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = "<group>"; };
|
||||||
31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = "<group>"; };
|
31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = "<group>"; };
|
||||||
@ -691,7 +691,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
D29E28DE23D740FC00ACEA85 /* Container */,
|
D29E28DE23D740FC00ACEA85 /* Container */,
|
||||||
0ABD136A237B193A0081388D /* EntryFieldContainer.swift */,
|
0ACDF26A23DA0AC2002044B2 /* EntryFieldContainer.swift */,
|
||||||
014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */,
|
014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */,
|
||||||
D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */,
|
D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */,
|
||||||
);
|
);
|
||||||
@ -1603,6 +1603,7 @@
|
|||||||
017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */,
|
017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */,
|
||||||
D274CA332236A78900B01B62 /* FooterView.swift in Sources */,
|
D274CA332236A78900B01B62 /* FooterView.swift in Sources */,
|
||||||
D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */,
|
D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */,
|
||||||
|
0ACDF26B23DA0AC2002044B2 /* EntryFieldContainer.swift in Sources */,
|
||||||
014AA72423C501E2006F3E93 /* MoleculeContainerModel.swift in Sources */,
|
014AA72423C501E2006F3E93 /* MoleculeContainerModel.swift in Sources */,
|
||||||
D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */,
|
D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */,
|
||||||
011B58F223A2AE2C0085F53C /* DropDownListItemModel.swift in Sources */,
|
011B58F223A2AE2C0085F53C /* DropDownListItemModel.swift in Sources */,
|
||||||
@ -1684,7 +1685,6 @@
|
|||||||
D2B18B922361E65A00A9AEDC /* CoreUIObject.swift in Sources */,
|
D2B18B922361E65A00A9AEDC /* CoreUIObject.swift in Sources */,
|
||||||
D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */,
|
D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */,
|
||||||
014AA72E23C5059B006F3E93 /* StackCenteredPageTemplateModel.swift in Sources */,
|
014AA72E23C5059B006F3E93 /* StackCenteredPageTemplateModel.swift in Sources */,
|
||||||
0ABD136B237B193A0081388D /* EntryFieldContainer.swift in Sources */,
|
|
||||||
D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */,
|
D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */,
|
||||||
D260105923D0A92900764D80 /* ContainerProtocol.swift in Sources */,
|
D260105923D0A92900764D80 /* ContainerProtocol.swift in Sources */,
|
||||||
C695A69423C9909000BFB94E /* DoughnutChartModel.swift in Sources */,
|
C695A69423C9909000BFB94E /* DoughnutChartModel.swift in Sources */,
|
||||||
|
|||||||
@ -76,6 +76,24 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open override var isEnabled: Bool {
|
||||||
|
didSet {
|
||||||
|
|
||||||
|
isUserInteractionEnabled = isEnabled
|
||||||
|
|
||||||
|
if isEnabled {
|
||||||
|
layer.borderColor = borderColor.cgColor
|
||||||
|
backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor
|
||||||
|
setShapeLayerStrokeColor(checkColor)
|
||||||
|
} else {
|
||||||
|
layer.borderColor = UIColor.mfSilver().cgColor
|
||||||
|
backgroundColor = .clear
|
||||||
|
setShapeLayerStrokeColor(UIColor.mfSilver())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// public var disabledColor: (check: UIColor?, background: UIColor?, border: UIColor?)
|
||||||
|
|
||||||
/// Color of the check mark.
|
/// Color of the check mark.
|
||||||
public var checkColor: UIColor = .black {
|
public var checkColor: UIColor = .black {
|
||||||
didSet {
|
didSet {
|
||||||
@ -107,7 +125,6 @@ import MVMCore
|
|||||||
if !updateSelectionOnly {
|
if !updateSelectionOnly {
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
shapeLayer?.removeAllAnimations()
|
shapeLayer?.removeAllAnimations()
|
||||||
|
|
||||||
updateCheckboxUI(isSelected: isSelected, isAnimated: isAnimated)
|
updateCheckboxUI(isSelected: isSelected, isAnimated: isAnimated)
|
||||||
FormValidator.enableByValidationWith(delegate: delegateObject?.formValidationProtocol)
|
FormValidator.enableByValidationWith(delegate: delegateObject?.formValidationProtocol)
|
||||||
updateAccessibilityLabel()
|
updateAccessibilityLabel()
|
||||||
@ -154,16 +171,12 @@ import MVMCore
|
|||||||
|
|
||||||
public convenience init(isChecked: Bool) {
|
public convenience init(isChecked: Bool) {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
updateSelectionOnly = true
|
checkAndBypassAnimations(selected: isChecked)
|
||||||
isSelected = isChecked
|
|
||||||
updateSelectionOnly = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init(checkedBackgroundColor: UIColor, unCheckedBackgroundColor: UIColor, isChecked: Bool = false) {
|
public convenience init(checkedBackgroundColor: UIColor, unCheckedBackgroundColor: UIColor, isChecked: Bool = false) {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
updateSelectionOnly = true
|
checkAndBypassAnimations(selected: isChecked)
|
||||||
isSelected = isChecked
|
|
||||||
updateSelectionOnly = false
|
|
||||||
self.checkedBackgroundColor = checkedBackgroundColor
|
self.checkedBackgroundColor = checkedBackgroundColor
|
||||||
self.unCheckedBackgroundColor = unCheckedBackgroundColor
|
self.unCheckedBackgroundColor = unCheckedBackgroundColor
|
||||||
}
|
}
|
||||||
@ -177,8 +190,6 @@ import MVMCore
|
|||||||
|
|
||||||
drawShapeLayer()
|
drawShapeLayer()
|
||||||
layer.cornerRadius = isRound ? cornerRadiusValue : 0
|
layer.cornerRadius = isRound ? cornerRadiusValue : 0
|
||||||
layer.borderWidth = borderWidth
|
|
||||||
layer.borderColor = borderColor.cgColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
@ -268,9 +279,7 @@ import MVMCore
|
|||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
||||||
self.updateSelectionOnly = true
|
self.checkAndBypassAnimations(selected: selected)
|
||||||
self.isSelected = selected
|
|
||||||
self.updateSelectionOnly = false
|
|
||||||
self.drawShapeLayer()
|
self.drawShapeLayer()
|
||||||
self.shapeLayer?.removeAllAnimations()
|
self.shapeLayer?.removeAllAnimations()
|
||||||
self.updateCheckboxUI(isSelected: selected, isAnimated: animated)
|
self.updateCheckboxUI(isSelected: selected, isAnimated: animated)
|
||||||
@ -313,23 +322,6 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isEnabled(_ enabled: Bool) {
|
|
||||||
|
|
||||||
isUserInteractionEnabled = enabled
|
|
||||||
|
|
||||||
if enabled {
|
|
||||||
layer.borderColor = borderColor.cgColor
|
|
||||||
backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor
|
|
||||||
alpha = 1.0
|
|
||||||
setShapeLayerStrokeColor(checkColor)
|
|
||||||
} else {
|
|
||||||
layer.borderColor = UIColor.mfSilver().cgColor
|
|
||||||
backgroundColor = .clear
|
|
||||||
alpha = DisableOppacity
|
|
||||||
setShapeLayerStrokeColor(UIColor.mfSilver())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func setShapeLayerStrokeColor(_ color: UIColor) {
|
private func setShapeLayerStrokeColor(_ color: UIColor) {
|
||||||
|
|
||||||
if let shapeLayer = shapeLayer {
|
if let shapeLayer = shapeLayer {
|
||||||
@ -345,13 +337,19 @@ import MVMCore
|
|||||||
widthConstraint?.isActive = isActive
|
widthConstraint?.isActive = isActive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func checkAndBypassAnimations(selected: Bool) {
|
||||||
|
updateSelectionOnly = true
|
||||||
|
isSelected = selected
|
||||||
|
updateSelectionOnly = false
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - UITouch
|
// MARK: - UITouch
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
|
|
||||||
sendActions(for: .touchUpInside)
|
sendActions(for: .touchUpInside)
|
||||||
}
|
}
|
||||||
|
|
||||||
override open func accessibilityActivate() -> Bool {
|
override open func accessibilityActivate() -> Bool {
|
||||||
@ -370,7 +368,7 @@ import MVMCore
|
|||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
|
|
||||||
isEnabled(true)
|
isEnabled = true
|
||||||
shapeLayer?.removeAllAnimations()
|
shapeLayer?.removeAllAnimations()
|
||||||
shapeLayer?.removeFromSuperlayer()
|
shapeLayer?.removeFromSuperlayer()
|
||||||
shapeLayer = nil
|
shapeLayer = nil
|
||||||
@ -379,9 +377,7 @@ import MVMCore
|
|||||||
borderWidth = 1.0
|
borderWidth = 1.0
|
||||||
checkColor = .black
|
checkColor = .black
|
||||||
checkWidth = 2.0
|
checkWidth = 2.0
|
||||||
updateSelectionOnly = true
|
checkAndBypassAnimations(selected: false)
|
||||||
isSelected = false
|
|
||||||
updateSelectionOnly = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open func setAsMolecule() {
|
open func setAsMolecule() {
|
||||||
@ -425,9 +421,7 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let isChecked = dictionary["isChecked"] as? Bool, isChecked {
|
if let isChecked = dictionary["isChecked"] as? Bool, isChecked {
|
||||||
updateSelectionOnly = true
|
checkAndBypassAnimations(selected: isChecked)
|
||||||
isSelected = isChecked
|
|
||||||
updateSelectionOnly = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let checkColorHex = dictionary["checkColor"] as? String {
|
if let checkColorHex = dictionary["checkColor"] as? String {
|
||||||
@ -451,7 +445,7 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let enabled = dictionary["isEnabled"] as? Bool {
|
if let enabled = dictionary["isEnabled"] as? Bool {
|
||||||
isEnabled(enabled)
|
isEnabled = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if let actionMap = dictionary.optionalDictionaryForKey("action") {
|
if let actionMap = dictionary.optionalDictionaryForKey("action") {
|
||||||
@ -459,61 +453,35 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.setWithModel(model, delegateObject, additionalData)
|
super.setWithModel(model, delegateObject, additionalData)
|
||||||
guard let checkboxModel = model as? CheckboxModel else {
|
|
||||||
return
|
guard let checkboxModel = model as? CheckboxModel else { return }
|
||||||
}
|
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
|
FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
|
||||||
|
|
||||||
groupName = checkboxModel.groupName
|
groupName = checkboxModel.groupName
|
||||||
fieldValue = checkboxModel.value
|
fieldValue = checkboxModel.value
|
||||||
|
isRequired = checkboxModel.required
|
||||||
|
|
||||||
if let fieldKey = checkboxModel.fieldKey {
|
if let fieldKey = checkboxModel.fieldKey {
|
||||||
self.fieldKey = fieldKey
|
self.fieldKey = fieldKey
|
||||||
}
|
}
|
||||||
|
|
||||||
if let isRequired = checkboxModel.required {
|
borderColor = checkboxModel.borderColor.uiColor
|
||||||
self.isRequired = isRequired
|
borderWidth = checkboxModel.borderWidth
|
||||||
}
|
|
||||||
|
|
||||||
if let borderColor = checkboxModel.borderColor {
|
|
||||||
self.borderColor = borderColor.uiColor
|
|
||||||
}
|
|
||||||
|
|
||||||
if let borderWidth = checkboxModel.borderWidth {
|
|
||||||
self.borderWidth = borderWidth
|
|
||||||
}
|
|
||||||
|
|
||||||
if checkboxModel.isChecked {
|
if checkboxModel.isChecked {
|
||||||
updateSelectionOnly = true
|
checkAndBypassAnimations(selected: checkboxModel.isChecked)
|
||||||
isSelected = checkboxModel.isChecked
|
|
||||||
updateSelectionOnly = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let uiCheckColor = checkboxModel.checkColor?.uiColor {
|
checkColor = checkboxModel.checkColor.uiColor
|
||||||
checkColor = uiCheckColor
|
unCheckedBackgroundColor = checkboxModel.unCheckedBackgroundColor.uiColor
|
||||||
}
|
checkedBackgroundColor = checkboxModel.checkedBackgroundColor.uiColor
|
||||||
|
isAnimated = checkboxModel.isAnimated
|
||||||
if let unCheckedBackgroundColor = checkboxModel.unCheckedBackgroundColor {
|
isRound = checkboxModel.isRound
|
||||||
self.unCheckedBackgroundColor = unCheckedBackgroundColor.uiColor
|
isEnabled = checkboxModel.isEnabled
|
||||||
}
|
|
||||||
|
|
||||||
if let checkedBackgroundColor = checkboxModel.checkedBackgroundColor {
|
|
||||||
self.checkedBackgroundColor = checkedBackgroundColor.uiColor
|
|
||||||
}
|
|
||||||
|
|
||||||
if let isAnimated = checkboxModel.isAnimated {
|
|
||||||
self.isAnimated = isAnimated
|
|
||||||
}
|
|
||||||
|
|
||||||
if let isRound = checkboxModel.isRound {
|
|
||||||
self.isRound = isRound
|
|
||||||
}
|
|
||||||
|
|
||||||
if let enabled = checkboxModel.isEnabled {
|
|
||||||
isEnabled(enabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let action = checkboxModel.action {
|
if let action = checkboxModel.action {
|
||||||
actionBlock = {
|
actionBlock = {
|
||||||
|
|||||||
@ -15,16 +15,16 @@ import Foundation
|
|||||||
public var groupName: String?
|
public var groupName: String?
|
||||||
public var value: String?
|
public var value: String?
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var required: Bool?
|
public var required: Bool
|
||||||
public var borderColor: Color?
|
public var borderColor: Color
|
||||||
public var borderWidth: CGFloat?
|
public var borderWidth: CGFloat = 1
|
||||||
public var isChecked: Bool = false
|
public var isChecked: Bool = false
|
||||||
public var checkColor: Color?
|
public var checkColor: Color
|
||||||
public var unCheckedBackgroundColor: Color?
|
public var unCheckedBackgroundColor: Color
|
||||||
public var checkedBackgroundColor: Color?
|
public var checkedBackgroundColor: Color
|
||||||
public var isAnimated: Bool?
|
public var isAnimated: Bool = true
|
||||||
public var isRound: Bool?
|
public var isRound: Bool = false
|
||||||
public var isEnabled: Bool?
|
public var isEnabled: Bool = true
|
||||||
public var action: ActionModelProtocol?
|
public var action: ActionModelProtocol?
|
||||||
|
|
||||||
|
|
||||||
@ -47,20 +47,20 @@ import Foundation
|
|||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
self.groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName)
|
groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName)
|
||||||
self.value = try typeContainer.decodeIfPresent(String.self, forKey: .value)
|
value = try typeContainer.decodeIfPresent(String.self, forKey: .value)
|
||||||
self.fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||||
self.required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required)
|
required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) ?? false
|
||||||
self.borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor)
|
borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) ?? 1
|
||||||
self.borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth)
|
borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) ?? Color(uiColor: .black)
|
||||||
self.isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false
|
checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) ?? Color(uiColor: .black)
|
||||||
self.checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor)
|
unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor) ?? Color(uiColor: .clear)
|
||||||
self.unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor)
|
checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor) ?? Color(uiColor: .clear)
|
||||||
self.checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor)
|
isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false
|
||||||
self.isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated)
|
isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) ?? true
|
||||||
self.isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound)
|
isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) ?? false
|
||||||
self.isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled)
|
isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) ?? true
|
||||||
self.action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
@ -70,7 +70,7 @@ import Foundation
|
|||||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||||
try container.encodeIfPresent(required, forKey: .required)
|
try container.encodeIfPresent(required, forKey: .required)
|
||||||
try container.encodeIfPresent(borderColor, forKey: .borderColor)
|
try container.encodeIfPresent(borderColor, forKey: .borderColor)
|
||||||
try container.encodeIfPresent(borderColor, forKey: .borderColor)
|
try container.encode(borderWidth, forKey: .borderWidth)
|
||||||
try container.encode(isChecked, forKey: .isChecked)
|
try container.encode(isChecked, forKey: .isChecked)
|
||||||
try container.encodeIfPresent(checkColor, forKey: .checkColor)
|
try container.encodeIfPresent(checkColor, forKey: .checkColor)
|
||||||
try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor)
|
try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor)
|
||||||
|
|||||||
@ -1,285 +0,0 @@
|
|||||||
//
|
|
||||||
// EntryFieldContainer.swift
|
|
||||||
// MVMCoreUI
|
|
||||||
//
|
|
||||||
// Created by Kevin Christiano on 11/12/19.
|
|
||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
import UIKit
|
|
||||||
|
|
||||||
|
|
||||||
@objcMembers open class EntryFieldContainer: View {
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Drawing Properties
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
/// The bottom border line. Height is dynamic based on scenario.
|
|
||||||
public var bottomBar: CAShapeLayer? = {
|
|
||||||
let layer = CAShapeLayer()
|
|
||||||
layer.backgroundColor = UIColor.black.cgColor
|
|
||||||
layer.drawsAsynchronously = true
|
|
||||||
layer.anchorPoint = CGPoint(x: 0.5, y: 1.0);
|
|
||||||
return layer
|
|
||||||
}()
|
|
||||||
|
|
||||||
/// Total control over the drawn top, bottom, left and right borders.
|
|
||||||
public var disableAllBorders = false {
|
|
||||||
didSet {
|
|
||||||
bottomBar?.isHidden = disableAllBorders
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private(set) var fieldState: FieldState = .original {
|
|
||||||
didSet (oldState) {
|
|
||||||
// Will not update if new state is the same as old.
|
|
||||||
if fieldState != oldState {
|
|
||||||
DispatchQueue.main.async { [weak self] in
|
|
||||||
guard let self = self else { return }
|
|
||||||
|
|
||||||
self.fieldState.setStateUI(for: self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Determines if the top, left, and right borders should be drawn.
|
|
||||||
private var hideBorders = false
|
|
||||||
|
|
||||||
public var borderStrokeColor: UIColor = .mfSilver()
|
|
||||||
private var borderPath: UIBezierPath = UIBezierPath()
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Property Observers
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
private var _isEnabled: Bool = true
|
|
||||||
private var _showError: Bool = false
|
|
||||||
private var _isLocked: Bool = false
|
|
||||||
private var _isSelected: Bool = false
|
|
||||||
|
|
||||||
public var isEnabled: Bool {
|
|
||||||
get { return _isEnabled }
|
|
||||||
set (enabled) {
|
|
||||||
|
|
||||||
_isEnabled = enabled
|
|
||||||
_isLocked = false
|
|
||||||
_isSelected = false
|
|
||||||
_showError = false
|
|
||||||
|
|
||||||
fieldState = enabled ? .original : .disabled
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public var showError: Bool {
|
|
||||||
get { return _showError }
|
|
||||||
set (error) {
|
|
||||||
|
|
||||||
_showError = error
|
|
||||||
_isEnabled = true
|
|
||||||
_isLocked = false
|
|
||||||
_isSelected = false
|
|
||||||
|
|
||||||
fieldState = error ? .error : .original
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public var isLocked: Bool {
|
|
||||||
get { return _isLocked }
|
|
||||||
set (locked) {
|
|
||||||
|
|
||||||
_isLocked = locked
|
|
||||||
_isEnabled = true
|
|
||||||
_isSelected = false
|
|
||||||
_showError = false
|
|
||||||
|
|
||||||
fieldState = locked ? .locked : .original
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public var isSelected: Bool {
|
|
||||||
get { return _isSelected }
|
|
||||||
set (selected) {
|
|
||||||
|
|
||||||
_isSelected = selected
|
|
||||||
_isLocked = false
|
|
||||||
_isEnabled = true
|
|
||||||
|
|
||||||
if _showError {
|
|
||||||
fieldState = selected ? .selectedError : .error
|
|
||||||
} else {
|
|
||||||
fieldState = selected ? .selected : .original
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Delegate
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
/// Holds reference to delegateObject to inform molecular tableView of an update.
|
|
||||||
weak var delegateObject: MVMCoreUIDelegateObject?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Lifecycle
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
open override func layoutSubviews() {
|
|
||||||
super.layoutSubviews()
|
|
||||||
|
|
||||||
refreshUI(bottomBarSize: showError ? 4 : 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func updateView(_ size: CGFloat) {
|
|
||||||
super.updateView(size)
|
|
||||||
|
|
||||||
refreshUI()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This handles the top, left, and right border lines.
|
|
||||||
open override func draw(_ rect: CGRect) {
|
|
||||||
super.draw(rect)
|
|
||||||
|
|
||||||
borderPath.removeAllPoints()
|
|
||||||
|
|
||||||
if !disableAllBorders && !hideBorders {
|
|
||||||
// Brings the other half of the line inside the view to prevent cropping.
|
|
||||||
let origin = bounds.origin
|
|
||||||
let size = frame.size
|
|
||||||
let insetLean: CGFloat = 0.5
|
|
||||||
borderPath.lineWidth = 1
|
|
||||||
|
|
||||||
borderPath.move(to: CGPoint(x: origin.x + insetLean, y: origin.y + size.height))
|
|
||||||
borderPath.addLine(to: CGPoint(x: origin.x + insetLean, y: origin.y + insetLean))
|
|
||||||
borderPath.addLine(to: CGPoint(x: origin.x + size.width - insetLean, y: origin.y + insetLean))
|
|
||||||
borderPath.addLine(to: CGPoint(x: origin.x + size.width - insetLean, y: origin.y + size.height))
|
|
||||||
|
|
||||||
borderStrokeColor.setStroke()
|
|
||||||
borderPath.stroke()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override open func setupView() {
|
|
||||||
super.setupView()
|
|
||||||
|
|
||||||
isAccessibilityElement = false
|
|
||||||
isOpaque = false
|
|
||||||
|
|
||||||
if let bottomBar = bottomBar {
|
|
||||||
layer.addSublayer(bottomBar)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Draw States
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
public enum FieldState {
|
|
||||||
case original
|
|
||||||
case error
|
|
||||||
case selectedError
|
|
||||||
case selected
|
|
||||||
case locked
|
|
||||||
case disabled
|
|
||||||
|
|
||||||
public func setStateUI(for formField: EntryFieldContainer) {
|
|
||||||
|
|
||||||
switch self {
|
|
||||||
case .original:
|
|
||||||
formField.originalUI()
|
|
||||||
|
|
||||||
case .error:
|
|
||||||
formField.errorUI()
|
|
||||||
|
|
||||||
case .selectedError:
|
|
||||||
formField.selectedErrorUI()
|
|
||||||
|
|
||||||
case .selected:
|
|
||||||
formField.selectedUI()
|
|
||||||
|
|
||||||
case .locked:
|
|
||||||
formField.lockedUI()
|
|
||||||
|
|
||||||
case .disabled:
|
|
||||||
formField.disabledUI()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open func originalUI() {
|
|
||||||
|
|
||||||
isUserInteractionEnabled = true
|
|
||||||
hideBorders = false
|
|
||||||
borderStrokeColor = .mfSilver()
|
|
||||||
bottomBar?.backgroundColor = UIColor.black.cgColor
|
|
||||||
refreshUI(bottomBarSize: 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
open func errorUI() {
|
|
||||||
|
|
||||||
isUserInteractionEnabled = true
|
|
||||||
hideBorders = false
|
|
||||||
borderStrokeColor = .mfPumpkin()
|
|
||||||
bottomBar?.backgroundColor = UIColor.mfPumpkin().cgColor
|
|
||||||
refreshUI(bottomBarSize: 4)
|
|
||||||
}
|
|
||||||
|
|
||||||
open func selectedErrorUI() {
|
|
||||||
|
|
||||||
isUserInteractionEnabled = true
|
|
||||||
hideBorders = false
|
|
||||||
borderStrokeColor = .black
|
|
||||||
bottomBar?.backgroundColor = UIColor.mfPumpkin().cgColor
|
|
||||||
refreshUI(bottomBarSize: 4)
|
|
||||||
}
|
|
||||||
|
|
||||||
open func selectedUI() {
|
|
||||||
|
|
||||||
isUserInteractionEnabled = true
|
|
||||||
hideBorders = false
|
|
||||||
borderStrokeColor = .black
|
|
||||||
bottomBar?.backgroundColor = UIColor.black.cgColor
|
|
||||||
refreshUI(bottomBarSize: 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
open func lockedUI() {
|
|
||||||
|
|
||||||
isUserInteractionEnabled = false
|
|
||||||
hideBorders = true
|
|
||||||
borderStrokeColor = .clear
|
|
||||||
bottomBar?.backgroundColor = UIColor.clear.cgColor
|
|
||||||
refreshUI(bottomBarSize: 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
open func disabledUI() {
|
|
||||||
|
|
||||||
isUserInteractionEnabled = false
|
|
||||||
hideBorders = false
|
|
||||||
borderStrokeColor = .mfSilver()
|
|
||||||
bottomBar?.backgroundColor = UIColor.mfSilver().cgColor
|
|
||||||
refreshUI(bottomBarSize: 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
open func refreshUI(bottomBarSize: CGFloat? = nil) {
|
|
||||||
|
|
||||||
if !disableAllBorders {
|
|
||||||
let size: CGFloat = bottomBarSize ?? (showError ? 4 : 1)
|
|
||||||
bottomBar?.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size)
|
|
||||||
|
|
||||||
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
|
|
||||||
setNeedsDisplay()
|
|
||||||
layoutIfNeeded()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK:- MVMCoreUIMoleculeViewProtocol
|
|
||||||
extension EntryFieldContainer {
|
|
||||||
|
|
||||||
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 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user