diabled functionality

This commit is contained in:
Kevin G Christiano 2020-01-23 12:55:21 -05:00
parent 2100468899
commit ea40da2c90
2 changed files with 40 additions and 25 deletions

View File

@ -88,13 +88,14 @@ import MVMCore
} else {
layer.borderColor = disabledBorderColor.cgColor
backgroundColor = disabledBackgroundColor
setShapeLayerStrokeColor(UIColor.mfSilver())
setShapeLayerStrokeColor(disabledCheckColor)
}
}
}
public var disabledBackgroundColor: UIColor = .clear
public var disabledBorderColor: UIColor = .mvmCoolGray3
public var disabledCheckColor: UIColor = .mvmCoolGray3
/// Color of the check mark.
public var checkColor: UIColor = .black {
@ -241,7 +242,7 @@ import MVMCore
self.shapeLayer = shapeLayer
shapeLayer.frame = bounds
layer.addSublayer(shapeLayer)
shapeLayer.strokeColor = checkColor.cgColor
shapeLayer.strokeColor = isEnabled ? checkColor.cgColor : disabledCheckColor.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.path = checkMarkPath()
shapeLayer.lineJoin = .miter
@ -422,14 +423,14 @@ import MVMCore
layer.borderWidth = borderWidth
}
if let isChecked = dictionary["isChecked"] as? Bool, isChecked {
checkAndBypassAnimations(selected: isChecked)
}
if let checkColorHex = dictionary["checkColor"] as? String {
checkColor = UIColor.mfGet(forHex: checkColorHex)
}
if let isChecked = dictionary["isChecked"] as? Bool, isChecked {
checkAndBypassAnimations(selected: isChecked)
}
if let unCheckedBackgroundColorHex = dictionary["unCheckedBackgroundColor"] as? String {
unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedBackgroundColorHex)
}
@ -458,34 +459,39 @@ import MVMCore
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.setWithModel(model, delegateObject, additionalData)
guard let checkboxModel = model as? CheckboxModel else { return }
guard let model = model as? CheckboxModel else { return }
self.delegateObject = delegateObject
FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
groupName = checkboxModel.groupName
fieldValue = checkboxModel.value
isRequired = checkboxModel.required
groupName = model.groupName
fieldValue = model.value
isRequired = model.required
if let fieldKey = checkboxModel.fieldKey {
if let fieldKey = model.fieldKey {
self.fieldKey = fieldKey
}
borderColor = checkboxModel.borderColor.uiColor
borderWidth = checkboxModel.borderWidth
borderColor = model.borderColor.uiColor
borderWidth = model.borderWidth
if checkboxModel.isChecked {
checkAndBypassAnimations(selected: checkboxModel.isChecked)
checkColor = model.checkColor.uiColor
unCheckedBackgroundColor = model.unCheckedBackgroundColor.uiColor
checkedBackgroundColor = model.checkedBackgroundColor.uiColor
disabledCheckColor = model.disabledCheckColor.uiColor
disabledBorderColor = model.disabledBorderColor.uiColor
disabledBackgroundColor = model.disabledBackgroundColor.uiColor
isAnimated = model.isAnimated
isRound = model.isRound
if model.isChecked {
checkAndBypassAnimations(selected: model.isChecked)
}
checkColor = checkboxModel.checkColor.uiColor
unCheckedBackgroundColor = checkboxModel.unCheckedBackgroundColor.uiColor
checkedBackgroundColor = checkboxModel.checkedBackgroundColor.uiColor
isAnimated = checkboxModel.isAnimated
isRound = checkboxModel.isRound
isEnabled = checkboxModel.isEnabled
isEnabled = model.isEnabled
if let action = checkboxModel.action {
if let action = model.action {
actionBlock = {
if let actionMap = action.toJSON() {
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)

View File

@ -30,10 +30,10 @@ import Foundation
public var isRound: Bool = false
public var isEnabled: Bool = true
public var action: ActionModelProtocol?
public var disabledBackgroundColor: Color = Color(uiColor: .clear)
public var disabledBorderColor: Color = Color(uiColor: .mvmCoolGray3)
public var disabledCheckColor: Color = Color(uiColor: .mvmCoolGray3)
public var disabledBackgroundColor: Color = Color(uiColor: .black)
public var disabledBorderColor: Color = Color(uiColor: .black)
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
@ -49,6 +49,9 @@ import Foundation
case checkColor
case unCheckedBackgroundColor
case checkedBackgroundColor
case disabledBackgroundColor
case disabledCheckColor
case disabledBorderColor
case isAnimated
case isRound
case isEnabled
@ -70,6 +73,9 @@ import Foundation
checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) ?? Color(uiColor: .black)
unCheckedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .unCheckedBackgroundColor) ?? Color(uiColor: .clear)
checkedBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkedBackgroundColor) ?? Color(uiColor: .clear)
disabledBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBackgroundColor) ?? Color(uiColor: .clear)
disabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBorderColor) ?? Color(uiColor: .mvmCoolGray3)
disabledCheckColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledCheckColor) ?? Color(uiColor: .mvmCoolGray3)
isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked) ?? false
isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) ?? true
isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound) ?? false
@ -89,6 +95,9 @@ import Foundation
try container.encodeIfPresent(checkColor, forKey: .checkColor)
try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor)
try container.encodeIfPresent(checkedBackgroundColor, forKey: .checkedBackgroundColor)
try container.encodeIfPresent(disabledBorderColor, forKey: .disabledBorderColor)
try container.encodeIfPresent(disabledBackgroundColor, forKey: .disabledBackgroundColor)
try container.encodeIfPresent(disabledCheckColor, forKey: .disabledCheckColor)
try container.encodeIfPresent(isAnimated, forKey: .isAnimated)
try container.encodeIfPresent(isRound, forKey: .isRound)
try container.encodeIfPresent(isEnabled, forKey: .isEnabled)