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 { } else {
layer.borderColor = disabledBorderColor.cgColor layer.borderColor = disabledBorderColor.cgColor
backgroundColor = disabledBackgroundColor backgroundColor = disabledBackgroundColor
setShapeLayerStrokeColor(UIColor.mfSilver()) setShapeLayerStrokeColor(disabledCheckColor)
} }
} }
} }
public var disabledBackgroundColor: UIColor = .clear public var disabledBackgroundColor: UIColor = .clear
public var disabledBorderColor: UIColor = .mvmCoolGray3 public var disabledBorderColor: UIColor = .mvmCoolGray3
public var disabledCheckColor: UIColor = .mvmCoolGray3
/// Color of the check mark. /// Color of the check mark.
public var checkColor: UIColor = .black { public var checkColor: UIColor = .black {
@ -241,7 +242,7 @@ import MVMCore
self.shapeLayer = shapeLayer self.shapeLayer = shapeLayer
shapeLayer.frame = bounds shapeLayer.frame = bounds
layer.addSublayer(shapeLayer) layer.addSublayer(shapeLayer)
shapeLayer.strokeColor = checkColor.cgColor shapeLayer.strokeColor = isEnabled ? checkColor.cgColor : disabledCheckColor.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.path = checkMarkPath() shapeLayer.path = checkMarkPath()
shapeLayer.lineJoin = .miter shapeLayer.lineJoin = .miter
@ -422,14 +423,14 @@ import MVMCore
layer.borderWidth = borderWidth layer.borderWidth = borderWidth
} }
if let isChecked = dictionary["isChecked"] as? Bool, isChecked {
checkAndBypassAnimations(selected: isChecked)
}
if let checkColorHex = dictionary["checkColor"] as? String { if let checkColorHex = dictionary["checkColor"] as? String {
checkColor = UIColor.mfGet(forHex: checkColorHex) checkColor = UIColor.mfGet(forHex: checkColorHex)
} }
if let isChecked = dictionary["isChecked"] as? Bool, isChecked {
checkAndBypassAnimations(selected: isChecked)
}
if let unCheckedBackgroundColorHex = dictionary["unCheckedBackgroundColor"] as? String { if let unCheckedBackgroundColorHex = dictionary["unCheckedBackgroundColor"] as? String {
unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedBackgroundColorHex) unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedBackgroundColorHex)
} }
@ -458,34 +459,39 @@ 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 model = 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 = model.groupName
fieldValue = checkboxModel.value fieldValue = model.value
isRequired = checkboxModel.required isRequired = model.required
if let fieldKey = checkboxModel.fieldKey { if let fieldKey = model.fieldKey {
self.fieldKey = fieldKey self.fieldKey = fieldKey
} }
borderColor = checkboxModel.borderColor.uiColor borderColor = model.borderColor.uiColor
borderWidth = checkboxModel.borderWidth borderWidth = model.borderWidth
if checkboxModel.isChecked { checkColor = model.checkColor.uiColor
checkAndBypassAnimations(selected: checkboxModel.isChecked) 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 isEnabled = model.isEnabled
unCheckedBackgroundColor = checkboxModel.unCheckedBackgroundColor.uiColor
checkedBackgroundColor = checkboxModel.checkedBackgroundColor.uiColor
isAnimated = checkboxModel.isAnimated
isRound = checkboxModel.isRound
isEnabled = checkboxModel.isEnabled
if let action = checkboxModel.action { if let action = model.action {
actionBlock = { actionBlock = {
if let actionMap = action.toJSON() { if let actionMap = action.toJSON() {
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)

View File

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