diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index f288c4cd..cc6895db 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -158,6 +158,7 @@ import MVMCore super.init(frame: frame) accessibilityTraits = .button + isAccessibilityElement = true accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "checkbox_action_hint") updateAccessibilityLabel() } @@ -198,8 +199,6 @@ import MVMCore open override func setupView() { super.setupView() - guard constraints.isEmpty else { return } - isUserInteractionEnabled = true translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear @@ -394,8 +393,6 @@ import MVMCore widthConstraint?.constant = dimension heightConstraint?.constant = dimension } - - //layoutIfNeeded() } public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index 265e56b3..9d6ce521 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -12,6 +12,7 @@ import UIKit //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- + open var json: [AnyHashable: Any]? open var model: MoleculeModelProtocol? @@ -78,7 +79,7 @@ extension Control: AppleGuidelinesProtocol { // MARK: - MVMCoreViewProtocol extension Control: MVMCoreViewProtocol { - open func updateView(_ size: CGFloat) {} + open func updateView(_ size: CGFloat) { } /// Will be called only once. open func setupView() { @@ -89,6 +90,7 @@ extension Control: MVMCoreViewProtocol { // MARK: - MVMCoreUIMoleculeViewProtocol extension Control: MVMCoreUIMoleculeViewProtocol { + open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.json = json diff --git a/MVMCoreUI/BaseClasses/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift index ebf25a3c..510779b2 100644 --- a/MVMCoreUI/BaseClasses/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -246,7 +246,7 @@ import UIKit // MARK: - MoleculeListCellProtocol /// For when the separator between cells shows using json and frequency. Default is type: standard, frequency: allExceptTop. - public func setLines(with model: LineModel?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?, indexPath: IndexPath) { + public func setLines(with model: LineModel?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, indexPath: IndexPath) { addSeparatorsIfNeeded() if let model = model { topSeparatorView?.set(with: model, delegateObject, additionalData) @@ -258,7 +258,7 @@ import UIKit setSeparatorFrequency(model?.frequency ?? .allExceptTop, indexPath: indexPath) } - public func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + public func didSelectCell(at index: IndexPath, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { //TODO: Use object when handleAction is rewrote to handle action model if let actionMap = self.listItemModel?.action?.toJSON() { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) diff --git a/MVMCoreUI/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift b/MVMCoreUI/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift index 8d7fb539..448d76e1 100644 --- a/MVMCoreUI/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift +++ b/MVMCoreUI/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift @@ -9,11 +9,18 @@ import Foundation @objcMembers open class ListLeftVariableCheckboxAllTextAndLinks: TableViewCell { - public let checkbox = Checkbox(frame: .zero) + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public let checkbox = Checkbox() public let eyebrowHeadlineBodyLink = EyebrowHeadlineBodyLink(frame: .zero) public var stack: Stack + //-------------------------------------------------- // MARK: - Initializers + //-------------------------------------------------- + public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { stack = Stack.createStack(with: [(view: checkbox, model: StackItemModel(horizontalAlignment: .fill)), (view: eyebrowHeadlineBodyLink, model: StackItemModel(horizontalAlignment: .leading))], @@ -25,17 +32,25 @@ import Foundation fatalError("init(coder:) has not been implemented") } - // MARK: - View Lifecycle + //-------------------------------------------------- + // MARK: - Life Cycle + //-------------------------------------------------- + override open func setupView() { super.setupView() addMolecule(stack) stack.restack() } - // MARK:- MVMCoreUIMoleculeViewProtocol - open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + //-------------------------------------------------- + // MARK: - MVMCoreUIMoleculeViewProtocol + //-------------------------------------------------- + + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) - guard let model = model as? ListLeftVariableCheckboxAllTextAndLinksModel else { return} + + guard let model = model as? ListLeftVariableCheckboxAllTextAndLinksModel else { return } + checkbox.set(with: model.checkbox, delegateObject, additionalData) eyebrowHeadlineBodyLink.set(with: model.eyebrowHeadlineBodyLink, delegateObject, additionalData) } diff --git a/MVMCoreUI/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift b/MVMCoreUI/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift index 12ae94fe..ab5a24c0 100644 --- a/MVMCoreUI/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift +++ b/MVMCoreUI/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift @@ -9,10 +9,10 @@ import UIKit @objcMembers open class ListLeftVariableRadioButtonAndPaymentMethod: TableViewCell { - //----------------------------------------------------- // MARK: - Outlets //----------------------------------------------------- + let radioButton = RadioButton(frame: .zero) let leftImage = MFLoadImageView(pinnedEdges: .all) let eyebrowHeadlineBodyLink = EyebrowHeadlineBodyLink() @@ -21,6 +21,7 @@ import UIKit //----------------------------------------------------- // MARK: - Initializers //----------------------------------------------------- + public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { stack = Stack.createStack(with: [(view: radioButton, model: StackItemModel(horizontalAlignment: .fill)), (view: leftImage, model: StackItemModel(horizontalAlignment: .fill)), @@ -36,6 +37,7 @@ import UIKit //----------------------------------------------------- // MARK: - View Lifecycle //----------------------------------------------------- + override open func setupView() { super.setupView() addMolecule(stack) @@ -53,6 +55,7 @@ import UIKit //---------------------------------------------------- // MARK: - Molecule //---------------------------------------------------- + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = model as? ListLeftVariableRadioButtonAndPaymentMethodModel else { return} diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index 49b08b44..410112ed 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -19,7 +19,7 @@ import UIKit public let body = Label.commonLabelB2(true) public let link = Link() - var casteModel: EyebrowHeadlineBodyLinkModel? { + var castModel: EyebrowHeadlineBodyLinkModel? { get { return model as? EyebrowHeadlineBodyLinkModel } } @@ -52,6 +52,19 @@ import UIKit body.styleB2(true) } + public func eyebrow(isHidden: Bool) { + + stack.stackModel?.molecules[0].gone = isHidden + + if isHidden { + accessibilityElements = [headline, body, link] + } else { + accessibilityElements = [eyebrow, headline, body, link] + } + + stack.restack() + } + //-------------------------------------------------- // MARK: - ModelMoleculeViewProtocol //-------------------------------------------------- @@ -59,10 +72,10 @@ import UIKit open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) - eyebrow.setOptional(with: casteModel?.eyebrow, delegateObject, additionalData) - headline.setOptional(with: casteModel?.headline, delegateObject, additionalData) - body.setOptional(with: casteModel?.body, delegateObject, additionalData) - link.setOptional(with: casteModel?.link, delegateObject, additionalData) + eyebrow.setOptional(with: castModel?.eyebrow, delegateObject, additionalData) + headline.setOptional(with: castModel?.headline, delegateObject, additionalData) + body.setOptional(with: castModel?.body, delegateObject, additionalData) + link.setOptional(with: castModel?.link, delegateObject, additionalData) // Hide labels if neeeded. stack.stackModel?.molecules[0].gone = !eyebrow.hasText diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift index a120807d..9cdd9e67 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -9,9 +9,12 @@ import UIKit open class HeadlineBody: View { + let headlineLabel = Label.commonLabelH2(true) let messageLabel = Label.commonLabelB2(true) + var spaceBetweenLabelsConstant = PaddingTwo + var spaceBetweenLabels: NSLayoutConstraint? var leftConstraintTitle: NSLayoutConstraint? var rightConstraintTitle: NSLayoutConstraint? @@ -71,8 +74,6 @@ open class HeadlineBody: View { open override func setupView() { super.setupView() - - guard subviews.isEmpty else { return } backgroundColor = .clear clipsToBounds = true @@ -81,6 +82,10 @@ open class HeadlineBody: View { addSubview(view) NSLayoutConstraint.constraintPinSubview(toSuperview: view) + view.isAccessibilityElement = false + view.shouldGroupAccessibilityChildren = true + view.accessibilityElements = [headlineLabel, messageLabel] + view.addSubview(headlineLabel) view.addSubview(messageLabel) diff --git a/MVMCoreUI/Organisms/Stack.swift b/MVMCoreUI/Organisms/Stack.swift index 8e6df863..2f3b0f78 100644 --- a/MVMCoreUI/Organisms/Stack.swift +++ b/MVMCoreUI/Organisms/Stack.swift @@ -46,6 +46,9 @@ open class Stack: Container where T: (StackModelProtocol & MoleculeModelProto for (index, view) in stackItems.enumerated() { addView(view, stackModel.molecules[index], totalSpacing: totalSpace, lastItem: lastItemIndex == index) } + + isAccessibilityElement = false + accessibilityElements = stackItems } /// Removes all stack items views from the view.