adding accessibility id. formatting. adding test logic.
This commit is contained in:
parent
7dcf1279b7
commit
9baf9e7d0d
@ -71,6 +71,7 @@ import UIKit
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
addTarget(self, action: #selector(tapAction), for: .touchUpInside)
|
addTarget(self, action: #selector(tapAction), for: .touchUpInside)
|
||||||
@ -88,6 +89,7 @@ import UIKit
|
|||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
self.additionalData = additionalData
|
self.additionalData = additionalData
|
||||||
guard let model = model as? HeartModel else { return }
|
guard let model = model as? HeartModel else { return }
|
||||||
|
accessibilityIdentifier = model.accessibilityIdentifier
|
||||||
isSelected = model.isActive
|
isSelected = model.isActive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,15 +6,15 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
open class HeartModel: MoleculeModelProtocol {
|
open class HeartModel: MoleculeModelProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "heart"
|
public static var identifier: String = "heart"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
public var accessibilityIdentifier: String?
|
||||||
public var isActive: Bool = false
|
public var isActive: Bool = false
|
||||||
public var activeColor: Color = Color(uiColor: .mvmRed)
|
public var activeColor: Color = Color(uiColor: .mvmRed)
|
||||||
public var inActiveColor: Color = Color(uiColor: .clear)
|
public var inActiveColor: Color = Color(uiColor: .clear)
|
||||||
@ -23,9 +23,11 @@ open class HeartModel: MoleculeModelProtocol {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
case accessibilityIdentifier
|
||||||
case isActive
|
case isActive
|
||||||
case activeColor
|
case activeColor
|
||||||
case inActiveColor
|
case inActiveColor
|
||||||
@ -41,13 +43,18 @@ open class HeartModel: MoleculeModelProtocol {
|
|||||||
if let isActive = try typeContainer.decodeIfPresent(Bool.self, forKey: .isActive) {
|
if let isActive = try typeContainer.decodeIfPresent(Bool.self, forKey: .isActive) {
|
||||||
self.isActive = isActive
|
self.isActive = isActive
|
||||||
}
|
}
|
||||||
|
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
|
||||||
|
|
||||||
if let activeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .activeColor) {
|
if let activeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .activeColor) {
|
||||||
self.activeColor = activeColor
|
self.activeColor = activeColor
|
||||||
}
|
}
|
||||||
|
|
||||||
if let inActiveColor = try typeContainer.decodeIfPresent(Color.self, forKey: .inActiveColor) {
|
if let inActiveColor = try typeContainer.decodeIfPresent(Color.self, forKey: .inActiveColor) {
|
||||||
self.inActiveColor = inActiveColor
|
self.inActiveColor = inActiveColor
|
||||||
}
|
}
|
||||||
|
|
||||||
if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) {
|
if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) {
|
||||||
self.action = action
|
self.action = action
|
||||||
}
|
}
|
||||||
@ -56,6 +63,7 @@ open class HeartModel: MoleculeModelProtocol {
|
|||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encode(isActive, forKey: .isActive)
|
try container.encode(isActive, forKey: .isActive)
|
||||||
try container.encode(activeColor, forKey: .activeColor)
|
try container.encode(activeColor, forKey: .activeColor)
|
||||||
|
|||||||
@ -6,9 +6,12 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
open class RadioBox: Control, MFButtonProtocol {
|
open class RadioBox: Control, MFButtonProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public let label = Label(fontStyle: .RegularBodySmall)
|
public let label = Label(fontStyle: .RegularBodySmall)
|
||||||
public let subTextLabel = Label(fontStyle: .RegularMicro)
|
public let subTextLabel = Label(fontStyle: .RegularMicro)
|
||||||
public var isOutOfStock = false
|
public var isOutOfStock = false
|
||||||
@ -26,22 +29,20 @@ open class RadioBox: Control, MFButtonProtocol {
|
|||||||
var additionalData: [AnyHashable: Any]?
|
var additionalData: [AnyHashable: Any]?
|
||||||
|
|
||||||
public var radioBoxModel: RadioBoxModel? {
|
public var radioBoxModel: RadioBoxModel? {
|
||||||
return model as? RadioBoxModel
|
model as? RadioBoxModel
|
||||||
}
|
}
|
||||||
|
|
||||||
public override var isSelected: Bool {
|
public override var isSelected: Bool {
|
||||||
didSet {
|
didSet { updateAccessibility() }
|
||||||
updateAccessibility()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override var isEnabled: Bool {
|
public override var isEnabled: Bool {
|
||||||
didSet {
|
didSet { updateAccessibility() }
|
||||||
updateAccessibility()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
// MARK: - MVMCoreViewProtocol
|
// MARK: - MVMCoreViewProtocol
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
@ -75,8 +76,6 @@ open class RadioBox: Control, MFButtonProtocol {
|
|||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MoleculeViewProtocol
|
|
||||||
|
|
||||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
guard let model = model as? RadioBoxModel else { return }
|
guard let model = model as? RadioBoxModel else { return }
|
||||||
@ -86,6 +85,7 @@ open class RadioBox: Control, MFButtonProtocol {
|
|||||||
subTextLabel.text = model.subText
|
subTextLabel.text = model.subText
|
||||||
isOutOfStock = model.strikethrough
|
isOutOfStock = model.strikethrough
|
||||||
subTextLabelHeightConstraint?.isActive = (subTextLabel.text?.count ?? 0) == 0
|
subTextLabelHeightConstraint?.isActive = (subTextLabel.text?.count ?? 0) == 0
|
||||||
|
accessibilityIdentifier = model.accessibilityIdentifier
|
||||||
if let color = model.selectedAccentColor?.uiColor {
|
if let color = model.selectedAccentColor?.uiColor {
|
||||||
accentColor = color
|
accentColor = color
|
||||||
}
|
}
|
||||||
@ -99,7 +99,9 @@ open class RadioBox: Control, MFButtonProtocol {
|
|||||||
accentColor = .mvmRed
|
accentColor = .mvmRed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
// MARK: - State Handling
|
// MARK: - State Handling
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
||||||
// Draw the strikethrough
|
// Draw the strikethrough
|
||||||
@ -213,21 +215,29 @@ open class RadioBox: Control, MFButtonProtocol {
|
|||||||
return mask
|
return mask
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
// MARK: - Accessibility
|
// MARK: - Accessibility
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func updateAccessibility() {
|
public func updateAccessibility() {
|
||||||
|
|
||||||
var message = ""
|
var message = ""
|
||||||
|
|
||||||
if let labelText = label.text, label.hasText {
|
if let labelText = label.text, label.hasText {
|
||||||
message += labelText + ", "
|
message += labelText + ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
if let subLabelText = subTextLabel.text, subTextLabel.hasText {
|
if let subLabelText = subTextLabel.text, subTextLabel.hasText {
|
||||||
message += subLabelText + ", "
|
message += subLabelText + ", "
|
||||||
}
|
}
|
||||||
accessibilityLabel = message
|
|
||||||
|
|
||||||
|
accessibilityLabel = message
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
|
|
||||||
if isSelected {
|
if isSelected {
|
||||||
accessibilityTraits.insert(.selected)
|
accessibilityTraits.insert(.selected)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isEnabled {
|
if !isEnabled {
|
||||||
accessibilityTraits.insert(.notEnabled)
|
accessibilityTraits.insert(.notEnabled)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,17 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
open class RadioBoxCollectionViewCell: CollectionViewCell {
|
open class RadioBoxCollectionViewCell: CollectionViewCell {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Outlets
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public let radioBox = RadioBox()
|
public let radioBox = RadioBox()
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Lifecycle
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
|
|||||||
@ -6,12 +6,16 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
@objcMembers public class RadioBoxModel: MoleculeModelProtocol {
|
@objcMembers public class RadioBoxModel: MoleculeModelProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "radioBox"
|
public static var identifier: String = "radioBox"
|
||||||
public var text: String
|
public var text: String
|
||||||
public var subText: String?
|
public var subText: String?
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
public var accessibilityIdentifier: String?
|
||||||
public var selectedAccentColor: Color?
|
public var selectedAccentColor: Color?
|
||||||
public var selected: Bool = false
|
public var selected: Bool = false
|
||||||
public var enabled: Bool = true
|
public var enabled: Bool = true
|
||||||
@ -19,12 +23,17 @@ import Foundation
|
|||||||
public var fieldValue: String?
|
public var fieldValue: String?
|
||||||
public var action: ActionModelProtocol?
|
public var action: ActionModelProtocol?
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Keys
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case text
|
case text
|
||||||
case subText
|
case subText
|
||||||
case selectedAccentColor
|
case selectedAccentColor
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
case accessibilityIdentifier
|
||||||
case selected
|
case selected
|
||||||
case enabled
|
case enabled
|
||||||
case strikethrough
|
case strikethrough
|
||||||
@ -32,18 +41,26 @@ import Foundation
|
|||||||
case action
|
case action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Codec
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
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)
|
||||||
text = try typeContainer.decode(String.self, forKey: .text)
|
text = try typeContainer.decode(String.self, forKey: .text)
|
||||||
subText = try typeContainer.decodeIfPresent(String.self, forKey: .subText)
|
subText = try typeContainer.decodeIfPresent(String.self, forKey: .subText)
|
||||||
selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor)
|
selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
|
||||||
|
|
||||||
if let isSelected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) {
|
if let isSelected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) {
|
||||||
selected = isSelected
|
selected = isSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
if let isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
if let isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
||||||
enabled = isEnabled
|
enabled = isEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if let isStrikeTrough = try typeContainer.decodeIfPresent(Bool.self, forKey: .strikethrough) {
|
if let isStrikeTrough = try typeContainer.decodeIfPresent(Bool.self, forKey: .strikethrough) {
|
||||||
strikethrough = isStrikeTrough
|
strikethrough = isStrikeTrough
|
||||||
}
|
}
|
||||||
@ -59,6 +76,7 @@ import Foundation
|
|||||||
try container.encodeIfPresent(subText, forKey: .subText)
|
try container.encodeIfPresent(subText, forKey: .subText)
|
||||||
try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor)
|
try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
try container.encode(selected, forKey: .selected)
|
try container.encode(selected, forKey: .selected)
|
||||||
try container.encode(enabled, forKey: .enabled)
|
try container.encode(enabled, forKey: .enabled)
|
||||||
try container.encode(strikethrough, forKey: .strikethrough)
|
try container.encode(strikethrough, forKey: .strikethrough)
|
||||||
|
|||||||
@ -57,11 +57,13 @@ open class RadioBoxes: View {
|
|||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
|
||||||
guard let radioBoxesModel = model as? RadioBoxesModel else { return }
|
guard let model = model as? RadioBoxesModel else { return }
|
||||||
boxes = radioBoxesModel.boxes
|
boxes = model.boxes
|
||||||
FormValidator.setupValidation(for: radioBoxesModel, delegate: delegateObject?.formHolderDelegate)
|
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
||||||
|
|
||||||
|
backgroundColor = model.backgroundColor?.uiColor
|
||||||
|
accessibilityIdentifier = model.accessibilityIdentifier
|
||||||
|
|
||||||
backgroundColor = radioBoxesModel.backgroundColor?.uiColor
|
|
||||||
registerCells()
|
registerCells()
|
||||||
setHeight()
|
setHeight()
|
||||||
collectionView.reloadData()
|
collectionView.reloadData()
|
||||||
@ -168,4 +170,3 @@ extension RadioBoxes: UICollectionViewDelegate {
|
|||||||
cell.updateAccessibility()
|
cell.updateAccessibility()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,17 +6,25 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
@objcMembers public class RadioBoxesModel: MoleculeModelProtocol, FormFieldProtocol {
|
@objcMembers public class RadioBoxesModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "radioBoxes"
|
public static var identifier: String = "radioBoxes"
|
||||||
public var boxes: [RadioBoxModel]
|
public var boxes: [RadioBoxModel]
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
public var accessibilityIdentifier: String?
|
||||||
public var selectedAccentColor: Color?
|
public var selectedAccentColor: Color?
|
||||||
public var boxesColor: Color?
|
public var boxesColor: Color?
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String = FormValidator.defaultGroupName
|
public var groupName: String = FormValidator.defaultGroupName
|
||||||
public var baseValue: AnyHashable?
|
public var baseValue: AnyHashable?
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Methods
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Returns the fieldValue of the selected box, otherwise the text of the selected box.
|
/// Returns the fieldValue of the selected box, otherwise the text of the selected box.
|
||||||
public func formFieldValue() -> AnyHashable? {
|
public func formFieldValue() -> AnyHashable? {
|
||||||
let selectedBox = boxes.first { (box) -> Bool in
|
let selectedBox = boxes.first { (box) -> Bool in
|
||||||
@ -25,20 +33,30 @@ import Foundation
|
|||||||
return selectedBox?.fieldValue ?? selectedBox?.text
|
return selectedBox?.fieldValue ?? selectedBox?.text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Keys
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case selectedAccentColor
|
case selectedAccentColor
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
case accessibilityIdentifier
|
||||||
case boxesColor
|
case boxesColor
|
||||||
case boxes
|
case boxes
|
||||||
case fieldKey
|
case fieldKey
|
||||||
case groupName
|
case groupName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Codec
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
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)
|
||||||
selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor)
|
selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
|
||||||
boxesColor = try typeContainer.decodeIfPresent(Color.self, forKey: .boxesColor)
|
boxesColor = try typeContainer.decodeIfPresent(Color.self, forKey: .boxesColor)
|
||||||
boxes = try typeContainer.decode([RadioBoxModel].self, forKey: .boxes)
|
boxes = try typeContainer.decode([RadioBoxModel].self, forKey: .boxes)
|
||||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||||
@ -54,6 +72,7 @@ import Foundation
|
|||||||
try container.encode(boxes, forKey: .boxes)
|
try container.encode(boxes, forKey: .boxes)
|
||||||
try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor)
|
try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||||
try container.encode(groupName, forKey: .groupName)
|
try container.encode(groupName, forKey: .groupName)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,6 @@
|
|||||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
|
|
||||||
@objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol {
|
@objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -77,7 +75,5 @@ import Foundation
|
|||||||
// MARK: - FormValidationFormFieldProtocol
|
// MARK: - FormValidationFormFieldProtocol
|
||||||
extension RadioButtonSelectionHelper {
|
extension RadioButtonSelectionHelper {
|
||||||
|
|
||||||
public func formFieldValue() -> AnyHashable? {
|
public func formFieldValue() -> AnyHashable? { selectedRadioButtonModel?.fieldValue }
|
||||||
return selectedRadioButtonModel?.fieldValue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,6 +62,7 @@ open class RadioSwatch: Control, MFButtonProtocol {
|
|||||||
guard let model = model as? RadioSwatchModel else { return }
|
guard let model = model as? RadioSwatchModel else { return }
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
self.additionalData = additionalData
|
self.additionalData = additionalData
|
||||||
|
accessibilityIdentifier = model.accessibilityIdentifier
|
||||||
bottomText.text = model.text
|
bottomText.text = model.text
|
||||||
isSelected = model.selected
|
isSelected = model.selected
|
||||||
isEnabled = model.enabled
|
isEnabled = model.enabled
|
||||||
@ -77,6 +78,7 @@ open class RadioSwatch: Control, MFButtonProtocol {
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - State Handling
|
// MARK: - State Handling
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
||||||
//Draw the swatch
|
//Draw the swatch
|
||||||
circleLayer?.removeFromSuperlayer()
|
circleLayer?.removeFromSuperlayer()
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
open class RadioSwatchCollectionViewCell: CollectionViewCell {
|
open class RadioSwatchCollectionViewCell: CollectionViewCell {
|
||||||
public let radioSwatch = RadioSwatch()
|
public let radioSwatch = RadioSwatch()
|
||||||
|
|
||||||
|
|||||||
@ -6,11 +6,15 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
@objcMembers public class RadioSwatchModel: MoleculeModelProtocol {
|
@objcMembers public class RadioSwatchModel: MoleculeModelProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "radioSwatch"
|
public static var identifier: String = "radioSwatch"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
public var accessibilityIdentifier: String?
|
||||||
public var color: Color = Color(uiColor: .mvmBlue)
|
public var color: Color = Color(uiColor: .mvmBlue)
|
||||||
public var text: String?
|
public var text: String?
|
||||||
public var selected: Bool = false
|
public var selected: Bool = false
|
||||||
@ -19,9 +23,14 @@ import Foundation
|
|||||||
public var fieldValue: String?
|
public var fieldValue: String?
|
||||||
public var action: ActionModelProtocol?
|
public var action: ActionModelProtocol?
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Keys
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
case accessibilityIdentifier
|
||||||
case color
|
case color
|
||||||
case text
|
case text
|
||||||
case selected
|
case selected
|
||||||
@ -31,22 +40,33 @@ import Foundation
|
|||||||
case action
|
case action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Codec
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
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)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
|
||||||
|
|
||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) {
|
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) {
|
||||||
self.color = color
|
self.color = color
|
||||||
}
|
}
|
||||||
|
|
||||||
text = try typeContainer.decodeIfPresent(String.self, forKey: .text)
|
text = try typeContainer.decodeIfPresent(String.self, forKey: .text)
|
||||||
|
|
||||||
if let selected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) {
|
if let selected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) {
|
||||||
self.selected = selected
|
self.selected = selected
|
||||||
}
|
}
|
||||||
|
|
||||||
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if let strikethrough = try typeContainer.decodeIfPresent(Bool.self, forKey: .strikethrough) {
|
if let strikethrough = try typeContainer.decodeIfPresent(Bool.self, forKey: .strikethrough) {
|
||||||
self.strikethrough = strikethrough
|
self.strikethrough = strikethrough
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
|
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
|
||||||
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
|
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
|
||||||
}
|
}
|
||||||
@ -55,6 +75,7 @@ import Foundation
|
|||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
try container.encode(color, forKey: .color)
|
try container.encode(color, forKey: .color)
|
||||||
try container.encodeIfPresent(text, forKey: .text)
|
try container.encodeIfPresent(text, forKey: .text)
|
||||||
try container.encode(selected, forKey: .selected)
|
try container.encode(selected, forKey: .selected)
|
||||||
@ -64,5 +85,3 @@ import Foundation
|
|||||||
try container.encodeModelIfPresent(action, forKey: .action)
|
try container.encodeModelIfPresent(action, forKey: .action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -55,9 +55,10 @@ open class RadioSwatches: View {
|
|||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
|
||||||
guard let radioSwatchesModel = model as? RadioSwatchesModel else { return }
|
guard let model = model as? RadioSwatchesModel else { return }
|
||||||
swatches = radioSwatchesModel.swatches
|
swatches = model.swatches
|
||||||
FormValidator.setupValidation(for: radioSwatchesModel, delegate: delegateObject?.formHolderDelegate)
|
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
||||||
|
accessibilityIdentifier = model.accessibilityIdentifier
|
||||||
collectionView.reloadData()
|
collectionView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,16 +6,24 @@
|
|||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
@objcMembers public class RadioSwatchesModel: MoleculeModelProtocol, FormFieldProtocol {
|
@objcMembers public class RadioSwatchesModel: MoleculeModelProtocol, FormFieldProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "radioSwatches"
|
public static var identifier: String = "radioSwatches"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
public var accessibilityIdentifier: String?
|
||||||
public var swatches: [RadioSwatchModel]
|
public var swatches: [RadioSwatchModel]
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String = FormValidator.defaultGroupName
|
public var groupName: String = FormValidator.defaultGroupName
|
||||||
public var baseValue: AnyHashable?
|
public var baseValue: AnyHashable?
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Methods
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Returns the fieldValue of the selected swatch, otherwise the text of selected swatch.
|
/// Returns the fieldValue of the selected swatch, otherwise the text of selected swatch.
|
||||||
public func formFieldValue() -> AnyHashable? {
|
public func formFieldValue() -> AnyHashable? {
|
||||||
let selectedSwatch = swatches.first { (swatch) -> Bool in
|
let selectedSwatch = swatches.first { (swatch) -> Bool in
|
||||||
@ -24,17 +32,27 @@ import Foundation
|
|||||||
return selectedSwatch?.fieldValue ?? selectedSwatch?.text
|
return selectedSwatch?.fieldValue ?? selectedSwatch?.text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Keys
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
case accessibilityIdentifier
|
||||||
case swatches
|
case swatches
|
||||||
case fieldKey
|
case fieldKey
|
||||||
case groupName
|
case groupName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Codec
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
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)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .backgaccessibilityIdentifierroundColor)
|
||||||
swatches = try typeContainer.decode([RadioSwatchModel].self, forKey: .swatches)
|
swatches = try typeContainer.decode([RadioSwatchModel].self, forKey: .swatches)
|
||||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
||||||
@ -47,6 +65,7 @@ import Foundation
|
|||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
|
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
||||||
try container.encode(swatches, forKey: .swatches)
|
try container.encode(swatches, forKey: .swatches)
|
||||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||||
try container.encode(groupName, forKey: .groupName)
|
try container.encode(groupName, forKey: .groupName)
|
||||||
|
|||||||
@ -1104,7 +1104,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2;
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ (nonnull NSAttributedString *)styleGetRegularMicroAttributedString:(nullable NSString *)string {
|
+ (nonnull NSAttributedString *)styleGetRegularMicroAttributedString:(nullable NSString *)string {
|
||||||
return [MFStyler styleGetRegularBodySmallAttributedString:string genericScaling:YES];
|
return [MFStyler styleGetRegularMicroAttributedString:string genericScaling:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (nonnull NSAttributedString *)styleGetRegularMicroAttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling {
|
+ (nonnull NSAttributedString *)styleGetRegularMicroAttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user