diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 21f82bfd..3865ef36 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -118,6 +118,8 @@ 27F9736A246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27F97369246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift */; }; 31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; }; 31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; }; + 324FB6AA249366F3002552C7 /* ListLeftVariableNumberedListBodyTextModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324FB6A9249366F3002552C7 /* ListLeftVariableNumberedListBodyTextModel.swift */; }; + 324FB6AC24936717002552C7 /* ListLeftVariableNumberedListBodyText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 324FB6AB24936717002552C7 /* ListLeftVariableNumberedListBodyText.swift */; }; 32F8804624765C6E00C2ACB3 /* ListLeftVariableNumberedListAllTextAndLinksModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F8804524765C6E00C2ACB3 /* ListLeftVariableNumberedListAllTextAndLinksModel.swift */; }; 32F8804824765C8400C2ACB3 /* ListLeftVariableNumberedListAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F8804724765C8400C2ACB3 /* ListLeftVariableNumberedListAllTextAndLinks.swift */; }; 522679C123FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522679BF23FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift */; }; @@ -323,6 +325,7 @@ D27CD40E2322EEAF00C1DC07 /* TabsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */; }; D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27CD40F2339057800C1DC07 /* EyebrowHeadlineBodyLink.swift */; }; D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */; }; + D2874024249BA6F300BE950A /* MVMCoreUISplitViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2874023249BA6F300BE950A /* MVMCoreUISplitViewController+Extension.swift */; }; D28764AA2458980300CB882D /* ThreeLayerFillMiddleTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28764A92458980300CB882D /* ThreeLayerFillMiddleTemplate.swift */; }; D28764AC245898A400CB882D /* ThreeLayerFillMiddleTemplateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28764AB245898A400CB882D /* ThreeLayerFillMiddleTemplateModel.swift */; }; D28764F9245A327200CB882D /* TwoLinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28764F8245A327200CB882D /* TwoLinkView.swift */; }; @@ -565,6 +568,8 @@ 27F97369246750BE00CAB5C5 /* ScreenBrightnessModifierBehavior.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenBrightnessModifierBehavior.swift; sourceTree = ""; }; 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = ""; }; 31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = ""; }; + 324FB6A9249366F3002552C7 /* ListLeftVariableNumberedListBodyTextModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableNumberedListBodyTextModel.swift; sourceTree = ""; }; + 324FB6AB24936717002552C7 /* ListLeftVariableNumberedListBodyText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableNumberedListBodyText.swift; sourceTree = ""; }; 32F8804524765C6E00C2ACB3 /* ListLeftVariableNumberedListAllTextAndLinksModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableNumberedListAllTextAndLinksModel.swift; sourceTree = ""; }; 32F8804724765C8400C2ACB3 /* ListLeftVariableNumberedListAllTextAndLinks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableNumberedListAllTextAndLinks.swift; sourceTree = ""; }; 522679BF23FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListLeftVariableCheckboxAllTextAndLinks.swift; sourceTree = ""; }; @@ -769,6 +774,7 @@ D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsTableViewCell.swift; sourceTree = ""; }; D27CD40F2339057800C1DC07 /* EyebrowHeadlineBodyLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EyebrowHeadlineBodyLink.swift; sourceTree = ""; }; D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFTransparentGIFView.swift; sourceTree = ""; }; + D2874023249BA6F300BE950A /* MVMCoreUISplitViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUISplitViewController+Extension.swift"; sourceTree = ""; }; D28764A92458980300CB882D /* ThreeLayerFillMiddleTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerFillMiddleTemplate.swift; sourceTree = ""; }; D28764AB245898A400CB882D /* ThreeLayerFillMiddleTemplateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerFillMiddleTemplateModel.swift; sourceTree = ""; }; D28764F8245A327200CB882D /* TwoLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoLinkView.swift; sourceTree = ""; }; @@ -1358,6 +1364,8 @@ AA997251247530B100FC7472 /* ListLeftVariableIconAllTextLinks.swift */, 32F8804524765C6E00C2ACB3 /* ListLeftVariableNumberedListAllTextAndLinksModel.swift */, 32F8804724765C8400C2ACB3 /* ListLeftVariableNumberedListAllTextAndLinks.swift */, + 324FB6A9249366F3002552C7 /* ListLeftVariableNumberedListBodyTextModel.swift */, + 324FB6AB24936717002552C7 /* ListLeftVariableNumberedListBodyText.swift */, ); path = LeftVariable; sourceTree = ""; @@ -1813,6 +1821,7 @@ D29DF15321E69760003B2FB9 /* MVMCoreUIPanelButtonProtocol.h */, D29DF11A21E684A9003B2FB9 /* MVMCoreUISplitViewController.h */, D29DF11B21E684A9003B2FB9 /* MVMCoreUISplitViewController.m */, + D2874023249BA6F300BE950A /* MVMCoreUISplitViewController+Extension.swift */, ); path = SplitViewController; sourceTree = ""; @@ -2059,6 +2068,7 @@ files = ( 0A775F2624893916009EFB58 /* ThreeHeadlineBodyLink.swift in Sources */, AAC6F167243332E400F295C1 /* RadioSwatchesModel.swift in Sources */, + 324FB6AA249366F3002552C7 /* ListLeftVariableNumberedListBodyTextModel.swift in Sources */, 5248BFED23F12E350059236A /* ListThreeColumnPlanDataDividerModel.swift in Sources */, AA0A257824766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift in Sources */, 0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */, @@ -2260,6 +2270,7 @@ 942C378E2412F5B60066E45E /* ModalMoleculeStackTemplate.swift in Sources */, 8D8067D32444473A00203BE8 /* ListRightVariablePriceChangeAllTextAndLinks.swift in Sources */, 8D4687E4242E2DF300802879 /* ListFourColumnDataUsageListItem.swift in Sources */, + D2874024249BA6F300BE950A /* MVMCoreUISplitViewController+Extension.swift in Sources */, 01F2A03223A4498200D954D8 /* CaretLinkModel.swift in Sources */, 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */, 011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */, @@ -2315,6 +2326,7 @@ BB6C6AC0242232DF005F7224 /* ListOneColumnTextWithWhitespaceDividerTallModel.swift in Sources */, 8DEFA95E243DAC2F000D27E5 /* ListThreeColumnDataUsageDivider.swift in Sources */, D2A638FD22CA98280052ED1F /* HeadlineBody.swift in Sources */, + 324FB6AC24936717002552C7 /* ListLeftVariableNumberedListBodyText.swift in Sources */, AAA74A172410C04600080241 /* HeadersH2NoButtonsBodyText.swift in Sources */, 522679C223FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinksModel.swift in Sources */, AA7F32AB246C0F7900C965BA /* ListLeftVariableRadioButtonAllTextAndLinksModel.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift index cffbb916..f23fd337 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/Checkbox.swift @@ -157,9 +157,9 @@ import MVMCore override public init(frame: CGRect) { super.init(frame: frame) - accessibilityTraits = .button isAccessibilityElement = true accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "checkbox_action_hint") + accessibilityTraits = .button updateAccessibilityLabel() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index 43750513..371d3f7a 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -147,8 +147,8 @@ import UIKit addTarget(self, action: #selector(tapAction), for: .touchUpInside) isAccessibilityElement = true - accessibilityTraits = .button accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint") + accessibilityTraits = .button updateAccessibilityLabel() } diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index 9dc4a0bd..69048e74 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -115,12 +115,12 @@ open class BarsIndicatorView: CarouselIndicator { for i in 0.. (Bool) super.setupView() isAccessibilityElement = true - accessibilityTraits = .button accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "AccToggleHint") accessibilityLabel = MVMCoreUIUtility.hardcodedString(withKey: "Toggle_buttonlabel") - + accessibilityTraits = .button + heightConstraint = heightAnchor.constraint(equalToConstant: Self.containerSize.height) heightConstraint?.isActive = true diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index aaecdf7b..487291cd 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -173,6 +173,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: ListLeftVariableCheckboxBodyText.self, viewModelClass: ListLeftVariableCheckboxBodyTextModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListLeftVariableIconAllTextLinks.self, viewModelClass: ListLeftVariableIconAllTextLinksModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListLeftVariableNumberedListAllTextAndLinks.self, viewModelClass: ListLeftVariableNumberedListAllTextAndLinksModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: ListLeftVariableNumberedListBodyText.self, viewModelClass: ListLeftVariableNumberedListBodyTextModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListRVWheel.self, viewModelClass: ListRVWheelModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListRightVariablePayments.self, viewModelClass: ListRightVariablePaymentsModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListRightVariableTotalData.self, viewModelClass: ListRightVariableTotalDataModel.self) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexButtonMedium.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexButtonMedium.swift index 983cfc59..986ee73b 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexButtonMedium.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexButtonMedium.swift @@ -58,10 +58,8 @@ import Foundation addMolecule(stack) stack.restack() verticalStack.restack() - isAccessibilityElement = true - accessibilityTraits = button.accessibilityTraits accessibilityHint = button.accessibilityHint - updateAccessibilityLabel() + accessibilityTraits = button.accessibilityTraits } //-------------------------------------------------- @@ -100,10 +98,8 @@ import Foundation // MARK: - Accessibility //-------------------------------------------------- - func updateAccessibilityLabel() { - + func getAccessibilityMessage() -> String? { var message = "" - if let eyebrowText = eyebrow.text, !eyebrowText.isEmpty { message += eyebrowText + ", " } @@ -120,11 +116,28 @@ import Foundation message += body2Text + ", " } - if let rightImageViewText = rightImageView.accessibilityLabel, !rightImageViewText.isEmpty { + if let rightImageViewText = rightImageView.imageView.accessibilityLabel, !rightImageViewText.isEmpty { message += rightImageViewText } - - accessibilityLabel = message + return message.count > 0 ? message : nil + } + + func updateAccessibilityLabel() { + if let accessoryView = accessoryView { + // Both caret and button. Read all content on caret. + isAccessibilityElement = false + accessoryView.accessibilityLabel = getAccessibilityMessage() + accessibilityElements = [accessoryView, button] + } else { + // Make whole cell focusable if no action. + isAccessibilityElement = true + if let message = getAccessibilityMessage(), + let buttonTitle = button.titleLabel?.text { + accessibilityLabel = message + ", " + buttonTitle + } else { + accessibilityLabel = getAccessibilityMessage() + } + } } open override func accessibilityActivate() -> Bool { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexButtonSmall.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexButtonSmall.swift index f0ee4619..cd43215b 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexButtonSmall.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexButtonSmall.swift @@ -58,10 +58,8 @@ import Foundation addMolecule(stack) stack.restack() verticalStack.restack() - isAccessibilityElement = true - accessibilityTraits = button.accessibilityTraits accessibilityHint = button.accessibilityHint - updateAccessibilityLabel() + accessibilityTraits = button.accessibilityTraits } //-------------------------------------------------- @@ -100,10 +98,8 @@ import Foundation // MARK: - Accessibility //-------------------------------------------------- - func updateAccessibilityLabel() { - + func getAccessibilityMessage() -> String? { var message = "" - if let eyebrowText = eyebrow.text, !eyebrowText.isEmpty { message += eyebrowText + ", " } @@ -120,11 +116,28 @@ import Foundation message += body2Text + ", " } - if let rightImageViewText = rightImageView.accessibilityLabel, !rightImageViewText.isEmpty { + if let rightImageViewText = rightImageView.imageView.accessibilityLabel, !rightImageViewText.isEmpty { message += rightImageViewText } - - accessibilityLabel = message + return message.count > 0 ? message : nil + } + + func updateAccessibilityLabel() { + if let accessoryView = accessoryView { + // Both caret and button. Read all content on caret. + isAccessibilityElement = false + accessoryView.accessibilityLabel = getAccessibilityMessage() + accessibilityElements = [accessoryView, button] + } else { + // Make whole cell focusable if no action. + isAccessibilityElement = true + if let message = getAccessibilityMessage(), + let buttonTitle = button.titleLabel?.text { + accessibilityLabel = message + ", " + buttonTitle + } else { + accessibilityLabel = getAccessibilityMessage() + } + } } open override func accessibilityActivate() -> Bool { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexLinkMedium.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexLinkMedium.swift index 9c75f78c..ee6ade09 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexLinkMedium.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexLinkMedium.swift @@ -114,7 +114,7 @@ import Foundation message += body2Text + ", " } - if let rightImageLabel = rightImage.accessibilityLabel, !rightImageLabel.isEmpty { + if let rightImageLabel = rightImage.imageView.accessibilityLabel, !rightImageLabel.isEmpty { message += rightImageLabel } @@ -145,8 +145,8 @@ import Foundation views.append(twoLinkView.leftLink) views.append(twoLinkView.rightLink) - if let rightImageLabel = rightImage.accessibilityLabel, !rightImageLabel.isEmpty { - views.append(rightImage) + if let rightImageLabel = rightImage.imageView.accessibilityLabel, !rightImageLabel.isEmpty { + views.append(rightImage.imageView) } accessibilityElements = views diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexLinkSmall.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexLinkSmall.swift index 6a469b0d..1791ec9d 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexLinkSmall.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/Device/ListDeviceComplexLinkSmall.swift @@ -111,7 +111,7 @@ import Foundation message += body2Text + ", " } - if let rightImageLabel = rightImage.accessibilityLabel, !rightImageLabel.isEmpty { + if let rightImageLabel = rightImage.imageView.accessibilityLabel, !rightImageLabel.isEmpty { message += rightImageLabel } @@ -142,8 +142,8 @@ import Foundation views.append(twoLinkView.leftLink) views.append(twoLinkView.rightLink) - if let rightImageLabel = rightImage.accessibilityLabel, !rightImageLabel.isEmpty { - views.append(rightImage) + if let rightImageLabel = rightImage.imageView.accessibilityLabel, !rightImageLabel.isEmpty { + views.append(rightImage.imageView) } accessibilityElements = views diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/FourColumn/ListFourColumnDataUsageListItem.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/FourColumn/ListFourColumnDataUsageListItem.swift index 4ae4c4d2..8455a5bf 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/FourColumn/ListFourColumnDataUsageListItem.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/FourColumn/ListFourColumnDataUsageListItem.swift @@ -54,8 +54,6 @@ import Foundation arrow.pinHeightAndWidth() arrowAndLabel2Stack.restack() stack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //----------------------------------------------------- @@ -92,7 +90,7 @@ import Foundation //----------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let label1Text = label1.text, !label1Text.isEmpty { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift index ff1c6e1b..ff625e8b 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxAllTextAndLinks.swift @@ -49,11 +49,9 @@ import Foundation addMolecule(stack) stack.restack() - isAccessibilityElement = true - checkbox.isAccessibilityElement = false - accessibilityTraits = checkbox.accessibilityTraits accessibilityHint = checkbox.accessibilityHint - // Update accessibility label on radio button state change. + accessibilityTraits = checkbox.accessibilityTraits + // Update accessibility label on checkbox state change. observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } @@ -92,41 +90,19 @@ import Foundation message += checkboxLabel + ", " } - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text, !eyebrowLabel.isEmpty { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text, !headlineLabel.isEmpty { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text, !bodyLabel.isEmpty { - message += bodyLabel + if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() { + message += label } let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 - isAccessibilityElement = !linkShowing - checkbox.isAccessibilityElement = linkShowing - eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing - if !linkShowing { // Make whole cell focusable if no link. accessibilityLabel = message } else { - // Allow only radio button and link to be focused on. + // Allow only checkbox and link to be focused on. checkbox.accessibilityLabel = message - var elements: [UIView] = [] - - if message.count > 0 { - elements.append(checkbox) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - - accessibilityElements = elements + accessibilityElements = [checkbox, eyebrowHeadlineBodyLink.link] } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxBodyText.swift index 326c9320..69ad2156 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableCheckboxBodyText.swift @@ -49,10 +49,9 @@ import Foundation addMolecule(stack) stack.restack() isAccessibilityElement = true - checkbox.isAccessibilityElement = false - accessibilityTraits = checkbox.accessibilityTraits accessibilityHint = checkbox.accessibilityHint - // Update accessibility label on radio button state change. + accessibilityTraits = checkbox.accessibilityTraits + // Update accessibility label on checkbox state change. observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconAllTextLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconAllTextLinks.swift index 1f8a6a43..9655c4dd 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconAllTextLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconAllTextLinks.swift @@ -42,7 +42,6 @@ import Foundation leftImage.imageView.contentMode = .scaleAspectFit addMolecule(stack) stack.restack() - updateAccessibilityLabel() } //-------------------------------------------------- @@ -63,57 +62,37 @@ import Foundation return 140 } + func getAccessibilityMessage() -> String? { + guard let leftImageLabel = leftImage.imageView.accessibilityLabel else { + return eyebrowHeadlineBodyLink.getAccessibilityMessage() + } + guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else { + return leftImageLabel + } + return leftImageLabel + ", " + label + } + func updateAccessibilityLabel() { - var message = "" - - if let leftImageLabel = leftImage.accessibilityLabel { - message += leftImageLabel + ", " - } - - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { - message += bodyLabel - } - let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 isAccessibilityElement = !linkShowing - eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing - + accessibilityTraits = (isAccessibilityElement && accessoryView != nil) ? .button : .none if !linkShowing { // Make whole cell focusable if no link. - accessibilityLabel = message + accessibilityLabel = getAccessibilityMessage() + } else if let accessoryView = accessoryView { + // Both caret and link. Read all content on caret. + accessoryView.accessibilityLabel = getAccessibilityMessage() + accessibilityElements = [accessoryView, eyebrowHeadlineBodyLink.link] } else { - // Allow only radio button and link to be focused on. - var elements: [UIView] = [] - - if let leftImageLabel = leftImage.accessibilityLabel, !leftImageLabel.isEmpty { - elements.append(leftImage) + // Only link. Manually add accessibility elements to ensure they are read in the right order. + var elements: [Any] = [] + if let leftImageLabel = leftImage.imageView.accessibilityLabel, !leftImageLabel.isEmpty { + elements.append(leftImage.imageView) } - - if let eyeBrowText = eyebrowHeadlineBodyLink.eyebrow.text, !eyeBrowText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.eyebrow) + if let otherElements = eyebrowHeadlineBodyLink.getAccessibilityElements() { + elements.append(otherElements) } - - if let headlineText = eyebrowHeadlineBodyLink.headline.text, !headlineText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.headline) - } - - if let bodyText = eyebrowHeadlineBodyLink.body.text, !bodyText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.body) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - accessibilityElements = elements } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaret.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaret.swift index 297ef31b..2ebe1c98 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaret.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaret.swift @@ -48,8 +48,6 @@ import UIKit rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal) addMolecule(stack) stack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //-------------------------------------------------- @@ -78,10 +76,10 @@ import UIKit } func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" - if let leftImageLabel = leftImage.accessibilityLabel { + if let leftImageLabel = leftImage.imageView.accessibilityLabel { message += leftImageLabel + ", " } @@ -94,5 +92,6 @@ import UIKit } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift index 0617b5e8..c69bebb2 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableIconWithRightCaretBodyText.swift @@ -58,10 +58,8 @@ import Foundation rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal) rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal) rightLabel.numberOfLines = 1 - isAccessibilityElement = true addMolecule(stack) stack.restack() - updateAccessibilityLabel() } //-------------------------------------------------- @@ -93,10 +91,10 @@ import Foundation //-------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" - if let leftImageLabel = leftImage.accessibilityLabel { + if let leftImageLabel = leftImage.imageView.accessibilityLabel { message += leftImageLabel + ", " } @@ -113,5 +111,6 @@ import Foundation } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListAllTextAndLinks.swift index 5924b3d7..1ec68330 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListAllTextAndLinks.swift @@ -37,10 +37,11 @@ import Foundation //-------------------------------------------------- override open func setupView() { super.setupView() + leftLabel.setContentCompressionResistancePriority(.required, for: .horizontal) + leftLabel.setContentHuggingPriority(.defaultHigh, for: .vertical) leftLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal) addMolecule(stack) stack.restack() - updateAccessibilityLabel() } //--------------------------------------------------- @@ -66,66 +67,41 @@ import Foundation leftLabel.setFontStyle(.Title2XLarge) } - open override func layoutSubviews() { - super.layoutSubviews() - // This fixes a defect body text where it doesn't layout correctly. - eyebrowHeadlineBodyLink.body.preferredMaxLayoutWidth = eyebrowHeadlineBodyLink.frame.width - } - //-------------------------------------------------- // MARK: - Accessibility //-------------------------------------------------- + func getAccessibilityMessage() -> String? { + guard let leftLabel = leftLabel.text else { + return eyebrowHeadlineBodyLink.getAccessibilityMessage() + } + guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else { + return leftLabel + } + return leftLabel + ", " + label + } + func updateAccessibilityLabel() { - - var message = "" - - if let leftLabel = leftLabel.text { - message += leftLabel + ", " - } - - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { - message += bodyLabel - } - + let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 isAccessibilityElement = !linkShowing - eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing - + accessibilityTraits = (isAccessibilityElement && accessoryView != nil) ? .button : .none if !linkShowing { // Make whole cell focusable if no link. - accessibilityLabel = message + accessibilityLabel = getAccessibilityMessage() + } else if let accessoryView = accessoryView { + // Both caret and link. Read all content on caret. + accessoryView.accessibilityLabel = getAccessibilityMessage() + accessibilityElements = [accessoryView, eyebrowHeadlineBodyLink.link] } else { - var elements: [UIView] = [] - + // Only link. Manually add accessibility elements to ensure they are read in the right order. + var elements: [Any] = [] if let leftLabelText = leftLabel.text, !leftLabelText.isEmpty { elements.append(leftLabel) } - - if let eyeBrowText = eyebrowHeadlineBodyLink.eyebrow.text, !eyeBrowText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.eyebrow) + if let otherElements = eyebrowHeadlineBodyLink.getAccessibilityElements() { + elements.append(otherElements) } - - if let headlineText = eyebrowHeadlineBodyLink.headline.text, !headlineText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.headline) - } - - if let bodyText = eyebrowHeadlineBodyLink.body.text, !bodyText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.body) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - accessibilityElements = elements } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListBodyText.swift new file mode 100644 index 00000000..a0a7a462 --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListBodyText.swift @@ -0,0 +1,95 @@ +// +// ListLeftVariableNumberedListBodyText.swift +// MVMCoreUI +// +// Created by Subhankar Acharya on 12/06/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers open class ListLeftVariableNumberedListBodyText: TableViewCell { + //-------------------------------------------------- + // MARK: - Outlets + //----------------------------------------------------- + public let leftLabel = Label(fontStyle: .Title2XLarge) + public let headlineBody = HeadlineBody() + public var stack: Stack + + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + + public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + + stack = Stack.createStack(with: [(view: leftLabel, model: StackItemModel(horizontalAlignment: .fill)), + (view: headlineBody, model: StackItemModel(horizontalAlignment: .leading))], + axis: .horizontal) + super.init(style: style, reuseIdentifier: reuseIdentifier) + } + + public required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + //-------------------------------------------------- + // MARK: - Life Cycle + //-------------------------------------------------- + override open func setupView() { + super.setupView() + leftLabel.setContentCompressionResistancePriority(.required, for: .horizontal) + leftLabel.setContentHuggingPriority(.defaultHigh, for: .vertical) + leftLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal) + addMolecule(stack) + stack.restack() + } + + //--------------------------------------------------- + // 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? ListLeftVariableNumberedListBodyTextModel else { return } + leftLabel.text = String(model.number) + headlineBody.set(with: model.headlineBody, delegateObject, additionalData) + updateAccessibilityLabel() + } + + open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return 140 + } + + open override func reset() { + super.reset() + leftLabel.setFontStyle(.Title2XLarge) + } + + //-------------------------------------------------- + // MARK: - Accessibility + //-------------------------------------------------- + + func updateAccessibilityLabel() { + + isAccessibilityElement = true + + var message = "" + + if let leftLabel = leftLabel.text { + message += leftLabel + ", " + } + + if let headlineLabel = headlineBody.headlineLabel.text { + message += headlineLabel + ", " + } + + if let messageLabel = headlineBody.messageLabel.text { + message += messageLabel + } + + accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none + } +} + diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListBodyTextModel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListBodyTextModel.swift new file mode 100644 index 00000000..372bab32 --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableNumberedListBodyTextModel.swift @@ -0,0 +1,58 @@ +// +// ListLeftVariableNumberedListBodyTextModel.swift +// MVMCoreUI +// +// Created by Subhankar Acharya on 12/06/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +public class ListLeftVariableNumberedListBodyTextModel: ListItemModel, MoleculeModelProtocol { + //----------------------------------------------------- + // MARK: - Properties + //----------------------------------------------------- + + public static var identifier: String = "listLVNLBdy" + public var number: Int + public var headlineBody: HeadlineBodyModel + + //----------------------------------------------------- + // MARK: - Initializer + //----------------------------------------------------- + + public init(number: Int, headlineBody: HeadlineBodyModel) { + self.number = number + self.headlineBody = headlineBody + super.init() + } + + //----------------------------------------------------- + // MARK: - Keys + //----------------------------------------------------- + + private enum CodingKeys: String, CodingKey { + case moleculeName + case number + case headlineBody + } + + //----------------------------------------------------- + // MARK: - Codec + //----------------------------------------------------- + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + number = try typeContainer.decode(Int.self, forKey: .number) + headlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .headlineBody) + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encode(number, forKey: .number) + try container.encode(headlineBody, forKey: .headlineBody) + } +} diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift index 5756d4f5..e5e9e178 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAllTextAndLinks.swift @@ -89,41 +89,19 @@ import Foundation message += radioButtonLabel + ", " } - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { - message += bodyLabel + if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() { + message += label } let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 isAccessibilityElement = !linkShowing - radioButton.isAccessibilityElement = linkShowing - eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing - if !linkShowing { // Make whole cell focusable if no link. accessibilityLabel = message } else { // Allow only radio button and link to be focused on. radioButton.accessibilityLabel = message - - var elements: [UIView] = [] - - if !message.isEmpty { - elements.append(radioButton) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - - accessibilityElements = elements + accessibilityElements = [radioButton, eyebrowHeadlineBodyLink.link] } } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift index 523c6d4e..e14e91e2 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonAndPaymentMethod.swift @@ -50,9 +50,9 @@ import UIKit eyebrowHeadlineBodyLink.body.textColor = .mvmOrangeAA eyebrowHeadlineBodyLink.headline.setFontStyle(.BoldBodySmall) - accessibilityTraits = radioButton.accessibilityTraits accessibilityHint = radioButton.accessibilityHint - + accessibilityTraits = radioButton.accessibilityTraits + // Update accessibility label on radio button state change. observation = observe(\.radioButton.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() @@ -103,44 +103,23 @@ import UIKit message += radioButtonLabel + ", " } - if let leftImageLabel = leftImage.accessibilityLabel { + if let leftImageLabel = leftImage.imageView.accessibilityLabel { message += leftImageLabel + ", " } - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { - message += bodyLabel + if let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() { + message += label } let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 isAccessibilityElement = !linkShowing - radioButton.isAccessibilityElement = linkShowing - eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing - if !linkShowing { // Make whole cell focusable if no link. accessibilityLabel = message } else { // Allow only radio button and link to be focused on. radioButton.accessibilityLabel = message - var elements: [UIView] = [] - - if !message.isEmpty { - elements.append(radioButton) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - - accessibilityElements = elements + accessibilityElements = [radioButton, eyebrowHeadlineBodyLink.link] } } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonBodyText.swift index 860b78f8..a30f3f9e 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/LeftVariable/ListLeftVariableRadioButtonBodyText.swift @@ -47,9 +47,8 @@ open class ListLeftVariableRadioButtonBodyText: TableViewCell { // Make the whole cell focusable. isAccessibilityElement = true - radioButton.isAccessibilityElement = false - accessibilityTraits = radioButton.accessibilityTraits accessibilityHint = radioButton.accessibilityHint + accessibilityTraits = radioButton.accessibilityTraits updateAccessibilityLabel() // Update accessibility label on radio button state change. diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThin.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThin.swift index 08255db9..4e0eb83a 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThin.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ListProgressBarThin.swift @@ -78,8 +78,6 @@ import Foundation stack.restack() horizontalStack.restack() labelStack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //------------------------------------------------------ @@ -115,7 +113,7 @@ import Foundation //------------------------------------------------------ func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftHeadlineText = leftHeadline.text { @@ -135,5 +133,6 @@ import Foundation } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextAllTextAndLinks.swift index a5d2a374..6e5a7245 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextAllTextAndLinks.swift @@ -43,7 +43,6 @@ import Foundation super.setupView() addMolecule(stack) stack.restack() - updateAccessibilityLabel() } open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { @@ -72,8 +71,7 @@ import Foundation // MARK: - Accessibility //-------------------------------------------------- - func updateAccessibilityLabel() { - + func getAccessibilityMessage() -> String? { var message = "" if let eyebrowLabel = eyebrow.text, !eyebrowLabel.isEmpty { @@ -91,19 +89,31 @@ import Foundation if let bodyLabel = body.text, !bodyLabel.isEmpty { message += bodyLabel } - + return message.count > 0 ? message : nil + } + + // Ensures voice over does not read "selected" after user triggers action on cell. + override public var accessibilityTraits: UIAccessibilityTraits { + get { + return (accessoryView != nil) ? .button : .none + } + set {} + } + + func updateAccessibilityLabel() { + let linkShowing = link.titleLabel?.text?.count ?? 0 > 0 isAccessibilityElement = !linkShowing - link.isAccessibilityElement = linkShowing - if !linkShowing { // Make whole cell focusable if no link. - accessibilityLabel = message + accessibilityLabel = getAccessibilityMessage() + } else if let accessoryView = accessoryView { + // Both caret and link. Read all content on caret. + accessoryView.accessibilityLabel = getAccessibilityMessage() + accessibilityElements = [accessoryView, link] } else { - // Allow only radio button and link to be focused on. - var elements: [UIView] = [] - - + // Only link. Manually add accessibility elements to ensure they are read in the right order. + var elements: [Any] = [] if let eyeBrowText = eyebrow.text, !eyeBrowText.isEmpty { elements.append(eyebrow) } @@ -119,11 +129,7 @@ import Foundation if let bodyText = body.text, !bodyText.isEmpty { elements.append(body) } - - if linkShowing { - elements.append(link) - } - + elements.append(link) accessibilityElements = elements } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextBodyText.swift index bad9caca..cced55dd 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/OneColumn/ListOneColumnFullWidthTextBodyText.swift @@ -24,8 +24,6 @@ import Foundation super.setupView() addMolecule(headlineBody) - isAccessibilityElement = true - updateAccessibilityLabel() } open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?){ @@ -46,7 +44,7 @@ import Foundation //----------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let headlineLabel = headlineBody.headlineLabel.text { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRVWheel.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRVWheel.swift index f410c635..58b9ada0 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRVWheel.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRVWheel.swift @@ -41,8 +41,6 @@ import Foundation rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal) addMolecule(stack) stack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //------------------------------------------------- @@ -75,7 +73,7 @@ import Foundation //-------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftLabelText = leftLabel.text, !leftLabelText.isEmpty { @@ -91,5 +89,6 @@ import Foundation } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableButtonAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableButtonAllTextAndLinks.swift index 6e9503dc..f0d5cdbf 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableButtonAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableButtonAllTextAndLinks.swift @@ -47,9 +47,9 @@ import Foundation addMolecule(stack) stack.restack() - updateAccessibilityLabel() accessibilityValue = button.accessibilityValue accessibilityHint = button.accessibilityHint + accessibilityTraits = .button } //----------------------------------------------------- @@ -74,48 +74,36 @@ import Foundation // MARK: - Accessibility //---------------------------------------------------- + func getAccessibilityMessage() -> String? { + guard let buttonText = button.titleLabel?.text else { + return eyebrowHeadlineBodyLink.getAccessibilityMessage() + } + guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else { + return buttonText + } + return label + ", " + buttonText + } + func updateAccessibilityLabel() { - - var message = "" - - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { - message += bodyLabel + ", " - } - - if let buttonLabel = button.accessibilityLabel { - message += buttonLabel - } - let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 - - isAccessibilityElement = !linkShowing - button.isAccessibilityElement = linkShowing - eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing - - if !linkShowing { - // Make whole cell focusable if no link. - accessibilityLabel = message + if !linkShowing && accessoryView == nil { + // Make whole cell focusable if one action + isAccessibilityElement = true + accessibilityLabel = getAccessibilityMessage() } else { - // Allow only radio button and link to be focused on. - button.accessibilityLabel = message - var elements: [UIView] = [] - - if !message.isEmpty { - elements.append(button) + // Make buttons focusable. + isAccessibilityElement = false + var elements: [Any] = [] + if let accessoryView = accessoryView { + accessoryView.accessibilityLabel = eyebrowHeadlineBodyLink.getAccessibilityMessage() + elements.append(accessoryView) + } else { + button.accessibilityLabel = getAccessibilityMessage() } - + elements.append(button) if linkShowing { elements.append(eyebrowHeadlineBodyLink.link) } - accessibilityElements = elements } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift index 5bb62b90..f6526e10 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePayments.swift @@ -40,8 +40,6 @@ import Foundation rightImage.addSizeConstraintsForAspectRatio = true addMolecule(stack) stack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //---------------------------------------------------- @@ -72,17 +70,18 @@ import Foundation //-------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftLabelText = leftLabel.text, !leftLabelText.isEmpty { message += leftLabelText + ", " } - if let rightImageText = rightImage.accessibilityLabel, !rightImageText.isEmpty { + if let rightImageText = rightImage.imageView.accessibilityLabel, !rightImageText.isEmpty { message += rightImageText } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinks.swift index afbdd2b5..65301304 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeAllTextAndLinks.swift @@ -67,7 +67,6 @@ import Foundation arrow.pinHeightAndWidth() addMolecule(stack) stack.restack() - updateAccessibilityLabel() } open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { @@ -89,57 +88,36 @@ import Foundation // MARK: - Accessibility //-------------------------------------------------- + func getAccessibilityMessage() -> String? { + guard let rightLabelText = rightLabel.text else { + return eyebrowHeadlineBodyLink.getAccessibilityMessage() + } + guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else { + return rightLabelText + } + return label + ", " + rightLabelText + } + func updateAccessibilityLabel() { - let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 isAccessibilityElement = !linkShowing - eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing - + accessibilityTraits = (isAccessibilityElement && accessoryView != nil) ? .button : .none if !linkShowing { // Make whole cell focusable if no link. - var message = "" - - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { - message += bodyLabel + ", " - } - - if let rightLabelText = rightLabel.text { - message += rightLabelText - } - - accessibilityLabel = message - + accessibilityLabel = getAccessibilityMessage() + } else if let accessoryView = accessoryView { + // Both caret and link. Read all content on caret. + accessoryView.accessibilityLabel = getAccessibilityMessage() + accessibilityElements = [accessoryView, eyebrowHeadlineBodyLink.link] } else { - var elements: [UIView] = [] - - if let eyebrowText = eyebrowHeadlineBodyLink.eyebrow.text, !eyebrowText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.eyebrow) + // Only link. Manually add accessibility elements to ensure they are read in the right order. + var elements: [Any] = [] + if let otherElements = eyebrowHeadlineBodyLink.getAccessibilityElements() { + elements.append(otherElements) } - - if let headlineText = eyebrowHeadlineBodyLink.headline.text, !headlineText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.headline) - } - - if let bodyText = eyebrowHeadlineBodyLink.body.text, !bodyText.isEmpty { - elements.append(eyebrowHeadlineBodyLink.body) - } - - if linkShowing { - elements.append(eyebrowHeadlineBodyLink.link) - } - if let rightLabelText = rightLabel.text, !rightLabelText.isEmpty { elements.append(rightLabel) } - accessibilityElements = elements } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyText.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyText.swift index a93d50f9..8428dccc 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyText.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariablePriceChangeBodyText.swift @@ -54,8 +54,6 @@ import Foundation addMolecule(stack) stack.restack() arrowAndRightLabelStack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //-------------------------------------------------- @@ -87,7 +85,7 @@ import Foundation //-------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let headlineText = headlineBody.headlineLabel.text, !headlineText.isEmpty { @@ -103,5 +101,6 @@ import Foundation } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableTextLinkAllTextAndLinks.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableTextLinkAllTextAndLinks.swift index 2dd2ca99..2c2f25bc 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableTextLinkAllTextAndLinks.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableTextLinkAllTextAndLinks.swift @@ -47,7 +47,6 @@ import Foundation addMolecule(stack) stack.restack() - updateAccessibilityLabel() } //-------------------------------------------------- @@ -72,52 +71,41 @@ import Foundation // MARK: - Accessibility //-------------------------------------------------- + func getAccessibilityMessage() -> String? { + guard let linkText = link.titleLabel?.text else { + return eyebrowHeadlineBodyLink.getAccessibilityMessage() + } + guard let label = eyebrowHeadlineBodyLink.getAccessibilityMessage() else { + return linkText + } + return label + ", " + linkText + } + func updateAccessibilityLabel() { - - var message = "" - - if let eyebrowLabel = eyebrowHeadlineBodyLink.eyebrow.text { - message += eyebrowLabel + ", " - } - - if let headlineLabel = eyebrowHeadlineBodyLink.headline.text { - message += headlineLabel + ", " - } - - if let bodyLabel = eyebrowHeadlineBodyLink.body.text { - message += bodyLabel + ", " - } - - if let linkLabel = link.accessibilityLabel { - message += linkLabel - } - let linkShowing = eyebrowHeadlineBodyLink.link.titleLabel?.text?.count ?? 0 > 0 - - isAccessibilityElement = !linkShowing - link.isAccessibilityElement = linkShowing - eyebrowHeadlineBodyLink.link.isAccessibilityElement = linkShowing - - if !linkShowing { - // Make whole cell focusable if no link. - accessibilityLabel = message + accessibilityTraits = .button + if !linkShowing && accessoryView == nil { + // Make whole cell focusable if one action + isAccessibilityElement = true + accessibilityLabel = getAccessibilityMessage() } else { - // Allow only radio button and link to be focused on. - link.accessibilityLabel = message - var elements: [UIView] = [] - + // Make buttons focusable. + isAccessibilityElement = false + var elements: [Any] = [] + if let accessoryView = accessoryView { + accessoryView.accessibilityLabel = eyebrowHeadlineBodyLink.getAccessibilityMessage() + elements.append(accessoryView) + } else { + link.accessibilityLabel = getAccessibilityMessage() + } + elements.append(link) if linkShowing { elements.append(eyebrowHeadlineBodyLink.link) } - - if !message.isEmpty { - elements.append(link) - } - accessibilityElements = elements } } - + open override func accessibilityActivate() -> Bool { return link.accessibilityActivate() } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableTotalData.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableTotalData.swift index a42cd81d..fe2c8a24 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableTotalData.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/RightVariable/ListRightVariableTotalData.swift @@ -51,8 +51,6 @@ import Foundation rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal) addMolecule(stack) stack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //-------------------------------------------------- @@ -86,7 +84,7 @@ import Foundation //-------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftLabelText = leftLabel.text, !leftLabelText.isEmpty { @@ -98,5 +96,6 @@ import Foundation } accessibilityLabel = message + accessibilityTraits = (accessoryView != nil) ? .button : .none } } diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnDataUsage.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnDataUsage.swift index 00a09527..6e0013d1 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnDataUsage.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnDataUsage.swift @@ -42,8 +42,6 @@ import Foundation super.setupView() addMolecule(stack) stack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } //-------------------------------------------------- @@ -77,7 +75,7 @@ import Foundation //-------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftText = leftLabel.text, !leftText.isEmpty { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnInternationalData.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnInternationalData.swift index 20e7378a..c8aaef83 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnInternationalData.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnInternationalData.swift @@ -55,8 +55,6 @@ import Foundation arrow.pinHeightAndWidth() arrowAndLabel2Stack.restack() stack.restack() - isAccessibilityElement = true - updateAccessibilityLabel() } open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { @@ -87,7 +85,7 @@ import Foundation //-------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftText = leftLabel.text, !leftText.isEmpty { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnCompareChanges.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnCompareChanges.swift index e0efa546..62048a71 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnCompareChanges.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnCompareChanges.swift @@ -54,7 +54,6 @@ import Foundation ((molecule as? StackItem)?.view as? Stack)?.restack() } containingStack.restack() - isAccessibilityElement = false } //------------------------------------------------------ diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnPriceDescription.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnPriceDescription.swift index 16328584..472c522d 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnPriceDescription.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnPriceDescription.swift @@ -67,9 +67,6 @@ import Foundation leftHeadline.numberOfLines = 1 rightLabel.numberOfLines = 1 rightSubLabel.numberOfLines = 1 - - isAccessibilityElement = true - updateAccessibilityLabel() } //---------------------------------------------------- @@ -107,7 +104,7 @@ import Foundation //---------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftHeadline = leftHeadline.text, !leftHeadline.isEmpty { diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnPriceDetails.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnPriceDetails.swift index e725bb64..cc59a15a 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnPriceDetails.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/TwoColumn/ListTwoColumnPriceDetails.swift @@ -31,8 +31,6 @@ import UIKit containerHelper.constrainView(view) rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal) rightLabel.setContentHuggingPriority(.defaultHigh, for: .vertical) - isAccessibilityElement = true - updateAccessibilityLabel() } open override func updateView(_ size: CGFloat) { @@ -72,7 +70,7 @@ import UIKit //---------------------------------------------------- func updateAccessibilityLabel() { - + isAccessibilityElement = true var message = "" if let leftLabel = leftLabel.text, !leftLabel.isEmpty { diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift index 94e53790..1068f350 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift @@ -56,7 +56,7 @@ import Foundation // Add buttons var tabs: [UITabBarItem] = [] for (index, tab) in model.tabs.enumerated() { - let tabBarItem = UITabBarItem(title: tab.title, image: UIImage(named: tab.image, in: MVMCoreCache.shared()?.bundleToUseForImages(), compatibleWith: nil), tag: index) + let tabBarItem = UITabBarItem(title: tab.title, image: MVMCoreCache.shared()?.getImageFromRegisteredBundles(tab.image), tag: index) tabs.append(tabBarItem) } setItems(tabs, animated: false) diff --git a/MVMCoreUI/Atomic/Molecules/NavigationBar/Buttons/NavigationImageButtonModel.swift b/MVMCoreUI/Atomic/Molecules/NavigationBar/Buttons/NavigationImageButtonModel.swift index aff9c58f..4c021d5f 100644 --- a/MVMCoreUI/Atomic/Molecules/NavigationBar/Buttons/NavigationImageButtonModel.swift +++ b/MVMCoreUI/Atomic/Molecules/NavigationBar/Buttons/NavigationImageButtonModel.swift @@ -11,34 +11,34 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule public var backgroundColor: Color? public static var identifier: String = "navigationImageButton" - public var imageName: String + public var image: String public var action: ActionModelProtocol - public init(with imageName: String, action: ActionModelProtocol) { - self.imageName = imageName + public init(with image: String, action: ActionModelProtocol) { + self.image = image self.action = action } private enum CodingKeys: String, CodingKey { - case imageName + case image case action } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - imageName = try typeContainer.decode(String.self, forKey: .imageName) + image = try typeContainer.decode(String.self, forKey: .image) action = try typeContainer.decodeModel(codingKey: .action) } open func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(imageName, forKey: .imageName) + try container.encode(image, forKey: .image) try container.encodeModel(action, forKey: .action) } /// Convenience function that creates a BarButtonItem for the model. public func createNavigationItemButton(delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> UIBarButtonItem { - let image = UIImage(named: imageName, in: MVMCoreCache.shared()?.bundleToUseForImages(), compatibleWith: nil) - return ImageBarButtonItem.create(with: image, actionModel: action, delegateObject: delegateObject, additionalData: additionalData) + let uiImage = MVMCoreCache.shared()?.getImageFromRegisteredBundles(image) + return ImageBarButtonItem.create(with: uiImage, actionModel: action, delegateObject: delegateObject, additionalData: additionalData) } } diff --git a/MVMCoreUI/Atomic/Molecules/NavigationBar/NavigationItemModel.swift b/MVMCoreUI/Atomic/Molecules/NavigationBar/NavigationItemModel.swift index bf926878..c0ee897c 100644 --- a/MVMCoreUI/Atomic/Molecules/NavigationBar/NavigationItemModel.swift +++ b/MVMCoreUI/Atomic/Molecules/NavigationBar/NavigationItemModel.swift @@ -19,7 +19,7 @@ public class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProt public var tintColor: Color public var line: LineModel? public var alwaysShowBackButton = false - public var backButton: (NavigationButtonModelProtocol & MoleculeModelProtocol)? = NavigationImageButtonModel(with: "back", action: ActionBackModel()) + public var backButton: (NavigationButtonModelProtocol & MoleculeModelProtocol)? = NavigationImageButtonModel(with: "nav_back", action: ActionBackModel()) public var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]? public var additionalRightButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]? @@ -51,7 +51,7 @@ public class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProt hidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidden) ?? false backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) ?? Color(uiColor: .white) tintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .tintColor) ?? Color(uiColor: .black) - line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) + line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) ?? LineModel(type: .standard) alwaysShowBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .alwaysShowBackButton) ?? false if let backButton: (NavigationButtonModelProtocol & MoleculeModelProtocol) = try typeContainer.decodeModelIfPresent(codingKey: .backButton) { self.backButton = backButton diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift index 7d176ba2..12b42e9f 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/EyebrowHeadlineBodyLink.swift @@ -69,4 +69,44 @@ import UIKit open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return 65 } + + //-------------------------------------------------- + // MARK: - Accessibility Helpers + //-------------------------------------------------- + + /// Returns the labels text in one message. + func getAccessibilityMessage() -> String? { + var message = "" + + if let eyebrowLabel = eyebrow.text { + message += eyebrowLabel + ", " + } + + if let headlineLabel = headline.text { + message += headlineLabel + ", " + } + + if let bodyLabel = body.text { + message += bodyLabel + } + return message.count > 0 ? message : nil + } + + /// Returns an array of the appropriate accessibility elements. + func getAccessibilityElements() -> [Any]? { + var elements: [UIView] = [] + if eyebrow.hasText { + elements.append(eyebrow) + } + if headline.hasText { + elements.append(headline) + } + if body.hasText { + elements.append(body) + } + if link.titleLabel?.text?.count ?? 0 > 0 { + elements.append(link) + } + return elements.count > 0 ? elements : nil + } } diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/ThreeHeadlineBodyLink.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/ThreeHeadlineBodyLink.swift index 474907dd..5926951f 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/ThreeHeadlineBodyLink.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/ThreeHeadlineBodyLink.swift @@ -73,8 +73,8 @@ open class ThreeHeadlineBodyLink: View { bottomAnchor.constraint(equalTo: link.bottomAnchor).isActive = true isAccessibilityElement = true - accessibilityTraits = link.accessibilityTraits accessibilityHint = link.accessibilityHint + accessibilityTraits = link.accessibilityTraits updateAccessibilityLabel() } diff --git a/MVMCoreUI/BaseClasses/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift index caaeec85..300150e8 100644 --- a/MVMCoreUI/BaseClasses/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -205,8 +205,8 @@ import UIKit let caret = CaretView(lineWidth: 1) caret.translatesAutoresizingMaskIntoConstraints = true caret.isAccessibilityElement = true - caret.accessibilityTraits = .button caret.accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "AccTabHint") + caret.accessibilityTraits = .button caret.size = .small(.vertical) if let size = caret.size?.dimensions() { caret.frame = CGRect(origin: CGPoint.zero, size: size) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 395587ec..3a7bc962 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -8,7 +8,7 @@ import UIKit -@objc open class ViewController: UIViewController, MVMCoreViewControllerProtocol, MVMCoreViewManagerViewControllerProtocol, MoleculeDelegateProtocol, FormHolderProtocol, MVMCoreActionDelegateProtocol, MVMCoreLoadDelegateProtocol, UITextFieldDelegate, UITextViewDelegate, ObservingTextFieldDelegate { +@objc open class ViewController: UIViewController, MVMCoreViewControllerProtocol, MVMCoreViewManagerViewControllerProtocol, MoleculeDelegateProtocol, FormHolderProtocol, MVMCoreActionDelegateProtocol, MVMCoreLoadDelegateProtocol, UITextFieldDelegate, UITextViewDelegate, ObservingTextFieldDelegate, MVMCoreUIDetailViewProtocol { @objc public var pageType: String? @objc public var loadObject: MVMCoreLoadObject? public var pageModel: MVMControllerModelProtocol? @@ -163,9 +163,6 @@ import UIKit open func createDefaultLegacyNavigationModel() -> NavigationItemModel { let navigationModel = NavigationItemModel() navigationModel.title = pageModel?.screenHeading - if /*(self as? MVMCoreUITabBarPageControlViewController) != nil ||*/ manager != nil || loadObject?.requestParameters?.tabWasPressed ?? false == true { - navigationModel.line = LineModel(type: .none) - } return navigationModel } @@ -199,18 +196,8 @@ import UIKit // We additionally want our left items navigationItem.leftItemsSupplementBackButton = true - NavigationController.set(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) - - // Special logic when using the split view controller. Legacy Update Panels. Change how this is done. - guard navigationController == MVMCoreUISplitViewController.main()?.navigationController, - navigationController.topViewController == viewController else { return } - - MVMCoreUISession.sharedGlobal()?.splitViewController?.setupPanels() - showBottomProgressBar() - - MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(isMasterInitiallyAccessible(), for: viewController) - MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(isSupportInitiallyAccessible(), for: viewController) - MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(navigationItemModel.tintColor.uiColor) + // Utilize helper function to set the split view and navigation item state. + MVMCoreUISplitViewController.setSplitViewController(for: viewController, navigationController: navigationController, navigationItemModel: navigationItemModel, leftPanelAccessible: isMasterInitiallyAccessible(), rightPanelAccessible: isSupportInitiallyAccessible(), progress: bottomProgress()) } // Eventually will be moved to server @@ -252,12 +239,10 @@ import UIKit } // Eventually will be moved to Model - open func showBottomProgressBar() { - if MVMCoreUISplitViewController.main()?.getCurrentVisibleController() == self, - let progressString = loadObject?.pageJSON?.optionalStringForKey(KeyProgressPercent), - let progress = Float(progressString) { - MVMCoreUISplitViewController.main()?.setBottomProgressBarProgress(progress / Float(100)) - } + open func bottomProgress() -> Float? { + guard let progressString = loadObject?.pageJSON?.optionalStringForKey(KeyProgressPercent), + let progress = Float(progressString) else { return nil } + return (progress / Float(100)) } // MARK: - TabBar @@ -321,24 +306,23 @@ import UIKit super.viewDidLayoutSubviews() } - open override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) + open func pageShown() { + // Update the navigation bar ui when view is appearing. + setNavigationController() - // Update the navigation bar ui when view is appearing. Can remove check in the future, see viewControllerReady - if manager == nil { - setNavigationController() - } + // Update tab if needed. + updateTabBar() + + // Track. + MVMCoreUISession.sharedGlobal()?.currentPageType = pageType + MVMCoreUILoggingHandler.shared()?.defaultLogPageState(forController: self) } open override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - // Update tab if needed. - updateTabBar() - if manager == nil { - MVMCoreUISession.sharedGlobal()?.currentPageType = pageType - MVMCoreUILoggingHandler.shared()?.defaultLogPageState(forController: self) + pageShown() } executeBehaviors { (behavior: PageVisibilityBehavior) in @@ -375,13 +359,7 @@ import UIKit // MARK: - MVMCoreViewManagerViewControllerProtocol open func viewControllerReady(inManager manager: UIViewController & MVMCoreViewManagerProtocol) { - // TODO: This check and set aren't technically needed anymore. The one in viewwillappear should be enough. However, there is a timing issue with the manager where the screen lays out before the menu shows, so the screen grows off the screen. Can fix in the future. - if let _ = self.view { - setNavigationController() - } - // Janky way to track current page. - MVMCoreUISession.sharedGlobal()?.currentPageType = pageType - MVMCoreUILoggingHandler.shared()?.defaultLogPageState(forController: self) + pageShown() } // MARK: - MVMCoreLoadDelegateProtocol @@ -443,6 +421,13 @@ import UIKit open func addMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], indexPath: IndexPath, animation: UITableView.RowAnimation) {} open func removeMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], animation: UITableView.RowAnimation) {} + // MARK: - MVMCoreUIDetailViewProtocol + + // Reset the navigation state. + public func splitViewDidReset() { + setNavigationController() + } + // MARK: - UITextFieldDelegate (Check if this is still needed) // To Remove TextFields Bug: Keyboard is not dismissing after reaching textfield max length limit open func textFieldShouldReturn(_ textField: UITextField) -> Bool { diff --git a/MVMCoreUI/Containers/NavigationController.swift b/MVMCoreUI/Containers/NavigationController.swift index 0d4d0a56..12d70634 100644 --- a/MVMCoreUI/Containers/NavigationController.swift +++ b/MVMCoreUI/Containers/NavigationController.swift @@ -67,8 +67,8 @@ import UIKit viewController.navigationItem.rightBarButtonItems = rightItems.count > 0 ? rightItems : nil } - /// Convenience function for setting navigation bar with model. - public static func set(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { + /// Convenience function for setting the navigation bar ui, except for the buttons. + public static func setNavigationUI(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { viewController.navigationItem.title = navigationItemModel.title viewController.navigationItem.accessibilityLabel = navigationItemModel.title viewController.navigationItem.hidesBackButton = (navigationItemModel.backButton != nil) @@ -86,8 +86,11 @@ import UIKit if let navigationController = navigationController as? NavigationController { navigationController.separatorView?.isHidden = navigationItemModel.line?.type ?? .standard == .none } + } - // Sets up the navigation buttons. + /// Convenience function for setting navigation bar with model. + public static func set(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) { + setNavigationUI(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) setNavigationButtons(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) } diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h index 377508c7..2ec18da9 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUIDetailViewProtocol.h @@ -42,6 +42,9 @@ NS_ASSUME_NONNULL_BEGIN - (UIStatusBarStyle)defaultStatusBarStyle; - (nullable UIColor *)defaultStatusBarBackgroundColor; +/// Called when the split view did reset. If this function found, the splitview assumes it is handling the split view state and does not do anything. If you have navigation item buttons, override this function and handle the panels manually. +- (void)splitViewDidReset; + @end NS_ASSUME_NONNULL_END diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift new file mode 100644 index 00000000..ed4f931c --- /dev/null +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController+Extension.swift @@ -0,0 +1,122 @@ +// +// MVMCoreUISplitViewController+Extension.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 6/18/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +public extension MVMCoreUISplitViewController { + + /// Convenience function. Sets the navigation and split view properties for the view controller. + static func setSplitViewController(for viewController: UIViewController, navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, leftPanelAccessible: Bool, rightPanelAccessible: Bool, progress: Float? = nil) { + guard let splitView = MVMCoreUISplitViewController.main(), + navigationController == splitView.navigationController, + navigationController.topViewController == viewController else { + NavigationController.set(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + return + } + splitView.set(for: viewController, navigationController: navigationController, navigationItemModel: navigationItemModel, leftPanelAccessible: leftPanelAccessible, rightPanelAccessible: rightPanelAccessible, progress: progress) + } + + /// Sets the navigation item for the view controller based on the model and splitview controller + func set(for viewController: UIViewController, navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, leftPanelAccessible: Bool, rightPanelAccessible: Bool, progress: Float? = nil) { + + // Setup the panels. + MVMCoreUISession.sharedGlobal()?.splitViewController?.setupPanels() + + NavigationController.setNavigationUI(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + + MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(leftPanelAccessible, for: viewController, updateNavigationButtons: false) + MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(rightPanelAccessible, for: viewController, updateNavigationButtons: false) + + setLeftNavigationButtons(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + setRightNavigationButtons(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + + MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(navigationItemModel.tintColor.uiColor) + + setBottomProgressBarProgress(progress ?? 0) + } + + /// Sets the left navigation items for the view controller based on model and splitview. + func setLeftNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) { + var leftItems: [UIBarButtonItem] = [] + let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject + + // Add back button first. + if let backButtonModel = navigationItemModel?.backButton { + if navigationController.viewControllers.count > 1 || navigationItemModel!.alwaysShowBackButton { + leftItems.append(backButtonModel.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) + } + } else if let backButton = backButton, + navigationController.viewControllers.count > 1 { + leftItems.append(backButton) + } + + // Add the panel button after the back button. + if let panelButton = leftPanelButton, + leftPanelIsAccessible, + !leftPanelStaysExtended() { + leftItems.append(panelButton) + } + + // Add other model buttons + if let leftItemModels = navigationItemModel?.additionalLeftButtons { + for item in leftItemModels { + leftItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) + } + } + + // Add any buttons added by the splitview. + if let additionalLeftButtons = additionalLeftButtons(for: viewController) { + leftItems.append(contentsOf: additionalLeftButtons) + } + + viewController.navigationItem.setLeftBarButtonItems(leftItems.count > 0 ? leftItems : nil, animated: !DisableAnimations.boolValue) + } + + /// Sets the right navigation items for the view controller based on model and splitview. + func setRightNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) { + let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject + var rightItems: [UIBarButtonItem] = [] + + // Add the panel button first. + if let panelButton = rightPanelButton, + rightPanelIsAccessible, + !rightPanelStaysExtended() { + rightItems.append(panelButton) + } + + // Add other model buttons + if let rightItemModels = navigationItemModel?.additionalRightButtons { + for item in rightItemModels { + rightItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil)) + } + } + + // Add any buttons added by the splitview. + if let additionalRightButtons = additionalRightButtons(for: viewController) { + rightItems.append(contentsOf: additionalRightButtons) + } + + viewController.navigationItem.setRightBarButtonItems(rightItems.count > 0 ? rightItems : nil, animated: !DisableAnimations.boolValue) + } + + // MARK: - Legacy Functions + /// Convenience setter for legacy files. Sets the navigation item for the view controller based on the json and splitview controller + @objc static func setSplitViewController(for viewController: UIViewController, navigationController: UINavigationController, navigationJSON: [String: Any], leftPanelAccessible: Bool, rightPanelAccessible: Bool, progress: NSNumber?) throws { + guard let navigationItemModel = try MoleculeObjectMapping.shared()?.getMoleculeModelForJSON(navigationJSON) as? (MoleculeModelProtocol & NavigationItemModelProtocol) else { + throw ModelRegistry.Error.decoderOther(message: "Model not a bar model") + } + guard let splitView = MVMCoreUISplitViewController.main(), + navigationController == splitView.navigationController, + navigationController.topViewController == viewController else { + NavigationController.set(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController) + return + } + let progress = progress?.floatValue + splitView.set(for: viewController, navigationController: navigationController, navigationItemModel: navigationItemModel, leftPanelAccessible: leftPanelAccessible, rightPanelAccessible: rightPanelAccessible, progress: progress) + } +} diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h index 4d6b2cff..c48c9e8c 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h @@ -67,10 +67,10 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { #pragma mark - Panel Functions // Sets if the left panel accessible for the view controller. Will show or hide the button. -- (void)setLeftPanelIsAccessible:(BOOL)leftPanelIsAccessible forViewController:(nonnull UIViewController *)viewController; +- (void)setLeftPanelIsAccessible:(BOOL)leftPanelIsAccessible forViewController:(nonnull UIViewController *)viewController updateNavigationButtons:(BOOL)updateNavigationButtons; // Sets if the right panel accessible for the view controller. Will show or hide the button. -- (void)setRightPanelIsAccessible:(BOOL)rightPanelIsAccessible forViewController:(nonnull UIViewController *)viewController; +- (void)setRightPanelIsAccessible:(BOOL)rightPanelIsAccessible forViewController:(nonnull UIViewController *)viewController updateNavigationButtons:(BOOL)updateNavigationButtons; - (void)hideLeftPanelIfNeededAnimated:(BOOL)animated; - (void)showLeftPanelAnimated:(BOOL)animated; @@ -94,6 +94,12 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { /// Updates the panels that are used. - (void)setupPanels; +/// Returns if the left panel is staying extended (usually do to screen size threshold) +- (BOOL)leftPanelStaysExtended; + +/// Returns if the right panel is staying extended (usually do to screen size threshold) +- (BOOL)rightPanelStaysExtended; + #pragma mark - Bottom Progress Bar - (void)setBottomProgressBarProgress:(float)progress; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index fe8036d2..2a98a418 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -110,11 +110,11 @@ CGFloat const PanelAnimationDuration = 0.2; } - (nullable NSArray *)additionalLeftButtonsForViewController:(nonnull UIViewController *)viewController { - return viewController.navigationItem.leftBarButtonItems; + return nil; } - (nullable NSArray *)additionalRightButtonsForViewController:(nonnull UIViewController *)viewController { - return viewController.navigationItem.rightBarButtonItems; + return nil; } - (CGFloat)leftPanelExtendedWidth { @@ -146,7 +146,7 @@ CGFloat const PanelAnimationDuration = 0.2; } - (nullable UIImage *)imageForBackButton { - return [MVMCoreUIUtility imageNamed:@"back"]; + return [MVMCoreUIUtility imageNamed:@"nav_back"]; } #pragma mark - Button Presses @@ -234,19 +234,27 @@ CGFloat const PanelAnimationDuration = 0.2; } } +- (BOOL)leftPanelStaysExtended { + MFNumberOfDrawers numberOfDrawers = [self numberOfDrawersShouldShow:self.transitionWidth]; + return [self shouldExtendLeftPanel:numberOfDrawers] && (numberOfDrawers != MFOneDrawer || self.explictlyShowingPanel != self.rightPanel); +} + - (void)setLeftNavigationItemForViewController:(UIViewController * _Nonnull)viewController accessible:(BOOL)accessible extended:(BOOL)extended { NSMutableArray *leftBarButtonItems = [NSMutableArray array]; + if ([viewController.navigationController.viewControllers count] > 1) { + [leftBarButtonItems addObject:self.backButton]; + } + if ((accessible && !extended) && self.leftPanelButton) { + [leftBarButtonItems addObject:self.leftPanelButton]; + } NSArray *extraButtons = [self additionalLeftButtonsForViewController:viewController]; if (extraButtons) { [leftBarButtonItems addObjectsFromArray:extraButtons]; } - if ((accessible && !extended) && self.leftPanelButton && ![extraButtons containsObject:self.leftPanelButton]) { - [leftBarButtonItems addObject:self.leftPanelButton]; - } [viewController.navigationItem setLeftBarButtonItems:(leftBarButtonItems.count > 0 ? leftBarButtonItems : nil) animated:!DisableAnimations]; } -- (void)setLeftPanelIsAccessible:(BOOL)leftPanelIsAccessible forViewController:(UIViewController *)viewController { +- (void)setLeftPanelIsAccessible:(BOOL)leftPanelIsAccessible forViewController:(UIViewController *)viewController updateNavigationButtons:(BOOL)updateNavigationButtons { if ([self.leftPanel respondsToSelector:@selector(panelAvailable)]) { self.leftPanelIsAccessible = leftPanelIsAccessible && [self.leftPanel panelAvailable]; } else { @@ -262,8 +270,7 @@ CGFloat const PanelAnimationDuration = 0.2; } else { // Determine if we should show the panel (extended based on width or from explicit action). - MFNumberOfDrawers numberOfDrawers = [self numberOfDrawersShouldShow:self.transitionWidth]; - extended = [self shouldExtendLeftPanel:numberOfDrawers] && (numberOfDrawers != MFOneDrawer || self.explictlyShowingPanel != self.rightPanel); + extended = [self leftPanelStaysExtended]; if (extended || self.explictlyShowingPanel == self.leftPanel) { [self showLeftPanelAnimated:NO explict:NO]; } @@ -272,7 +279,9 @@ CGFloat const PanelAnimationDuration = 0.2; [self.leftPanel resetIconToDefault]; } } - [self setLeftNavigationItemForViewController:viewController accessible:self.leftPanelIsAccessible extended:extended]; + if (updateNavigationButtons) { + [self setLeftNavigationItemForViewController:viewController accessible:self.leftPanelIsAccessible extended:extended]; + } }]; } @@ -407,10 +416,10 @@ CGFloat const PanelAnimationDuration = 0.2; - (void)setRightNavigationItemForViewController:(UIViewController * _Nonnull)viewController accessible:(BOOL)accessible extended:(BOOL)extended { NSMutableArray *navigationItems = [[NSMutableArray alloc] init]; - NSArray *extraButtons = [self additionalRightButtonsForViewController:viewController]; - if ((accessible && !extended) && self.rightPanelButton && ![extraButtons containsObject:self.rightPanelButton]) { + if ((accessible && !extended) && self.rightPanelButton) { [navigationItems addObject:self.rightPanelButton]; } + NSArray *extraButtons = [self additionalRightButtonsForViewController:viewController]; if (extraButtons) { [navigationItems addObjectsFromArray:extraButtons]; } @@ -440,7 +449,12 @@ CGFloat const PanelAnimationDuration = 0.2; } } -- (void)setRightPanelIsAccessible:(BOOL)rightPanelIsAccessible forViewController:(UIViewController *)viewController { +- (BOOL)rightPanelStaysExtended { + MFNumberOfDrawers numberOfDrawers = [self numberOfDrawersShouldShow:self.transitionWidth]; + return [self shouldExtendRightPanel:numberOfDrawers] && (numberOfDrawers != MFOneDrawer || self.explictlyShowingPanel != self.leftPanel); +} + +- (void)setRightPanelIsAccessible:(BOOL)rightPanelIsAccessible forViewController:(UIViewController *)viewController updateNavigationButtons:(BOOL)updateNavigationButtons { if ([self.rightPanel respondsToSelector:@selector(panelAvailable)]) { self.rightPanelIsAccessible = rightPanelIsAccessible && [self.rightPanel panelAvailable]; @@ -458,8 +472,7 @@ CGFloat const PanelAnimationDuration = 0.2; } else { // Determine if we should show the right panel (extended based on width or from explicit action). - MFNumberOfDrawers numberOfDrawers = [self numberOfDrawersShouldShow:self.transitionWidth]; - extended = [self shouldExtendRightPanel:numberOfDrawers] && (numberOfDrawers != MFOneDrawer || self.explictlyShowingPanel != self.leftPanel); + extended = [self rightPanelStaysExtended]; if (extended || self.explictlyShowingPanel == self.rightPanel) { [self showRightPanelAnimated:NO explict:NO]; } @@ -468,7 +481,10 @@ CGFloat const PanelAnimationDuration = 0.2; [self.rightPanel resetIconToDefault]; } } - [self setRightNavigationItemForViewController:viewController accessible:rightPanelIsAccessible extended:extended]; + + if (updateNavigationButtons) { + [self setRightNavigationItemForViewController:viewController accessible:rightPanelIsAccessible extended:extended]; + } }]; } @@ -918,7 +934,7 @@ CGFloat const PanelAnimationDuration = 0.2; self.extendedDrawers = MFExtendedDrawerLeft | MFExtendedDrawerRight; self.prioritizedExtendedPanel = MFExtendedDrawerLeft; - self.view.backgroundColor = [UIColor blackColor]; + self.view.backgroundColor = [UIColor whiteColor]; } - (void)viewDidLayoutSubviews { @@ -974,11 +990,15 @@ CGFloat const PanelAnimationDuration = 0.2; } - (void)resetDrawers { - [self setLeftPanelIsAccessible:self.leftPanelIsAccessible forViewController:self.navigationItemViewController]; - [self setRightPanelIsAccessible:self.rightPanelIsAccessible forViewController:self.navigationItemViewController]; - - [self.view setNeedsLayout]; - [self.view layoutIfNeeded]; + if ([self.navigationItemViewController respondsToSelector:@selector(splitViewDidReset)]) { + [((UIViewController *)self.navigationItemViewController) splitViewDidReset]; + } else { + [self setLeftPanelIsAccessible:self.leftPanelIsAccessible forViewController:self.navigationItemViewController updateNavigationButtons:YES]; + [self setRightPanelIsAccessible:self.rightPanelIsAccessible forViewController:self.navigationItemViewController updateNavigationButtons:YES]; + + [self.view setNeedsLayout]; + [self.view layoutIfNeeded]; + } } - (UIStatusBarStyle)preferredStatusBarStyle { @@ -1069,6 +1089,7 @@ CGFloat const PanelAnimationDuration = 0.2; if ([self.rightPanelButton respondsToSelector:@selector(setIconColor:)]) { [((UIBarButtonItem *)self.rightPanelButton) setIconColor:color]; } + [self.backButton setTintColor:color]; } @end diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back.png b/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back.png deleted file mode 100644 index 3d2734b6..00000000 Binary files a/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back.png and /dev/null differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back@2x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back@2x.png deleted file mode 100644 index 1d64be8b..00000000 Binary files a/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back@2x.png and /dev/null differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back@3x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back@3x.png deleted file mode 100644 index 147e2c6a..00000000 Binary files a/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/back@3x.png and /dev/null differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack.png b/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack.png deleted file mode 100644 index 5f31bd28..00000000 Binary files a/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack.png and /dev/null differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack@2x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack@2x.png deleted file mode 100644 index d966cb74..00000000 Binary files a/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack@2x.png and /dev/null differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack@3x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack@3x.png deleted file mode 100644 index 59847565..00000000 Binary files a/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/closeXBlack@3x.png and /dev/null differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/Contents.json b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/Contents.json similarity index 70% rename from MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/Contents.json rename to MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/Contents.json index 3bad3d0c..65a64dfd 100644 --- a/MVMCoreUI/SupportingFiles/Media.xcassets/back.imageset/Contents.json +++ b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/Contents.json @@ -2,17 +2,17 @@ "images" : [ { "idiom" : "universal", - "filename" : "back.png", + "filename" : "nav_back.png", "scale" : "1x" }, { "idiom" : "universal", - "filename" : "back@2x.png", + "filename" : "nav_back@2x.png", "scale" : "2x" }, { "idiom" : "universal", - "filename" : "back@3x.png", + "filename" : "nav_back@3x.png", "scale" : "3x" } ], diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back.png b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back.png new file mode 100644 index 00000000..2592ddda Binary files /dev/null and b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back.png differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back@2x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back@2x.png new file mode 100644 index 00000000..077a411d Binary files /dev/null and b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back@2x.png differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back@3x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back@3x.png new file mode 100644 index 00000000..f2ac8c73 Binary files /dev/null and b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_back.imageset/nav_back@3x.png differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/Contents.json b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/Contents.json similarity index 69% rename from MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/Contents.json rename to MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/Contents.json index d7771f8a..d328ed8e 100644 --- a/MVMCoreUI/SupportingFiles/Media.xcassets/closeXBlack.imageset/Contents.json +++ b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/Contents.json @@ -2,17 +2,17 @@ "images" : [ { "idiom" : "universal", - "filename" : "closeXBlack.png", + "filename" : "nav_close.png", "scale" : "1x" }, { "idiom" : "universal", - "filename" : "closeXBlack@2x.png", + "filename" : "nav_close@2x.png", "scale" : "2x" }, { "idiom" : "universal", - "filename" : "closeXBlack@3x.png", + "filename" : "nav_close@3x.png", "scale" : "3x" } ], diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close.png b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close.png new file mode 100644 index 00000000..e04a9996 Binary files /dev/null and b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close.png differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close@2x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close@2x.png new file mode 100644 index 00000000..f8876428 Binary files /dev/null and b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close@2x.png differ diff --git a/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close@3x.png b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close@3x.png new file mode 100644 index 00000000..b2e9d7df Binary files /dev/null and b/MVMCoreUI/SupportingFiles/Media.xcassets/nav_close.imageset/nav_close@3x.png differ diff --git a/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift b/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift index cf1603bb..d1173250 100644 --- a/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift +++ b/MVMCoreUI/Utility/MVMCoreUICommonViewsUtility+Extension.swift @@ -13,7 +13,7 @@ public extension MVMCoreUICommonViewsUtility { /// Add the close button (x) to the top right of the view. TODO: update this logic. @objc static func addCloseButton(to view: UIView, action: @escaping ButtonAction, centeredVertically: Bool = false) -> Button { let button = Button() - if let image = MVMCoreUIUtility.imageNamed("closeXBlack")?.withRenderingMode(.alwaysTemplate) { + if let image = MVMCoreUIUtility.imageNamed("nav_close")?.withRenderingMode(.alwaysTemplate) { button.setImage(image, for: .normal) } button.tintColor = .black