Checkbox models added

Label action attribute issue fixed
This commit is contained in:
Chintakrinda, Arun Kumar (Arun) 2020-01-22 20:27:14 +05:30
parent 00d1bf7be6
commit 5534f6ba58
7 changed files with 213 additions and 1 deletions

View File

@ -88,6 +88,8 @@
0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; };
0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; };
0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; };
31BE15CB23D8924D00452370 /* CheckboxWithLabelViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */; };
31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; };
943784F5236B77BB006A1E82 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F3236B77BB006A1E82 /* GraphView.swift */; };
943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */; };
9445890C2385BCE300DE9FD4 /* ProgressBarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */; };
@ -382,6 +384,8 @@
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>"; };
0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxWithLabelViewModel.swift; sourceTree = "<group>"; };
31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = "<group>"; };
9402C34F23A2CEA3004B974C /* LeftRightLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftRightLabelModel.swift; sourceTree = "<group>"; };
943784F3236B77BB006A1E82 /* GraphView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphView.swift; sourceTree = "<group>"; };
943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphViewAnimationHandler.swift; sourceTree = "<group>"; };
@ -1143,7 +1147,9 @@
DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */,
94C2D9822386F3E30006CF46 /* Label */,
0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */,
31BE15CA23D8924C00452370 /* CheckboxModel.swift */,
0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */,
31BE15C923D8924C00452370 /* CheckboxWithLabelViewModel.swift */,
01004F2F22721C3800991ECC /* RadioButton.swift */,
D28A838223CCBD3F00DFE4FC /* CircleProgressModel.swift */,
943784F3236B77BB006A1E82 /* GraphView.swift */,
@ -1473,6 +1479,7 @@
files = (
0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */,
943784F5236B77BB006A1E82 /* GraphView.swift in Sources */,
31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */,
94C661DA23CCF4FB00D9FE5B /* UIColor+Extension.swift in Sources */,
D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */,
D28A838123CCB0D800DFE4FC /* AccordionListItemModel.swift in Sources */,
@ -1555,6 +1562,7 @@
DBEFFA04225A829700230692 /* Label.swift in Sources */,
D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */,
01509D952327ED1900EF99AA /* HeadlineBodyTextButtonSwitch.swift in Sources */,
31BE15CB23D8924D00452370 /* CheckboxWithLabelViewModel.swift in Sources */,
D260105523CEA7DC00764D80 /* MVMCoreUISwitch+Model.swift in Sources */,
D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */,
0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */,

View File

@ -458,6 +458,72 @@ import MVMCore
actionBlock = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
}
}
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
super.setWithModel(model, delegateObject, additionalData)
guard let checkboxModel = model as? CheckboxModel else {
return
}
self.delegateObject = delegateObject
FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
groupName = checkboxModel.groupName
fieldValue = checkboxModel.value
if let fieldKey = checkboxModel.fieldKey {
self.fieldKey = fieldKey
}
if let isRequired = checkboxModel.required {
self.isRequired = isRequired
}
if let borderColorHex = checkboxModel.borderColor {
layer.borderColor = UIColor.mfGet(forHex: borderColorHex).cgColor
}
if let borderWidth = checkboxModel.borderWidth {
layer.borderWidth = borderWidth
}
if let isChecked = checkboxModel.isChecked, isChecked {
updateSelectionOnly = true
isSelected = isChecked
updateSelectionOnly = false
}
if let checkColorHex = checkboxModel.checkColor {
checkColor = UIColor.mfGet(forHex: checkColorHex)
}
if let unCheckedBackgroundColorHex = checkboxModel.unCheckedBackgroundColor {
unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedBackgroundColorHex)
}
if let checkedBackgroundColorHex = checkboxModel.checkedBackgroundColor {
checkedBackgroundColor = UIColor.mfGet(forHex: checkedBackgroundColorHex)
}
if let isAnimated = checkboxModel.isAnimated {
self.isAnimated = isAnimated
}
if let isRound = checkboxModel.isRound {
self.isRound = isRound
}
if let enabled = checkboxModel.isEnabled {
isEnabled(enabled)
}
guard let action = checkboxModel.action else { return }
actionBlock = {
if let data = try? action.encode(using: JSONEncoder()),
let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] {
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
}
}
}
}
// MARK:- FormValidationProtocol

View File

@ -0,0 +1,83 @@
//
// CheckboxModel.swift
// MVMCoreUI
//
// Created by Chintakrinda, Arun Kumar (Arun) on 21/01/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
@objcMembers public class CheckboxModel: MoleculeModelProtocol {
public static var identifier: String = "checkbox"
public var backgroundColor: Color?
public var groupName: String?
public var value: String?
public var fieldKey: String?
public var required: Bool?
public var borderColor: String?
public var borderWidth: CGFloat?
public var isChecked: Bool?
public var checkColor: String?
public var unCheckedBackgroundColor: String?
public var checkedBackgroundColor: String?
public var isAnimated: Bool?
public var isRound: Bool?
public var isEnabled: Bool?
public var action: ActionModelProtocol?
enum CodingKeys: String, CodingKey {
case groupName
case value
case fieldKey
case required
case borderColor
case borderWidth
case isChecked
case checkColor
case unCheckedBackgroundColor
case checkedBackgroundColor
case isAnimated
case isRound
case isEnabled
case action
}
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName)
self.value = try typeContainer.decodeIfPresent(String.self, forKey: .value)
self.fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
self.required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required)
self.borderColor = try typeContainer.decodeIfPresent(String.self, forKey: .borderColor)
self.borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth)
self.isChecked = try typeContainer.decodeIfPresent(Bool.self, forKey: .isChecked)
self.checkColor = try typeContainer.decodeIfPresent(String.self, forKey: .checkColor)
self.unCheckedBackgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .unCheckedBackgroundColor)
self.checkedBackgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .checkedBackgroundColor)
self.isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated)
self.isRound = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRound)
self.isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled)
self.action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(groupName, forKey: .groupName)
try container.encodeIfPresent(value, forKey: .value)
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
try container.encodeIfPresent(required, forKey: .required)
try container.encodeIfPresent(borderColor, forKey: .borderColor)
try container.encodeIfPresent(borderColor, forKey: .borderColor)
try container.encodeIfPresent(isChecked, forKey: .isChecked)
try container.encodeIfPresent(checkColor, forKey: .checkColor)
try container.encodeIfPresent(unCheckedBackgroundColor, forKey: .unCheckedBackgroundColor)
try container.encodeIfPresent(checkedBackgroundColor, forKey: .checkedBackgroundColor)
try container.encodeIfPresent(isAnimated, forKey: .isAnimated)
try container.encodeIfPresent(isRound, forKey: .isRound)
try container.encodeIfPresent(isEnabled, forKey: .isEnabled)
try container.encodeModelIfPresent(action, forKey: .action)
}
}

View File

@ -120,6 +120,19 @@
checkboxCenterYConstraint?.isActive = false
}
}
open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
guard let checkBoxWithLabelModel = model as? CheckboxWithLabelViewModel else {
return
}
if let checkboxAlignment = checkBoxWithLabelModel.checkboxAlignment, let position = CheckboxPosition(rawValue: checkboxAlignment) {
alignCheckbox(position)
}
checkbox.setWithModel(checkBoxWithLabelModel.checkbox, delegateObject, additionalData)
label.setWithModel(checkBoxWithLabelModel.label, delegateObject, additionalData)
}
}
// MARK: - Molecular

View File

@ -0,0 +1,38 @@
//
// CheckboxWithLabelViewModel.swift
// MVMCoreUI
//
// Created by Chintakrinda, Arun Kumar (Arun) on 21/01/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
@objcMembers public class CheckboxWithLabelViewModel: MoleculeModelProtocol {
public static var identifier: String = "checkboxLabel"
public var backgroundColor: Color?
public var checkboxAlignment: String?
public var checkbox: CheckboxModel
public var label: LabelModel
enum CodingKeys: String, CodingKey {
case checkboxAlignment
case checkbox
case label
}
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.checkboxAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .checkboxAlignment)
self.checkbox = try typeContainer.decode(CheckboxModel.self, forKey: .checkbox)
self.label = try typeContainer.decode(LabelModel.self, forKey: .label)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(checkboxAlignment, forKey: .checkboxAlignment)
try container.encode(checkbox, forKey: .checkbox)
try container.encode(label, forKey: .label)
}
}

View File

@ -315,7 +315,7 @@ public typealias ActionBlock = () -> ()
}
case let actionAtt as LabelAttributeActionModel:
addTappableLinkAttribute(range: NSRange(location: range.location, length: range.length)) {
if let data = try? actionAtt.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] {
if let data = try? actionAtt.action.encode(using: JSONEncoder()), let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] {
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
}
}

View File

@ -71,5 +71,9 @@ import Foundation
ModelRegistry.register(NumberedListModel.self)
ModelRegistry.register(UnOrderedListModel.self)
ModelRegistry.register(HeadlineBodyToggleModel.self)
//Checkbox
ModelRegistry.register(CheckboxModel.self)
ModelRegistry.register(CheckboxWithLabelViewModel.self)
}
}