From 1a60d36e2d4094364a17d2cd489f8e6a71a3eacb Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 3 Dec 2020 14:22:06 -0500 Subject: [PATCH] formatting updates. Adding identifier for easier testing. --- MVMCoreUI.xcodeproj/project.pbxproj | 2 +- .../Atomic/Atoms/Buttons/ButtonModel.swift | 4 ++ .../Atomic/Atoms/Buttons/CaretLink.swift | 13 ++----- .../Atomic/Atoms/Buttons/CaretLinkModel.swift | 4 ++ .../Atomic/Atoms/Buttons/PillButton.swift | 10 ++--- .../Atomic/Atoms/Views/DashLineModel.swift | 4 ++ .../Atomic/Atoms/Views/MultiProgress.swift | 7 ++-- .../HorizontalCombinationViews/TabBar.swift | 14 ++----- ...reUITopAlertExpandableView+Extension.swift | 7 +++- .../MVMCoreUITopAlertMainView+Extension.swift | 11 +++++- .../TopNotification/NotificationModel.swift | 39 ++++++++++++++----- MVMCoreUI/Atomic/Organisms/Stack.swift | 2 +- MVMCoreUI/BaseClasses/BarButtonItem.swift | 3 +- MVMCoreUI/BaseClasses/Button.swift | 18 ++++----- MVMCoreUI/BaseClasses/Control.swift | 17 ++++---- MVMCoreUI/BaseClasses/ImageView.swift | 25 ++++++------ .../BaseClasses/SectionHeaderFooterView.swift | 17 ++++---- MVMCoreUI/BaseClasses/TableView.swift | 2 +- MVMCoreUI/BaseClasses/TextField.swift | 4 ++ MVMCoreUI/BaseClasses/TextView.swift | 4 +- MVMCoreUI/BaseClasses/View.swift | 4 +- 21 files changed, 122 insertions(+), 89 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index f090183b..e97e3b20 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -2154,6 +2154,7 @@ D2B18B7D236090D500A9AEDC /* BaseClasses */ = { isa = PBXGroup; children = ( + 0A5D59C323AD488600EFD9E9 /* Protocols */, 0A6682B3243769C700AD3CA1 /* TextView.swift */, C003506023AA94CD00B6AC29 /* Button.swift */, D2B18B7E2360913400A9AEDC /* Control.swift */, @@ -2164,7 +2165,6 @@ BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */, D21B7F70243BAC1600051ABF /* CollectionViewCell.swift */, D264FAA92440F97600D98315 /* CollectionView.swift */, - 0A5D59C323AD488600EFD9E9 /* Protocols */, 0A7918F423F5E7EA00772FF4 /* ImageView.swift */, D272F5F82473163100BD1A8F /* BarButtonItem.swift */, D2EC7BDC2527B83700F540AF /* SectionHeaderFooterView.swift */, diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index 0881af71..9662fc48 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -18,6 +18,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW public static var identifier: String = "button" public var backgroundColor: Color? + public var accessibilityIdentifier: String? public var title: String public var action: ActionModelProtocol public var enabled: Bool = true @@ -172,6 +173,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor + case accessibilityIdentifier case title case inverted case action @@ -195,6 +197,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW 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.decode(String.self, forKey: .title) action = try typeContainer.decodeModel(codingKey: .action) @@ -252,6 +255,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW try container.encode(inverted, forKey: .inverted) try container.encodeModel(action, forKey: .action) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) try container.encodeIfPresent(enabledFillColor, forKey: .fillColor) try container.encodeIfPresent(enabledTextColor, forKey: .textColor) try container.encodeIfPresent(enabledBorderColor, forKey: .borderColor) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift index b0822480..5ae68241 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift @@ -127,7 +127,6 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { } public func updateCaretSpacing(_ spacing: CGFloat) { - caretSpacingConstraint?.constant = spacing } @@ -151,15 +150,9 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { setTitle(model.title, for: .normal) } - public func needsToBeConstrained() -> Bool { - return true - } + public func needsToBeConstrained() -> Bool { true } - open func horizontalAlignment() -> UIStackView.Alignment { - return .leading - } + open func horizontalAlignment() -> UIStackView.Alignment { .leading } - open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return 10.5 - } + open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { 10.5 } } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLinkModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLinkModel.swift index a37baeca..25d0a539 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLinkModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLinkModel.swift @@ -17,6 +17,7 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea public static var identifier: String = "caretLink" public var backgroundColor: Color? + public var accessibilityIdentifier: String? public var title: String public var action: ActionModelProtocol public var enabledColor: Color = Color(uiColor: .mvmBlack) @@ -41,6 +42,7 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea private enum CodingKeys: String, CodingKey { case backgroundColor + case accessibilityIdentifier case title case action case enabledColor_inverted @@ -60,6 +62,7 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea 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.decode(String.self, forKey: .title) if let enabledColor_inverted = try typeContainer.decodeIfPresent(Color.self, forKey: .enabledColor_inverted) { @@ -94,6 +97,7 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea try container.encode(moleculeName, forKey: .moleculeName) try container.encode(title, forKey: .title) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) try container.encodeModel(action, forKey: .action) try container.encode(enabled, forKey: .enabledColor) try container.encodeIfPresent(disabledColor, forKey: .disabledColor) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index f5a7ed44..b89d034d 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -18,7 +18,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { var size = MVMCoreUIUtility.getWidth() var buttonModel: ButtonModel? { - get { return model as? ButtonModel } + get { model as? ButtonModel } } /// Need to re-style on set. @@ -47,12 +47,12 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { //-------------------------------------------------- public var enabledTitleColor: UIColor? { - get { return titleColor(for: .normal) } + get { titleColor(for: .normal) } set { setTitleColor(newValue, for: .normal) } } public var disabledTitleColor: UIColor? { - get { return titleColor(for: .disabled) } + get { titleColor(for: .disabled) } set { setTitleColor(newValue, for: .disabled) } } @@ -228,9 +228,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { // MARK: - MVMCoreUIViewConstrainingProtocol //-------------------------------------------------- - open func horizontalAlignment() -> UIStackView.Alignment { - return .center - } + open func horizontalAlignment() -> UIStackView.Alignment { .center } public func enableField(_ enable: Bool) { isEnabled = enable diff --git a/MVMCoreUI/Atomic/Atoms/Views/DashLineModel.swift b/MVMCoreUI/Atomic/Atoms/Views/DashLineModel.swift index 523d83a6..c4375d53 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/DashLineModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/DashLineModel.swift @@ -16,6 +16,7 @@ import Foundation public static var identifier: String = "dashLine" public var backgroundColor: Color? + public var accessibilityIdentifier: String? public var dashColor: Color = Color(uiColor: .mvmCoolGray3) public var dashColor_inverted: Color = Color(uiColor: .mvmWhite) public var isHidden: Bool = false @@ -36,6 +37,7 @@ import Foundation private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor + case accessibilityIdentifier case dashColor_inverted case dashColor case isHidden @@ -57,6 +59,7 @@ import Foundation } backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier) if let isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden) { self.isHidden = isHidden @@ -69,5 +72,6 @@ import Foundation try container.encode(dashColor, forKey: .dashColor) try container.encode(isHidden, forKey: .isHidden) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/MultiProgress.swift b/MVMCoreUI/Atomic/Atoms/Views/MultiProgress.swift index 945229c7..2894ea1c 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/MultiProgress.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/MultiProgress.swift @@ -17,7 +17,7 @@ import UIKit private let stack = Stack() var multiProgressModel: MultiProgressBarModel? { - get { return model as? MultiProgressBarModel } + get { model as? MultiProgressBarModel } } var roundedCorners: Bool = false { @@ -85,7 +85,7 @@ import UIKit //-------------------------------------------------- /// Creates the bars - open func set(with progressList: Array, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + open func set(with progressList: [SingleProgressBarModel], _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { stack.removeAllItemViews() guard let stackModel = stack.stackModel else { return } @@ -103,7 +103,6 @@ import UIKit stack.set(with: stackModel, delegateObject, additionalData) } - public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) @@ -115,6 +114,6 @@ import UIKit } public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return (model as? MultiProgressBarModel)?.thickness ?? 8 + (model as? MultiProgressBarModel)?.thickness ?? 8 } } diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift index 1ee7ee71..87e71631 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TabBar.swift @@ -6,7 +6,6 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -import Foundation @objcMembers open class TabBar: UITabBar, MoleculeViewProtocol, TabBarProtocol, UITabBarDelegate { @@ -15,9 +14,7 @@ import Foundation public let line = Line() required public init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - guard let model = model as? TabBarModel else { - fatalError("model is not TabBarModel") - } + guard let model = model as? TabBarModel else { fatalError("model is not TabBarModel") } self.model = model super.init(frame: .zero) @@ -32,7 +29,7 @@ import Foundation fatalError("init(coder:) has not been implemented") } - open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let model = model as? TabBarModel else { return } self.model = model @@ -100,10 +97,7 @@ import Foundation }) } - public func currentTabIndex() -> Int { - return model.selectedTab - } + public func currentTabIndex() -> Int { model.selectedTab } } -extension UITabBarItem: MFButtonProtocol { -} +extension UITabBarItem: MFButtonProtocol { } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/MVMCoreUITopAlertExpandableView+Extension.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/MVMCoreUITopAlertExpandableView+Extension.swift index e28bf057..e1af54e3 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/MVMCoreUITopAlertExpandableView+Extension.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/MVMCoreUITopAlertExpandableView+Extension.swift @@ -6,11 +6,10 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -import Foundation extension MVMCoreUITopAlertExpandableView: MoleculeViewProtocol { - public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { defaultSetup() guard let model = model as? CollapsableNotificationModel else { return } backgroundColor = model.backgroundColor?.uiColor ?? .mvmGreen @@ -30,6 +29,10 @@ extension MVMCoreUITopAlertExpandableView: MoleculeViewProtocol { MVMCoreUITopAlertBaseView.addAction(to: button, actionMap: topActionMap, additionalData: nil) shortView?.label?.accessibilityTraits = .button } + + if let accessibilityIdentifier = model.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier + } } } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/MVMCoreUITopAlertMainView+Extension.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/MVMCoreUITopAlertMainView+Extension.swift index 157d6522..c6109372 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/MVMCoreUITopAlertMainView+Extension.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/MVMCoreUITopAlertMainView+Extension.swift @@ -6,17 +6,24 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -import Foundation extension MVMCoreUITopAlertMainView: MoleculeViewProtocol { - public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + + public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { defaultSetup() guard let model = model as? NotificationModel else { return } + backgroundColor = model.backgroundColor?.uiColor ?? .mvmGreen var actionMap = model.button?.action.toJSON() + if let title = model.button?.title { actionMap?.updateValue(title, forKey: KeyTitle) } + + if let accessibilityIdentifier = model.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier + } + setupCloseButton(model.closeButton != nil, animationDelegate: MVMCoreUITopAlertView.sharedGlobal()?.animationDelegate) setup(withMessage: model.headline.text, subMessage: model.body?.text, color: model.headline.textColor?.uiColor ?? .white, actionMap: actionMap, additionalData: nil) } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift index 70ff00bb..3d02cecd 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationModel.swift @@ -6,52 +6,72 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -import Foundation open class NotificationModel: MoleculeModelProtocol { - public class var identifier: String { - return "notification" - } + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public class var identifier: String { "notification" } + public var accessibilityIdentifier: String? public var backgroundColor: Color? public var headline: LabelModel public var body: LabelModel? public var button: ButtonModel? public var closeButton: NotificationXButtonModel? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(with headline: LabelModel) { self.headline = headline } + //-------------------------------------------------- + // MARK: - Default + //-------------------------------------------------- + open func setDefault() { if backgroundColor == nil { - backgroundColor = Color(uiColor: .mvmGreen()) + backgroundColor = Color(uiColor: .mvmGreen) } if headline.textColor == nil { - headline.textColor = Color(uiColor: .white) + headline.textColor = Color(uiColor: .mvmWhite) } if body?.textColor == nil { - body?.textColor = Color(uiColor: .white) + body?.textColor = Color(uiColor: .mvmWhite) } if button?.style == nil { button?.style = .secondary } button?.size = .tiny - button?.enabledTextColor = Color(uiColor: .white) - button?.enabledBorderColor = Color(uiColor: .white) + button?.enabledTextColor = Color(uiColor: .mvmWhite) + button?.enabledBorderColor = Color(uiColor: .mvmWhite) } + //-------------------------------------------------- + // MARK: - Coding Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor + case accessibilityIdentifier case headline case body case button case closeButton } + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + 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) headline = try typeContainer.decode(LabelModel.self, forKey: .headline) body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body) button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button) @@ -63,6 +83,7 @@ open class NotificationModel: MoleculeModelProtocol { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) try container.encode(headline, forKey: .headline) try container.encodeIfPresent(body, forKey: .body) try container.encodeIfPresent(button, forKey: .button) diff --git a/MVMCoreUI/Atomic/Organisms/Stack.swift b/MVMCoreUI/Atomic/Organisms/Stack.swift index d112af5e..29646f2e 100644 --- a/MVMCoreUI/Atomic/Organisms/Stack.swift +++ b/MVMCoreUI/Atomic/Organisms/Stack.swift @@ -16,7 +16,7 @@ open class Stack: Container where T: (StackModelProtocol & MoleculeModelProto open var stackItems: [UIView] = [] open var stackModel: T? { - get { return model as? T } + get { model as? T } } //-------------------------------------------------- diff --git a/MVMCoreUI/BaseClasses/BarButtonItem.swift b/MVMCoreUI/BaseClasses/BarButtonItem.swift index 93eb63a3..d41fd57f 100644 --- a/MVMCoreUI/BaseClasses/BarButtonItem.swift +++ b/MVMCoreUI/BaseClasses/BarButtonItem.swift @@ -8,6 +8,7 @@ public typealias BarButtonAction = (BarButtonItem) -> () + @objc class ActionDelegate: NSObject { var buttonAction: BarButtonAction? @objc func callActionBlock(_ sender: BarButtonItem) { @@ -16,7 +17,6 @@ public typealias BarButtonAction = (BarButtonItem) -> () } @objcMembers open class BarButtonItem: UIBarButtonItem, MFButtonProtocol { - //-------------------------------------------------- // MARK: - Delegate //-------------------------------------------------- @@ -43,4 +43,3 @@ public typealias BarButtonAction = (BarButtonItem) -> () } } } - diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index e06a5cb3..3387913e 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -65,7 +65,7 @@ public typealias ButtonAction = (Button) -> () /// Adds a block to be performed for the given event. open func addActionBlock(event: Event, _ buttonBlock: @escaping ButtonAction) { self.buttonAction = buttonBlock - addTarget(self, action: #selector(callActionBlock(_:)), for: event) + addTarget(self, action: #selector(callActionBlock), for: event) } @objc func callActionBlock(_ sender: Button) { @@ -103,6 +103,10 @@ public typealias ButtonAction = (Button) -> () self.backgroundColor = backgroundColor.uiColor } + if let accessibilityIdentifier = model.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier + } + if let model = model as? EnableableModelProtocol { isEnabled = model.enabled } @@ -119,16 +123,12 @@ public typealias ButtonAction = (Button) -> () // MARK: Overridables // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead. open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { - return model.moleculeName + model.moleculeName } - open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return nil - } + open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { nil } - open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { - return nil - } + open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { nil } //-------------------------------------------------- // MARK: - Accessibility @@ -160,6 +160,6 @@ extension Button: MVMCoreViewProtocol { extension Button: AppleGuidelinesProtocol { override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - return Self.acceptablyOutsideBounds(point: point, bounds: bounds) + Self.acceptablyOutsideBounds(point: point, bounds: bounds) } } diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index 57c13e9e..a8fde2e5 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -51,9 +51,14 @@ import UIKit // MARK:- MoleculeViewProtocol open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { self.model = model + if let backgroundColor = model.backgroundColor { self.backgroundColor = backgroundColor.uiColor } + + if let accessibilityIdentifier = model.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier + } } open func reset() { @@ -63,22 +68,18 @@ import UIKit // MARK: Overridables // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead. open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { - return model.moleculeName + model.moleculeName } - open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return nil - } + open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { nil } - open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { - return nil - } + open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { nil } } // MARK: - AppleGuidelinesProtocol extension Control: AppleGuidelinesProtocol { override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - return Self.acceptablyOutsideBounds(point: point, bounds: bounds) + Self.acceptablyOutsideBounds(point: point, bounds: bounds) } } diff --git a/MVMCoreUI/BaseClasses/ImageView.swift b/MVMCoreUI/BaseClasses/ImageView.swift index 271ee615..9aa003b8 100644 --- a/MVMCoreUI/BaseClasses/ImageView.swift +++ b/MVMCoreUI/BaseClasses/ImageView.swift @@ -53,33 +53,35 @@ open class ImageView: UIImageView, MoleculeViewProtocol { } public func reset() { - backgroundColor = .clear - } - + backgroundColor = .clear + } + public func setAsMolecule() { } //-------------------------------------------------- // MARK: - ModelMoleculeViewProtocol //-------------------------------------------------- - public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + self.model = model + if let backgroundColor = model.backgroundColor { self.backgroundColor = backgroundColor.uiColor } + + if let accessibilityIdentifier = model.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier + } } open class func nameForReuse(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { - return model?.moleculeName + model?.moleculeName } - open class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return nil - } + open class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { nil } - open class func requiredModules(_ molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { - return nil - } + open class func requiredModules(_ molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { nil } } // MARK:- MVMCoreViewProtocol @@ -94,4 +96,3 @@ extension ImageView: MVMCoreViewProtocol { MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0) } } - diff --git a/MVMCoreUI/BaseClasses/SectionHeaderFooterView.swift b/MVMCoreUI/BaseClasses/SectionHeaderFooterView.swift index b4b7f8eb..ab85e96f 100644 --- a/MVMCoreUI/BaseClasses/SectionHeaderFooterView.swift +++ b/MVMCoreUI/BaseClasses/SectionHeaderFooterView.swift @@ -6,7 +6,6 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -import Foundation @objcMembers open class SectionHeaderFooterView: UITableViewHeaderFooterView, MoleculeViewProtocol { //-------------------------------------------------- @@ -43,10 +42,16 @@ import Foundation //-------------------------------------------------- open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + self.model = model + if let backgroundColor = model.backgroundColor { contentView.backgroundColor = backgroundColor.uiColor } + + if let accessibilityIdentifier = model.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier + } } open func reset() { @@ -56,16 +61,12 @@ import Foundation // MARK: Overridables // Base classes need to implement these functions otherwise swift won't respect the subclass functions and use the ones in the protocol extension instead. open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { - return model.moleculeName + model.moleculeName } - open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return nil - } + open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { nil } - open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { - return nil - } + open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { nil } } // MARK:- MVMCoreViewProtocol diff --git a/MVMCoreUI/BaseClasses/TableView.swift b/MVMCoreUI/BaseClasses/TableView.swift index 9fb07ac7..bc899084 100644 --- a/MVMCoreUI/BaseClasses/TableView.swift +++ b/MVMCoreUI/BaseClasses/TableView.swift @@ -11,7 +11,7 @@ import Foundation @objcMembers open class TableView: UITableView { /// A block that gets called on tableview frame changes - public var frameChangeAction: (() -> Void)? + public var frameChangeAction: (() -> ())? private var previousFrame = CGRect.zero diff --git a/MVMCoreUI/BaseClasses/TextField.swift b/MVMCoreUI/BaseClasses/TextField.swift index 8795054b..9174426d 100644 --- a/MVMCoreUI/BaseClasses/TextField.swift +++ b/MVMCoreUI/BaseClasses/TextField.swift @@ -93,6 +93,10 @@ extension TextField: MoleculeViewProtocol { if let color = model.backgroundColor?.uiColor { backgroundColor = color } + + if let accessibilityIdentifier = model.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier + } } open func reset() { diff --git a/MVMCoreUI/BaseClasses/TextView.swift b/MVMCoreUI/BaseClasses/TextView.swift index 2c609e02..8d09ca35 100644 --- a/MVMCoreUI/BaseClasses/TextView.swift +++ b/MVMCoreUI/BaseClasses/TextView.swift @@ -106,8 +106,8 @@ import UIKit open func reset() { - fontStyle = Styler.Font.RegularBodyLarge - placeholderFontStyle = Styler.Font.RegularMicro + fontStyle = .RegularBodyLarge + placeholderFontStyle = .RegularMicro placeholderTextColor = .mvmCoolGray3 textColor = .mvmBlack isEnabled = true diff --git a/MVMCoreUI/BaseClasses/View.swift b/MVMCoreUI/BaseClasses/View.swift index 688fe28c..deb1bdfa 100644 --- a/MVMCoreUI/BaseClasses/View.swift +++ b/MVMCoreUI/BaseClasses/View.swift @@ -59,8 +59,8 @@ import UIKit self.backgroundColor = backgroundColor.uiColor } - if let identifier = model.accessibilityIdentifier { - accessibilityIdentifier = identifier + if let accessibilityIdentifier = model.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier } }