exposing accessibility. test improvements.

This commit is contained in:
Kevin G Christiano 2020-12-10 14:28:55 -05:00
parent 88110b6508
commit 0eaa7c1613
8 changed files with 50 additions and 44 deletions

View File

@ -94,27 +94,27 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
//-------------------------------------------------- //--------------------------------------------------
public func enabled_fillColor() -> UIColor? { public func enabled_fillColor() -> UIColor? {
return (inverted ? enabledFillColor_inverted : enabledFillColor)?.uiColor (inverted ? enabledFillColor_inverted : enabledFillColor)?.uiColor
} }
public func enabled_textColor() -> UIColor? { public func enabled_textColor() -> UIColor? {
return (inverted ? enabledTextColor_inverted : enabledTextColor)?.uiColor (inverted ? enabledTextColor_inverted : enabledTextColor)?.uiColor
} }
public func enabled_borderColor() -> UIColor? { public func enabled_borderColor() -> UIColor? {
return (inverted ? enabledBorderColor_inverted : enabledBorderColor)?.uiColor (inverted ? enabledBorderColor_inverted : enabledBorderColor)?.uiColor
} }
public func disabled_fillColor() -> UIColor? { public func disabled_fillColor() -> UIColor? {
return (inverted ? disabledFillColor_inverted : disabledFillColor)?.uiColor (inverted ? disabledFillColor_inverted : disabledFillColor)?.uiColor
} }
public func disabled_textColor() -> UIColor? { public func disabled_textColor() -> UIColor? {
return (inverted ? disabledTextColor_inverted : disabledTextColor)?.uiColor (inverted ? disabledTextColor_inverted : disabledTextColor)?.uiColor
} }
public func disabled_borderColor() -> UIColor? { public func disabled_borderColor() -> UIColor? {
return (inverted ? disabledBorderColor_inverted : disabledBorderColor)?.uiColor (inverted ? disabledBorderColor_inverted : disabledBorderColor)?.uiColor
} }
/// Defines the default appearance for the primary style. /// Defines the default appearance for the primary style.

View File

@ -27,9 +27,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
} }
open var buttonSize: Styler.Button.Size = .standard { open var buttonSize: Styler.Button.Size = .standard {
didSet { didSet { buttonModel?.size = buttonSize }
buttonModel?.size = buttonSize
}
} }
//-------------------------------------------------- //--------------------------------------------------
@ -106,6 +104,8 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
self.disabledTitleColor = disabledTitleColor self.disabledTitleColor = disabledTitleColor
} }
isAccessibilityElement = isEnabled
if isEnabled { if isEnabled {
if let fillColor = buttonModel?.enabledColors.fill { if let fillColor = buttonModel?.enabledColors.fill {
backgroundColor = fillColor backgroundColor = fillColor
@ -128,7 +128,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
} }
private func getInnerPadding() -> CGFloat { private func getInnerPadding() -> CGFloat {
return getHeight() / 2.0 getHeight() / 2.0
} }
private func getHeight() -> CGFloat { private func getHeight() -> CGFloat {
@ -181,9 +181,11 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol {
guard let model = model as? ButtonModel else { return } guard let model = model as? ButtonModel else { return }
setTitle(model.title, for: .normal) setTitle(model.title, for: .normal)
if let size = model.size { if let size = model.size {
buttonSize = size buttonSize = size
} }
model.updateUI = { [weak self] in model.updateUI = { [weak self] in
MVMCoreDispatchUtility.performBlock(onMainThread: { MVMCoreDispatchUtility.performBlock(onMainThread: {
self?.enableField(model.enabled) self?.enableField(model.enabled)

View File

@ -25,7 +25,7 @@ import MVMCore
var delegateObject: MVMCoreUIDelegateObject? var delegateObject: MVMCoreUIDelegateObject?
public var checkboxModel: CheckboxModel? { public var checkboxModel: CheckboxModel? {
return model as? CheckboxModel model as? CheckboxModel
} }
public static let defaultHeightWidth: CGFloat = 18.0 public static let defaultHeightWidth: CGFloat = 18.0
@ -59,7 +59,7 @@ import MVMCore
/// Retrieves ideeal radius value to curve square into a circle. /// Retrieves ideeal radius value to curve square into a circle.
public var cornerRadiusValue: CGFloat { public var cornerRadiusValue: CGFloat {
return bounds.size.height / 2 bounds.size.height / 2
} }
/// Action Block called when the switch is selected. /// Action Block called when the switch is selected.
@ -102,23 +102,17 @@ import MVMCore
/// Color of the check mark. /// Color of the check mark.
public var checkColor: UIColor = .mvmBlack { public var checkColor: UIColor = .mvmBlack {
didSet { didSet { setShapeLayerStrokeColor(checkColor) }
setShapeLayerStrokeColor(checkColor)
}
} }
/// Border width of the checkbox /// Border width of the checkbox
public var borderWidth: CGFloat = 1 { public var borderWidth: CGFloat = 1 {
didSet { didSet { layer.borderWidth = borderWidth }
layer.borderWidth = borderWidth
}
} }
/// border color of the Checkbox /// border color of the Checkbox
public var borderColor: UIColor = .mvmBlack { public var borderColor: UIColor = .mvmBlack {
didSet { didSet { layer.borderColor = borderColor.cgColor }
layer.borderColor = borderColor.cgColor
}
} }
/** /**
@ -367,9 +361,7 @@ import MVMCore
// MARK: - Molecular // MARK: - Molecular
//-------------------------------------------------- //--------------------------------------------------
open func needsToBeConstrained() -> Bool { open func needsToBeConstrained() -> Bool { true }
return true
}
open override func reset() { open override func reset() {
super.reset() super.reset()
@ -415,6 +407,8 @@ import MVMCore
self.fieldKey = fieldKey self.fieldKey = fieldKey
} }
accessibilityIdentifier = model.accessibilityIdentifier
borderColor = (model.inverted ? model.invertedColor : model.borderColor).uiColor borderColor = (model.inverted ? model.invertedColor : model.borderColor).uiColor
borderWidth = model.borderWidth borderWidth = model.borderWidth

View File

@ -16,6 +16,7 @@ import Foundation
public static var identifier: String = "checkbox" public static var identifier: String = "checkbox"
public var backgroundColor: Color? public var backgroundColor: Color?
public var accessibilityIdentifier: String?
public var checked: Bool = false public var checked: Bool = false
public var enabled: Bool = true public var enabled: Bool = true
public var animated: Bool = true public var animated: Bool = true
@ -44,6 +45,7 @@ import Foundation
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case accessibilityIdentifier
case checked case checked
case enabled case enabled
case inverted case inverted
@ -69,9 +71,7 @@ import Foundation
// MARK: - Methods // MARK: - Methods
//-------------------------------------------------- //--------------------------------------------------
public func formFieldValue() -> AnyHashable? { public func formFieldValue() -> AnyHashable? { checked }
return checked
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
@ -89,6 +89,8 @@ 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)
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
if let borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) { if let borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) {
self.borderWidth = borderWidth self.borderWidth = borderWidth
} }
@ -169,6 +171,7 @@ import Foundation
try container.encode(borderWidth, forKey: .borderWidth) try container.encode(borderWidth, forKey: .borderWidth)
try container.encode(checked, forKey: .checked) try container.encode(checked, forKey: .checked)
try container.encode(inverted, forKey: .inverted) try container.encode(inverted, forKey: .inverted)
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
try container.encodeIfPresent(checkColor, forKey: .checkColor) try container.encodeIfPresent(checkColor, forKey: .checkColor)
try container.encodeIfPresent(invertedColor, forKey: .invertedColor) try container.encodeIfPresent(invertedColor, forKey: .invertedColor)
try container.encodeIfPresent(invertedBackgroundColor, forKey: .invertedBackgroundColor) try container.encodeIfPresent(invertedBackgroundColor, forKey: .invertedBackgroundColor)

View File

@ -15,9 +15,7 @@ import UIKit
//-------------------------------------------------- //--------------------------------------------------
public var diameter: CGFloat = 30 { public var diameter: CGFloat = 30 {
didSet { didSet { widthConstraint?.constant = diameter }
widthConstraint?.constant = diameter
}
} }
@objc public override var isSelected: Bool { @objc public override var isSelected: Bool {
@ -33,7 +31,7 @@ import UIKit
var additionalData: [AnyHashable: Any]? var additionalData: [AnyHashable: Any]?
public var radioModel: RadioButtonModel? { public var radioModel: RadioButtonModel? {
return model as? RadioButtonModel model as? RadioButtonModel
} }
lazy public var radioGroupName: String? = { lazy public var radioGroupName: String? = {
@ -95,33 +93,34 @@ import UIKit
if !isEnabled { if !isEnabled {
return return
} }
let wasPreviouslySelected = isSelected let wasPreviouslySelected = isSelected
if let radioButtonModel = radioButtonSelectionHelper { if let radioButtonModel = radioButtonSelectionHelper {
radioButtonModel.selected(self) radioButtonModel.selected(self)
} else { } else {
isSelected = !isSelected isSelected = !isSelected
} }
if let radioModel = radioModel, let actionModel = radioModel.action, isSelected, !wasPreviouslySelected { if let radioModel = radioModel, let actionModel = radioModel.action, isSelected, !wasPreviouslySelected {
Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioModel) Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioModel)
} }
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
setNeedsDisplay() setNeedsDisplay()
} }
public func isValidField() -> Bool { public func isValidField() -> Bool { isSelected }
return isSelected
}
public func formFieldName() -> String? { public func formFieldName() -> String? {
return radioModel?.fieldKey radioModel?.fieldKey
} }
public func formFieldGroupName() -> String? { public func formFieldGroupName() -> String? {
return radioModel?.fieldKey radioModel?.fieldKey
} }
public func formFieldValue() -> AnyHashable? { public func formFieldValue() -> AnyHashable? {
return radioModel?.fieldValue radioModel?.fieldValue
} }
//-------------------------------------------------- //--------------------------------------------------
@ -164,6 +163,8 @@ import UIKit
guard let model = model as? RadioButtonModel else { return } guard let model = model as? RadioButtonModel else { return }
accessibilityIdentifier = model.accessibilityIdentifier
isSelected = model.state isSelected = model.state
isEnabled = model.enabled isEnabled = model.enabled
RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject) RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject)

View File

@ -6,7 +6,6 @@
// Copyright © 2020 Verizon Wireless. All rights reserved. // Copyright © 2020 Verizon Wireless. All rights reserved.
// //
import Foundation
import MVMCore import MVMCore
@ -17,6 +16,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
public static var identifier: String = "radioButton" public static var identifier: String = "radioButton"
public var backgroundColor: Color? public var backgroundColor: Color?
public var accessibilityIdentifier: String?
public var state: Bool = false public var state: Bool = false
public var enabled: Bool = true public var enabled: Bool = true
@ -35,6 +35,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case accessibilityIdentifier
case state case state
case enabled case enabled
case fieldValue case fieldValue
@ -56,9 +57,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
// MARK: - Validation // MARK: - Validation
//-------------------------------------------------- //--------------------------------------------------
public func formFieldValue() -> AnyHashable? { public func formFieldValue() -> AnyHashable? { fieldValue }
return fieldValue
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Codec // MARK: - Codec
@ -76,6 +75,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
} }
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
baseValue = state baseValue = state
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
@ -89,6 +89,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
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(state, forKey: .state) try container.encode(state, forKey: .state)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)

View File

@ -136,9 +136,11 @@ public typealias ButtonAction = (Button) -> ()
//-------------------------------------------------- //--------------------------------------------------
open override func accessibilityActivate() -> Bool { open override func accessibilityActivate() -> Bool {
guard isEnabled else { return false }
buttonAction?(self) buttonAction?(self)
return buttonAction != nil return buttonAction != nil
} }
} }
// MARK: - MVMCoreViewProtocol // MARK: - MVMCoreViewProtocol

View File

@ -75,11 +75,12 @@ import MVMCore
/// Convenience function. Gets the form validator from the holder and asks it to validate. /// Convenience function. Gets the form validator from the holder and asks it to validate.
public static func validate(delegate: FormHolderProtocol?) -> Bool? { public static func validate(delegate: FormHolderProtocol?) -> Bool? {
return delegate?.formValidator?.validate() delegate?.formValidator?.validate()
} }
/// Validates all rule groups. Returns if valid /// Validates all rule groups. Returns if valid
public func validate() -> Bool { public func validate() -> Bool {
var valid = true var valid = true
guard let formRules = formRules else { return valid } guard let formRules = formRules else { return valid }
@ -109,9 +110,10 @@ import MVMCore
} }
} }
// mark Form params // MARK: Form params
// TODO: Temporary hacks, rewrite architecture to support this. // TODO: Temporary hacks, rewrite architecture to support this.
@objc public extension FormValidator { @objc public extension FormValidator {
@objc func addFormParams(requestParameters: MVMCoreRequestParameters) { @objc func addFormParams(requestParameters: MVMCoreRequestParameters) {
let groupName = getGroupName(forPageType: requestParameters.pageType) ?? FormValidator.defaultGroupName let groupName = getGroupName(forPageType: requestParameters.pageType) ?? FormValidator.defaultGroupName
let formParams = self.getFormParams(forGroup: groupName) let formParams = self.getFormParams(forGroup: groupName)
@ -119,6 +121,7 @@ import MVMCore
} }
@objc func getFormParams( forGroup groupName: String) -> [String: Any] { @objc func getFormParams( forGroup groupName: String) -> [String: Any] {
var extraParam: [String: Any] = [:] var extraParam: [String: Any] = [:]
for (fieldKey, field) in fields { for (fieldKey, field) in fields {
if let formFieldValue = field.formFieldValue(), if let formFieldValue = field.formFieldValue(),
@ -126,6 +129,7 @@ import MVMCore
extraParam[fieldKey] = formFieldValue extraParam[fieldKey] = formFieldValue
} }
} }
return extraParam return extraParam
} }
} }
@ -145,4 +149,3 @@ public extension FormValidator {
return nil return nil
} }
} }