From 1e4963f58e1f6c1cf2d15e6b52f37a1ad44675ce Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 23 Dec 2020 12:20:38 -0500 Subject: [PATCH] updates --- MVMCoreUI.xcodeproj/project.pbxproj | 4 +++ .../FormFields/TextFields/EntryField.swift | 5 +-- .../TextFields/EntryFieldModel.swift | 4 +++ .../Atomic/Extensions/UIView+Extension.swift | 35 +++++++++++++++++++ .../Templates/MoleculeListTemplate.swift | 8 ----- .../BaseControllers/ViewController.swift | 6 ++++ 6 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 MVMCoreUI/Atomic/Extensions/UIView+Extension.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 3fce1455..a9c1a769 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -98,6 +98,7 @@ 0A7EF86523D8AFFF00B2AAD1 /* ItemDropdownEntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7EF86423D8AFFF00B2AAD1 /* ItemDropdownEntryFieldModel.swift */; }; 0A7EF86723D8B0AE00B2AAD1 /* DateDropdownEntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7EF86623D8B0AE00B2AAD1 /* DateDropdownEntryFieldModel.swift */; }; 0A849EFE246F1775009F277F /* RuleEqualsIgnoreCaseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A849EFD246F1775009F277F /* RuleEqualsIgnoreCaseModel.swift */; }; + 0A9394892593AC9D00D2791F /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9394882593AC9D00D2791F /* UIView+Extension.swift */; }; 0A9D091D2433796500D2E6C0 /* BarsCarouselIndicatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9D09172433796500D2E6C0 /* BarsCarouselIndicatorModel.swift */; }; 0A9D091E2433796500D2E6C0 /* NumericCarouselIndicatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9D09182433796500D2E6C0 /* NumericCarouselIndicatorModel.swift */; }; 0A9D091F2433796500D2E6C0 /* NumericIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9D09192433796500D2E6C0 /* NumericIndicatorView.swift */; }; @@ -641,6 +642,7 @@ 0A7EF86623D8B0AE00B2AAD1 /* DateDropdownEntryFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryFieldModel.swift; sourceTree = ""; }; 0A8321AE2355FE9500CB7F00 /* DigitBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DigitBox.swift; sourceTree = ""; }; 0A849EFD246F1775009F277F /* RuleEqualsIgnoreCaseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleEqualsIgnoreCaseModel.swift; sourceTree = ""; }; + 0A9394882593AC9D00D2791F /* UIView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = ""; }; 0A9D09172433796500D2E6C0 /* BarsCarouselIndicatorModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarsCarouselIndicatorModel.swift; sourceTree = ""; }; 0A9D09182433796500D2E6C0 /* NumericCarouselIndicatorModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumericCarouselIndicatorModel.swift; sourceTree = ""; }; 0A9D09192433796500D2E6C0 /* NumericIndicatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumericIndicatorView.swift; sourceTree = ""; }; @@ -1386,6 +1388,7 @@ 0AB764D224460FA400E7FE72 /* UIPickerView+Extension.swift */, D2ED27E6254B0CE600A1C293 /* UIAlertActionStyle+Codable.swift */, D2ED27E7254B0CE600A1C293 /* UIAlertControllerStyle+Extension.swift */, + 0A9394882593AC9D00D2791F /* UIView+Extension.swift */, ); path = Extensions; sourceTree = ""; @@ -2798,6 +2801,7 @@ 0A21DB83235DFBC500C160A2 /* MdnEntryField.swift in Sources */, 0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */, D28A837D23CCA86A00DFE4FC /* TabsListItemModel.swift in Sources */, + 0A9394892593AC9D00D2791F /* UIView+Extension.swift in Sources */, 0A51F3E32475CB73002E08B6 /* LoadingSpinner.swift in Sources */, BB2FB3BB247E7EBC00DF73CD /* TagCollectionViewCell.swift in Sources */, 012A88C6238DA34000FE3DA1 /* ModuleMoleculeModel.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift index 195fa0b9..3c990eef 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryField.swift @@ -78,8 +78,8 @@ import UIKit } } - var errorMessage: String { - (entryFieldModel?.dynamicErrorMessage != nil ? entryFieldModel?.dynamicErrorMessage : entryFieldModel?.errorMessage) ?? "" + var errorMessage: String? { + entryFieldModel?.dynamicErrorMessage ?? entryFieldModel?.errorMessage } /// Toggles original or locked UI. @@ -320,6 +320,7 @@ import UIKit feedback = model.feedback isEnabled = model.enabled entryFieldContainer.disableAllBorders = model.hideBorders + accessibilityIdentifier = model.accessibilityIdentifier ?? model.fieldKey if let isLocked = model.locked { self.isLocked = isLocked diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryFieldModel.swift index e5b58733..02affc3d 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryFieldModel.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/EntryFieldModel.swift @@ -19,6 +19,7 @@ import Foundation } public var backgroundColor: Color? + public var accessibilityIdentifier: String? public var title: String? public var feedback: String? public var dynamicErrorMessage: String? @@ -49,6 +50,7 @@ import Foundation private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor + case accessibilityIdentifier case title case enabled case feedback @@ -98,6 +100,7 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier) title = try typeContainer.decodeIfPresent(String.self, forKey: .title) feedback = try typeContainer.decodeIfPresent(String.self, forKey: .feedback) errorMessage = try typeContainer.decodeIfPresent(String.self, forKey: .errorMessage) @@ -119,6 +122,7 @@ import Foundation var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) try container.encodeIfPresent(title, forKey: .title) try container.encodeIfPresent(feedback, forKey: .feedback) try container.encodeIfPresent(text, forKey: .text) diff --git a/MVMCoreUI/Atomic/Extensions/UIView+Extension.swift b/MVMCoreUI/Atomic/Extensions/UIView+Extension.swift new file mode 100644 index 00000000..3878b64a --- /dev/null +++ b/MVMCoreUI/Atomic/Extensions/UIView+Extension.swift @@ -0,0 +1,35 @@ +// +// UIView+Extension.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 12/23/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + + +extension UIView { + + public class func findByAccessibility(identifier: String) -> UIView? { + + guard let window = UIApplication.shared.keyWindow else { return nil } + + func findByID(view: UIView, _ id: String) -> UIView? { + + if view.accessibilityIdentifier == id { + return view + } + + for v in view.subviews { + if let a = findByID(view: v, id) { + return a + } + } + + return nil + } + + return findByID(view: window, identifier) + } +} diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index 41117af4..ba057444 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -156,14 +156,6 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol // MARK: - MoleculeDelegateProtocol //-------------------------------------------------- - public override func handleFieldErrors(_ fieldErrors: [Any]?, loadObject: MVMCoreLoadObject) { - super.handleFieldErrors(fieldErrors, loadObject: loadObject) - - DispatchQueue.main.async { [self] in - tableView.reloadData() - } - } - open override func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) { if let tableView = tableView { diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index b309e370..fa9a1232 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -452,6 +452,12 @@ import UIKit entryFieldModel.dynamicErrorMessage = userError entryFieldModel.isValid = true entryFieldModel.text = "" + + if let view = UIView.findByAccessibility(identifier: fieldKey), let moleculeView = view as? MoleculeViewProtocol { + DispatchQueue.main.async { [self] in + moleculeView.set(with: entryFieldModel, delegateObjectIVar, nil) + } + } } }