diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index 9662fc48..52ade755 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -94,27 +94,27 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW //-------------------------------------------------- public func enabled_fillColor() -> UIColor? { - return (inverted ? enabledFillColor_inverted : enabledFillColor)?.uiColor + (inverted ? enabledFillColor_inverted : enabledFillColor)?.uiColor } public func enabled_textColor() -> UIColor? { - return (inverted ? enabledTextColor_inverted : enabledTextColor)?.uiColor + (inverted ? enabledTextColor_inverted : enabledTextColor)?.uiColor } public func enabled_borderColor() -> UIColor? { - return (inverted ? enabledBorderColor_inverted : enabledBorderColor)?.uiColor + (inverted ? enabledBorderColor_inverted : enabledBorderColor)?.uiColor } public func disabled_fillColor() -> UIColor? { - return (inverted ? disabledFillColor_inverted : disabledFillColor)?.uiColor + (inverted ? disabledFillColor_inverted : disabledFillColor)?.uiColor } public func disabled_textColor() -> UIColor? { - return (inverted ? disabledTextColor_inverted : disabledTextColor)?.uiColor + (inverted ? disabledTextColor_inverted : disabledTextColor)?.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. diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index b89d034d..4a7a8481 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -27,9 +27,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { } open var buttonSize: Styler.Button.Size = .standard { - didSet { - buttonModel?.size = buttonSize - } + didSet { buttonModel?.size = buttonSize } } //-------------------------------------------------- @@ -106,6 +104,8 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { self.disabledTitleColor = disabledTitleColor } + isAccessibilityElement = isEnabled + if isEnabled { if let fillColor = buttonModel?.enabledColors.fill { backgroundColor = fillColor @@ -128,7 +128,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { } private func getInnerPadding() -> CGFloat { - return getHeight() / 2.0 + getHeight() / 2.0 } private func getHeight() -> CGFloat { @@ -181,9 +181,11 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { guard let model = model as? ButtonModel else { return } setTitle(model.title, for: .normal) + if let size = model.size { buttonSize = size } + model.updateUI = { [weak self] in MVMCoreDispatchUtility.performBlock(onMainThread: { self?.enableField(model.enabled) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index edc37628..b440adaa 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -25,7 +25,7 @@ import MVMCore var delegateObject: MVMCoreUIDelegateObject? public var checkboxModel: CheckboxModel? { - return model as? CheckboxModel + model as? CheckboxModel } public static let defaultHeightWidth: CGFloat = 18.0 @@ -59,7 +59,7 @@ import MVMCore /// Retrieves ideeal radius value to curve square into a circle. public var cornerRadiusValue: CGFloat { - return bounds.size.height / 2 + bounds.size.height / 2 } /// Action Block called when the switch is selected. @@ -102,23 +102,17 @@ import MVMCore /// Color of the check mark. public var checkColor: UIColor = .mvmBlack { - didSet { - setShapeLayerStrokeColor(checkColor) - } + didSet { setShapeLayerStrokeColor(checkColor) } } /// Border width of the checkbox public var borderWidth: CGFloat = 1 { - didSet { - layer.borderWidth = borderWidth - } + didSet { layer.borderWidth = borderWidth } } /// border color of the Checkbox public var borderColor: UIColor = .mvmBlack { - didSet { - layer.borderColor = borderColor.cgColor - } + didSet { layer.borderColor = borderColor.cgColor } } /** @@ -367,9 +361,7 @@ import MVMCore // MARK: - Molecular //-------------------------------------------------- - open func needsToBeConstrained() -> Bool { - return true - } + open func needsToBeConstrained() -> Bool { true } open override func reset() { super.reset() @@ -415,6 +407,8 @@ import MVMCore self.fieldKey = fieldKey } + accessibilityIdentifier = model.accessibilityIdentifier + borderColor = (model.inverted ? model.invertedColor : model.borderColor).uiColor borderWidth = model.borderWidth diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift index bb21da1b..c2d9f14e 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/CheckboxModel.swift @@ -16,6 +16,7 @@ import Foundation public static var identifier: String = "checkbox" public var backgroundColor: Color? + public var accessibilityIdentifier: String? public var checked: Bool = false public var enabled: Bool = true public var animated: Bool = true @@ -44,6 +45,7 @@ import Foundation private enum CodingKeys: String, CodingKey { case moleculeName + case accessibilityIdentifier case checked case enabled case inverted @@ -69,9 +71,7 @@ import Foundation // MARK: - Methods //-------------------------------------------------- - public func formFieldValue() -> AnyHashable? { - return checked - } + public func formFieldValue() -> AnyHashable? { checked } //-------------------------------------------------- // MARK: - Initializer @@ -89,6 +89,8 @@ import Foundation required public init(from decoder: Decoder) throws { 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) { self.borderWidth = borderWidth } @@ -169,6 +171,7 @@ import Foundation try container.encode(borderWidth, forKey: .borderWidth) try container.encode(checked, forKey: .checked) try container.encode(inverted, forKey: .inverted) + try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) try container.encodeIfPresent(checkColor, forKey: .checkColor) try container.encodeIfPresent(invertedColor, forKey: .invertedColor) try container.encodeIfPresent(invertedBackgroundColor, forKey: .invertedBackgroundColor) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index bd720be8..a22907ce 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -15,9 +15,7 @@ import UIKit //-------------------------------------------------- public var diameter: CGFloat = 30 { - didSet { - widthConstraint?.constant = diameter - } + didSet { widthConstraint?.constant = diameter } } @objc public override var isSelected: Bool { @@ -33,7 +31,7 @@ import UIKit var additionalData: [AnyHashable: Any]? public var radioModel: RadioButtonModel? { - return model as? RadioButtonModel + model as? RadioButtonModel } lazy public var radioGroupName: String? = { @@ -95,33 +93,34 @@ import UIKit if !isEnabled { return } + let wasPreviouslySelected = isSelected if let radioButtonModel = radioButtonSelectionHelper { radioButtonModel.selected(self) } else { isSelected = !isSelected } + if let radioModel = radioModel, let actionModel = radioModel.action, isSelected, !wasPreviouslySelected { Button.performButtonAction(with: actionModel, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: radioModel) } + _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) setNeedsDisplay() } - public func isValidField() -> Bool { - return isSelected - } + public func isValidField() -> Bool { isSelected } public func formFieldName() -> String? { - return radioModel?.fieldKey + radioModel?.fieldKey } public func formFieldGroupName() -> String? { - return radioModel?.fieldKey + radioModel?.fieldKey } public func formFieldValue() -> AnyHashable? { - return radioModel?.fieldValue + radioModel?.fieldValue } //-------------------------------------------------- @@ -164,6 +163,8 @@ import UIKit guard let model = model as? RadioButtonModel else { return } + accessibilityIdentifier = model.accessibilityIdentifier + isSelected = model.state isEnabled = model.enabled RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButtonModel.swift index 7d50cf56..239a8d41 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButtonModel.swift @@ -6,7 +6,6 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -import Foundation import MVMCore @@ -17,6 +16,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { public static var identifier: String = "radioButton" public var backgroundColor: Color? + public var accessibilityIdentifier: String? public var state: Bool = false public var enabled: Bool = true @@ -35,6 +35,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor + case accessibilityIdentifier case state case enabled case fieldValue @@ -56,9 +57,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { // MARK: - Validation //-------------------------------------------------- - public func formFieldValue() -> AnyHashable? { - return fieldValue - } + public func formFieldValue() -> AnyHashable? { fieldValue } //-------------------------------------------------- // MARK: - Codec @@ -76,6 +75,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { } backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier) baseValue = state fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) @@ -89,6 +89,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(state, forKey: .state) try container.encode(enabled, forKey: .enabled) diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 79a72d02..1802e25d 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -136,9 +136,11 @@ public typealias ButtonAction = (Button) -> () //-------------------------------------------------- open override func accessibilityActivate() -> Bool { + guard isEnabled else { return false } buttonAction?(self) return buttonAction != nil } + } // MARK: - MVMCoreViewProtocol diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index e2e725c1..a0785c41 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -75,11 +75,12 @@ import MVMCore /// Convenience function. Gets the form validator from the holder and asks it to validate. public static func validate(delegate: FormHolderProtocol?) -> Bool? { - return delegate?.formValidator?.validate() + delegate?.formValidator?.validate() } /// Validates all rule groups. Returns if valid public func validate() -> Bool { + var valid = true 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. @objc public extension FormValidator { + @objc func addFormParams(requestParameters: MVMCoreRequestParameters) { let groupName = getGroupName(forPageType: requestParameters.pageType) ?? FormValidator.defaultGroupName let formParams = self.getFormParams(forGroup: groupName) @@ -119,6 +121,7 @@ import MVMCore } @objc func getFormParams( forGroup groupName: String) -> [String: Any] { + var extraParam: [String: Any] = [:] for (fieldKey, field) in fields { if let formFieldValue = field.formFieldValue(), @@ -126,6 +129,7 @@ import MVMCore extraParam[fieldKey] = formFieldValue } } + return extraParam } } @@ -145,4 +149,3 @@ public extension FormValidator { return nil } } -