From da701bac232512e1f70f0459154abd0771742eb7 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Wed, 3 Apr 2024 18:18:54 +0530 Subject: [PATCH 01/17] Added missing code --- MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift b/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift index 965656a6..2ce1254b 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift @@ -64,9 +64,8 @@ bottomLabelConstraint.isActive = true alignCheckbox(.center) - isAccessibilityElement = true - accessibilityHint = checkbox.accessibilityHint - accessibilityTraits = checkbox.accessibilityTraits + isAccessibilityElement = false + accessibilityElements = [checkbox, label] observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } @@ -139,6 +138,8 @@ open func updateAccessibilityLabel() { checkbox.updateAccessibilityLabel() - accessibilityLabel = [checkbox.accessibilityLabel, label.text].compactMap { $0 }.joined(separator: ",") + if let text = label.text { + checkbox.accessibilityLabel?.append(", \(text)") + } } } From 077ee85dc0be654ceb3edae8aa9ff9e541b8875c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 10 Apr 2024 13:39:45 -0500 Subject: [PATCH 02/17] removed ternary Signed-off-by: Matt Bruce --- MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index e5d1ae73..12c65867 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -36,7 +36,7 @@ open class PillButton: VDS.Button, MVMCoreUIViewConstrainingProtocol, MFButtonPr text = viewModel.title isEnabled = viewModel.enabled size = viewModel.size - use = viewModel.style ?? .primary + use = viewModel.style surface = viewModel.inverted ? .dark : .light if let accessibilityText = viewModel.accessibilityText { accessibilityLabel = accessibilityText From 5fbf076aa703cb6318cdf8662d92ca6f307f66e0 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 10 Apr 2024 13:40:09 -0500 Subject: [PATCH 03/17] refactored NotificationMoleculeView/Model Signed-off-by: Matt Bruce --- .../NotificationMoleculeModel.swift | 102 +++++++------- .../NotificationMoleculeView.swift | 131 +++++++++--------- 2 files changed, 115 insertions(+), 118 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift index 9958b59a..f9387064 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift @@ -5,7 +5,7 @@ // Created by Scott Pfeil on 9/15/20. // Copyright © 2020 Verizon Wireless. All rights reserved. // - +import VDS open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { @@ -21,6 +21,19 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { case error case warning case information + + var toVDSStyle: VDS.Notification.Style { + switch self { + case .success: + .success + case .error: + .error + case .warning: + .warning + case .information: + .info + } + } } //-------------------------------------------------- @@ -33,19 +46,22 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { public var headline: LabelModel public var body: LabelModel? public var button: ButtonModel? - public var closeButton: NotificationXButtonModel? - public var style: NotificationMoleculeModel.Style = .success + public var secondaryButton: ButtonModel? + public var closeButton: ButtonModel? + public var style: Style = .success + public var inverted: Bool = false //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(with headline: LabelModel, style: NotificationMoleculeModel.Style = .success, backgroundColor: Color? = nil, body: LabelModel? = nil, button: ButtonModel? = nil, closeButton: NotificationXButtonModel? = nil) { + public init(with headline: LabelModel, style: NotificationMoleculeModel.Style = .success, backgroundColor: Color? = nil, body: LabelModel? = nil, button: ButtonModel? = nil, secondaryButton: ButtonModel? = nil, closeButton: ButtonModel? = nil) { self.headline = headline self.style = style self.backgroundColor = backgroundColor self.body = body self.button = button + self.secondaryButton = secondaryButton self.closeButton = closeButton super.init() } @@ -55,57 +71,7 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { //-------------------------------------------------- open override func setDefaults() { - useHorizontalMargins = true - useVerticalMargins = true - topPadding = PaddingTwo - bottomPadding = PaddingTwo - if backgroundColor == nil { - switch style { - case .error: - backgroundColor = Color(uiColor: .mvmOrange) - case .warning: - backgroundColor = Color(uiColor: .mvmYellow) - case .information: - backgroundColor = Color(uiColor: .mvmBlue) - default: - backgroundColor = Color(uiColor: .mvmGreen) - } - } - if headline.textColor == nil { - switch style { - case .error, .warning: - headline.textColor = Color(uiColor: .mvmBlack) - default: - headline.textColor = Color(uiColor: .mvmWhite) - } - } - if body?.textColor == nil { - switch style { - case .error, .warning: - body?.textColor = Color(uiColor: .mvmBlack) - default: - body?.textColor = Color(uiColor: .mvmWhite) - } - } - - button?.size = .small - button?.style = .secondary - switch style { - case .error, .warning: - button?.inverted = false - default: - button?.inverted = true - } - - if closeButton?.color == nil { - switch style { - case .error, .warning: - closeButton?.color = Color(uiColor: .mvmBlack) - default: - closeButton?.color = Color(uiColor: .mvmWhite) - } - } } //-------------------------------------------------- @@ -119,7 +85,9 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { case headline case body case button + case secondaryButton case closeButton + case inverted case style } @@ -134,7 +102,9 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { headline = try typeContainer.decode(LabelModel.self, forKey: .headline) body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body) button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button) - closeButton = try typeContainer.decodeIfPresent(NotificationXButtonModel.self, forKey: .closeButton) + secondaryButton = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .secondaryButton) + closeButton = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .closeButton) + inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) ?? false if let style = try typeContainer.decodeIfPresent(NotificationMoleculeModel.Style.self, forKey: .style) { self.style = style } @@ -149,7 +119,29 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { try container.encode(headline, forKey: .headline) try container.encodeIfPresent(body, forKey: .body) try container.encodeIfPresent(button, forKey: .button) + try container.encodeIfPresent(secondaryButton, forKey: .secondaryButton) try container.encodeIfPresent(closeButton, forKey: .closeButton) try container.encode(style, forKey: .style) } } + +extension NotificationMoleculeModel { + public var surface: Surface { + inverted ? .dark : .light + } +} + +extension ButtonModel { + public func toNotficationButtonModel(delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) -> VDS.Notification.ButtonModel { + return .init(text: title, onClick: { [weak self] _ in + guard let self else { return } + self.onClick(delegateObject: delegateObject, additionalData) + }) + } + + public func onClick(delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + Task(priority: .userInitiated) { + try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: MVMCoreUIActionHandler.add(sourceModel: self, to: additionalData), delegateObject: delegateObject) + } + } +} diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift index 200dea16..7c4643bb 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift @@ -7,90 +7,95 @@ // import Foundation - -@objcMembers open class NotificationMoleculeView: Container { +import VDS +@objcMembers open class NotificationMoleculeView: VDS.Notification, VDSMoleculeViewProtocol { + + + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + open var viewModel: NotificationMoleculeModel! + public var delegateObject: MVMCoreUIDelegateObject? + public var additionalData: [AnyHashable: Any]? + + //-------------------------------------------------- + // MARK: - VDSMoleculeViewProtocol + //-------------------------------------------------- + + open func viewModelDidUpdate() { + surface = viewModel.surface + title = viewModel.headline.text + subTitle = viewModel.body?.text + + if let buttonModel = viewModel.button { + primaryButtonModel = buttonModel.toNotficationButtonModel(delegateObject: delegateObject, additionalData) + } + + if let buttonModel = viewModel.secondaryButton { + secondaryButtonModel = buttonModel.toNotficationButtonModel(delegateObject: delegateObject, additionalData) + } + + if let accessibilityIdentifier = viewModel.accessibilityIdentifier { + self.accessibilityIdentifier = accessibilityIdentifier + } + + if let closeButton = viewModel.closeButton { + onCloseClick = { [weak self] _ in + guard let self else { return } + closeButton.onClick(delegateObject: self.delegateObject, self.additionalData) + } + } + hideCloseButton = viewModel.closeButton == nil + style = viewModel.style.toVDSStyle + } + //-------------------------------------------------- // MARK: - Outlets //-------------------------------------------------- - - public let headline = Label(fontStyle: .BoldBodySmall) - public let body = Label(fontStyle: .RegularBodySmall) - public let button = PillButton() - public let closeButton = NotificationXButton() - public var labelStack: Stack! - public var horizontalStack: Stack! - // Legacy constant private static let viewHeight: CGFloat = 96.0 //-------------------------------------------------- // MARK: - Life Cycle //-------------------------------------------------- - - public override func setupView() { - super.setupView() - reset() - - // Buttons should have highest priority, then headline, then body - headline.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 500), for: .horizontal) - headline.setContentHuggingPriority(.required, for: .vertical) - body.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 500), for: .horizontal) - body.setContentHuggingPriority(.required, for: .vertical) - headline.setContentCompressionResistancePriority(UILayoutPriority(rawValue: body.contentCompressionResistancePriority(for: .vertical).rawValue + 40), for: .vertical) - headline.lineBreakMode = .byTruncatingTail - body.lineBreakMode = .byTruncatingTail - button.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal) - - labelStack = Stack.createStack(with: [headline, body], spacing: 0) - horizontalStack = Stack.createStack(with: [(view: labelStack, model: StackItemModel()),(view: button, model: StackItemModel(horizontalAlignment: .fill)),(view: closeButton, model: StackItemModel(horizontalAlignment: .fill))], axis: .horizontal) - addAndContain(horizontalStack) - labelStack.restack() - horizontalStack.restack() - - heightAnchor.constraint(equalToConstant: Self.viewHeight).isActive = true - } - - open override func reset() { - super.reset() - backgroundColor = .mvmGreen() - headline.textColor = .white - body.textColor = .white + open override func updateAccessibility() { + super.updateAccessibility() + Self.amendAccesibilityLabel(for: titleLabel) + Self.amendAccesibilityLabel(for: subTitleLabel) + Self.amendAccesibilityLabel(for: primaryButton) + Self.amendAccesibilityLabel(for: secondaryButton) + Self.amendAccesibilityLabel(for: closeButton) } //-------------------------------------------------- // 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? NotificationMoleculeModel else { return } - labelStack.updateContainedMolecules(with: [model.headline, model.body], delegateObject, nil) - horizontalStack.updateContainedMolecules(with: [labelStack.stackModel, model.button, model.closeButton], delegateObject, nil) - updateAccessibility() - } - - open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + public func updateView(_ size: CGFloat) { } + + open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return viewHeight } - - open func updateAccessibility() { - NotificationMoleculeView.amendAccesibilityLabel(for: headline) - NotificationMoleculeView.amendAccesibilityLabel(for: body) - NotificationMoleculeView.amendAccesibilityLabel(for: button) - NotificationMoleculeView.amendAccesibilityLabel(for: closeButton) - } - + /// Formats the accessibilityLabel so voice over users know it's in the notification. - static public func amendAccesibilityLabel(for view: UIView) { - guard let amendment = MVMCoreUIUtility.hardcodedString(withKey: "top_alert_notification"), - let accessibilityLabel = view.accessibilityLabel, - !accessibilityLabel.hasPrefix(amendment) else { return } - view.accessibilityLabel = "\(amendment) - \(accessibilityLabel)" + public class func amendAccesibilityLabel(for view: UIView?) { + guard let view, + let amendment = MVMCoreUIUtility.hardcodedString(withKey: "top_alert_notification") + else { return } + view.amendAccesibilityLabel(with: amendment) } } extension NotificationMoleculeView: AccessibilityProtocol { public func getAccessibilityLayoutChangedArgument() -> Any? { - return headline + return titleLabel + } +} + +extension UIView { + /// Formats the accessibilityLabel so voice over users know it's in the notification. + public func amendAccesibilityLabel(with amendment: String) { + guard let accessibilityLabel, !accessibilityLabel.hasPrefix(amendment) else { return } + self.accessibilityLabel = "\(amendment) - \(accessibilityLabel)" } } From f6a29a734c1620a908232bb468e4457d1bcca611 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 10 Apr 2024 14:01:26 -0500 Subject: [PATCH 04/17] updated collapsablenotification view/model Signed-off-by: Matt Bruce --- .../TopNotification/CollapsableNotification.swift | 8 +++++--- .../TopNotification/CollapsableNotificationModel.swift | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift index 4c677029..612f3873 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift @@ -10,6 +10,7 @@ import Foundation import Combine import Dispatch import MVMCore +import VDSColorTokens @objcMembers open class CollapsableNotification: View { //-------------------------------------------------- @@ -50,7 +51,7 @@ import MVMCore open override func reset() { super.reset() verticalStack.reset() - backgroundColor = .mvmGreen() + backgroundColor = bottomView.backgroundColor } open func subscribeForNotifications() { @@ -110,6 +111,7 @@ import MVMCore } } initialState() + backgroundColor = bottomView.backgroundColor } open func performBlockOperation(with block: @escaping (MVMCoreBlockOperation) -> Void) { @@ -214,7 +216,7 @@ import MVMCore extension CollapsableNotification: StatusBarUI { public func getStatusBarUI() -> (color: UIColor, style: UIStatusBarStyle) { - let color = backgroundColor ?? UIColor.mvmGreen + let color = backgroundColor ?? VDSColor.feedbackInformationBackgroundOnlight var greyScale: CGFloat = 0 topView.label.textColor.getWhite(&greyScale, alpha: nil) return (color, greyScale > 0.5 ? .lightContent : .default) @@ -226,7 +228,7 @@ extension CollapsableNotification: AccessibilityProtocol { if !topView.isHidden { return topView } else { - return bottomView.headline + return bottomView.titleLabel } } } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift index 3d366347..480665e2 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift @@ -19,7 +19,7 @@ open class CollapsableNotificationModel: NotificationMoleculeModel { public var collapseTime: Int = 5 public var initiallyCollapsed = false - public init(with topLabel: LabelModel, headline: LabelModel, style: NotificationMoleculeModel.Style = .success, backgroundColor: Color? = nil, topAction: ActionModelProtocol? = nil, collapseTime: Int? = nil, body: LabelModel? = nil, button: ButtonModel? = nil, closeButton: NotificationXButtonModel? = nil) { + public init(with topLabel: LabelModel, headline: LabelModel, style: NotificationMoleculeModel.Style = .success, backgroundColor: Color? = nil, topAction: ActionModelProtocol? = nil, collapseTime: Int? = nil, body: LabelModel? = nil, button: ButtonModel? = nil, closeButton: ButtonModel? = nil) { self.topLabel = topLabel self.topAction = topAction if let collapseTime = collapseTime { From 2e1bb7358ffcb76eb44fddb99ba7ecd40e012bb3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 10 Apr 2024 16:55:58 -0500 Subject: [PATCH 05/17] added executeAction helper method Signed-off-by: Matt Bruce --- MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift b/MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift index c3c07b6a..3869b398 100644 --- a/MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/MoleculeViewProtocol.swift @@ -66,6 +66,14 @@ extension MoleculeViewProtocol { set(with: model, delegateObject, additionalData) } } + + public func executeAction(model: T, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + Task(priority: .userInitiated) { + try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: model.action, + additionalData: MVMCoreUIActionHandler.add(sourceModel: model, to: additionalData), + delegateObject: delegateObject) + } + } } // Convenience Functions From 89e6ea43d0bd7ceade223d179bc01df3fec65b72 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 10 Apr 2024 16:56:51 -0500 Subject: [PATCH 06/17] put back to NotificationXBUttonModel Signed-off-by: Matt Bruce --- .../CollapsableNotificationModel.swift | 2 +- .../NotificationMoleculeModel.swift | 21 +++---------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift index 480665e2..3d366347 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift @@ -19,7 +19,7 @@ open class CollapsableNotificationModel: NotificationMoleculeModel { public var collapseTime: Int = 5 public var initiallyCollapsed = false - public init(with topLabel: LabelModel, headline: LabelModel, style: NotificationMoleculeModel.Style = .success, backgroundColor: Color? = nil, topAction: ActionModelProtocol? = nil, collapseTime: Int? = nil, body: LabelModel? = nil, button: ButtonModel? = nil, closeButton: ButtonModel? = nil) { + public init(with topLabel: LabelModel, headline: LabelModel, style: NotificationMoleculeModel.Style = .success, backgroundColor: Color? = nil, topAction: ActionModelProtocol? = nil, collapseTime: Int? = nil, body: LabelModel? = nil, button: ButtonModel? = nil, closeButton: NotificationXButtonModel? = nil) { self.topLabel = topLabel self.topAction = topAction if let collapseTime = collapseTime { diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift index f9387064..998fb689 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift @@ -47,7 +47,7 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { public var body: LabelModel? public var button: ButtonModel? public var secondaryButton: ButtonModel? - public var closeButton: ButtonModel? + public var closeButton: NotificationXButtonModel? public var style: Style = .success public var inverted: Bool = false @@ -55,7 +55,7 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { // MARK: - Initializer //-------------------------------------------------- - public init(with headline: LabelModel, style: NotificationMoleculeModel.Style = .success, backgroundColor: Color? = nil, body: LabelModel? = nil, button: ButtonModel? = nil, secondaryButton: ButtonModel? = nil, closeButton: ButtonModel? = nil) { + public init(with headline: LabelModel, style: NotificationMoleculeModel.Style = .success, backgroundColor: Color? = nil, body: LabelModel? = nil, button: ButtonModel? = nil, secondaryButton: ButtonModel? = nil, closeButton: NotificationXButtonModel? = nil) { self.headline = headline self.style = style self.backgroundColor = backgroundColor @@ -103,7 +103,7 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { body = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .body) button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button) secondaryButton = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .secondaryButton) - closeButton = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .closeButton) + closeButton = try typeContainer.decodeIfPresent(NotificationXButtonModel.self, forKey: .closeButton) inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) ?? false if let style = try typeContainer.decodeIfPresent(NotificationMoleculeModel.Style.self, forKey: .style) { self.style = style @@ -130,18 +130,3 @@ extension NotificationMoleculeModel { inverted ? .dark : .light } } - -extension ButtonModel { - public func toNotficationButtonModel(delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) -> VDS.Notification.ButtonModel { - return .init(text: title, onClick: { [weak self] _ in - guard let self else { return } - self.onClick(delegateObject: delegateObject, additionalData) - }) - } - - public func onClick(delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - Task(priority: .userInitiated) { - try await (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction(with: action, additionalData: MVMCoreUIActionHandler.add(sourceModel: self, to: additionalData), delegateObject: delegateObject) - } - } -} From b23351386b4161c57c34d89e039381214247466b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 10 Apr 2024 16:56:59 -0500 Subject: [PATCH 07/17] using helper now Signed-off-by: Matt Bruce --- .../NotificationMoleculeView.swift | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift index 7c4643bb..38c58aa9 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift @@ -28,12 +28,18 @@ import VDS title = viewModel.headline.text subTitle = viewModel.body?.text - if let buttonModel = viewModel.button { - primaryButtonModel = buttonModel.toNotficationButtonModel(delegateObject: delegateObject, additionalData) + if let button = viewModel.button { + primaryButtonModel = .init(text: button.title, onClick: {[weak self] _ in + guard let self else { return } + self.executeAction(model: button, delegateObject: self.delegateObject, additionalData: self.additionalData) + }) } - if let buttonModel = viewModel.secondaryButton { - secondaryButtonModel = buttonModel.toNotficationButtonModel(delegateObject: delegateObject, additionalData) + if let secondaryButton = viewModel.secondaryButton { + secondaryButtonModel = .init(text: secondaryButton.title, onClick: {[weak self] _ in + guard let self else { return } + self.executeAction(model: secondaryButton, delegateObject: self.delegateObject, additionalData: self.additionalData) + }) } if let accessibilityIdentifier = viewModel.accessibilityIdentifier { @@ -43,9 +49,9 @@ import VDS if let closeButton = viewModel.closeButton { onCloseClick = { [weak self] _ in guard let self else { return } - closeButton.onClick(delegateObject: self.delegateObject, self.additionalData) - } + self.executeAction(model: closeButton, delegateObject: self.delegateObject, additionalData: self.additionalData) } } + hideCloseButton = viewModel.closeButton == nil style = viewModel.style.toVDSStyle } From bd93cfdfe888b7cc2b0f0799ec97275bd49f3b65 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 11 Apr 2024 12:28:02 -0500 Subject: [PATCH 08/17] map notification label to topLabel Signed-off-by: Matt Bruce --- .../Molecules/TopNotification/CollapsableNotification.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift index 612f3873..6372e7ca 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift @@ -99,6 +99,8 @@ import VDSColorTokens guard let model = model as? CollapsableNotificationModel else { return } topView.set(with: model, delegateObject, additionalData) bottomView.set(with: model, delegateObject, additionalData) + topView.label.textColorConfiguration = bottomView.titleLabel.textColorConfiguration + topView.label.surface = bottomView.surface // Update top view default noop to expand. if let topAction = model.topAction, From 277f54599ee9bc013286b627102827c06ce961ed Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 11 Apr 2024 12:28:18 -0500 Subject: [PATCH 09/17] omit text color Signed-off-by: Matt Bruce --- .../TopNotification/CollapsableNotificationModel.swift | 8 -------- 1 file changed, 8 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift index 3d366347..e6c32afd 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift @@ -33,14 +33,6 @@ open class CollapsableNotificationModel: NotificationMoleculeModel { if topLabel.numberOfLines == nil { topLabel.numberOfLines = 1 } - if topLabel.textColor == nil { - switch style { - case .error, .warning: - topLabel.textColor = Color(uiColor: .mvmBlack) - default: - topLabel.textColor = Color(uiColor: .mvmWhite) - } - } if topLabel.textAlignment == nil { topLabel.textAlignment = .center } From ae8f19ba510aa2d5871dacd8c071904d2a9f22f4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 11 Apr 2024 12:28:31 -0500 Subject: [PATCH 10/17] set default color to black Signed-off-by: Matt Bruce --- .../TopNotification/CollapsableNotificationTopView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationTopView.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationTopView.swift index 01c0b3d5..1a9512d1 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationTopView.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationTopView.swift @@ -52,7 +52,7 @@ import Foundation open override func reset() { super.reset() label.setFontStyle(.BoldBodySmall) - label.textColor = .white + label.textColor = .black label.textAlignment = .center } From 7d6591a3940db115e0d4e3ac2b9b76dabf5bdef7 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 11 Apr 2024 12:29:28 -0500 Subject: [PATCH 11/17] default implementation for model in protocol used for vds component integration Signed-off-by: Matt Bruce --- MVMCoreUI/Atomic/Protocols/VDSMoleculeViewProtocol.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Protocols/VDSMoleculeViewProtocol.swift b/MVMCoreUI/Atomic/Protocols/VDSMoleculeViewProtocol.swift index 1bcc78c6..4bebf0c7 100644 --- a/MVMCoreUI/Atomic/Protocols/VDSMoleculeViewProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/VDSMoleculeViewProtocol.swift @@ -21,7 +21,11 @@ public protocol VDSMoleculeViewProtocol: MoleculeViewProtocol, MVMCoreViewProtoc } extension VDSMoleculeViewProtocol { - + public var model: MoleculeModelProtocol { + get { viewModel } + set { } + } + public func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { self.model = model guard let castedModel = model as? ViewModel else { return } From 1048a2989130f2fcefdcdeb61d0ed724a5cf03f1 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 11 Apr 2024 13:06:39 -0500 Subject: [PATCH 12/17] added rbg helper to UIColor extension Signed-off-by: Matt Bruce --- MVMCoreUI/Categories/UIColor+Extension.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MVMCoreUI/Categories/UIColor+Extension.swift b/MVMCoreUI/Categories/UIColor+Extension.swift index 78363630..f4ef0f7f 100644 --- a/MVMCoreUI/Categories/UIColor+Extension.swift +++ b/MVMCoreUI/Categories/UIColor+Extension.swift @@ -56,6 +56,18 @@ extension UIColor { "upGold2": (.vzupGold2, "#F4CA53"), "upGold3": (.vzupGold3, "#CC9B2D")] + //-------------------------------------------------- + // MARK: - Helper + //-------------------------------------------------- + public var rgbComponents: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { + var red: CGFloat = 0 + var green: CGFloat = 0 + var blue: CGFloat = 0 + var alpha: CGFloat = 0 + getRed(&red, green: &green, blue: &blue, alpha: &alpha) + return (red, green, blue, alpha) + } + //-------------------------------------------------- // MARK: - Brand //-------------------------------------------------- From 473c98cca431db3a0a43c3cb12bb8d3f68efae9d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 11 Apr 2024 14:04:12 -0500 Subject: [PATCH 13/17] removed color since now this is driven by vds Signed-off-by: Matt Bruce --- .../Molecules/TopNotification/NotificationXButton.swift | 1 - .../TopNotification/NotificationXButtonModel.swift | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift index d0071668..c102d064 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButton.swift @@ -30,7 +30,6 @@ import MVMCore open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = model as? NotificationXButtonModel else { return } - tintColor = model.color?.uiColor ?? .white // TODO: Temporary, consider action for dismissing top alert if model.action.actionType == ActionNoopModel.identifier { diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButtonModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButtonModel.swift index ac1c8905..0206b79d 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButtonModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationXButtonModel.swift @@ -15,25 +15,21 @@ public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtoco public var id: String = UUID().uuidString public var backgroundColor: Color? - public var color: Color? public var action: ActionModelProtocol = ActionNoopModel() private enum CodingKeys: String, CodingKey { case id case moleculeName - case color case action } - public init(color: Color? = nil, action: ActionModelProtocol = ActionNoopModel()) { - self.color = color + public init(action: ActionModelProtocol = ActionNoopModel()) { self.action = action } public required init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString - color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) { self.action = action } @@ -43,7 +39,6 @@ public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtoco var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(color, forKey: .color) try container.encodeModel(action, forKey: .action) } } From 8fd6a2e7c4f5fdd5785ddaaccbe3f46e6e2bcaf8 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 11 Apr 2024 14:08:21 -0500 Subject: [PATCH 14/17] removed background color coding Signed-off-by: Matt Bruce --- .../Molecules/TopNotification/NotificationMoleculeModel.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift index 998fb689..ddf90a77 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift @@ -97,7 +97,6 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { 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) @@ -114,7 +113,6 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { open override func encode(to encoder: Encoder) throws { 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) From 79cccbb47103d5595823d0d8a66aa0dd0bb0bbcb Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 12 Apr 2024 08:38:02 -0500 Subject: [PATCH 15/17] removed ContainerModel Signed-off-by: Matt Bruce --- .../NotificationMoleculeModel.swift | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift index ddf90a77..7fac6d43 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift @@ -7,7 +7,7 @@ // import VDS -open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { +open class NotificationMoleculeModel: MoleculeModelProtocol { /** The style of the notification: @@ -39,7 +39,7 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - + public var id: String = UUID().uuidString public class var identifier: String { "notification" } public var accessibilityIdentifier: String? public var backgroundColor: Color? @@ -63,15 +63,6 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { self.button = button self.secondaryButton = secondaryButton self.closeButton = closeButton - super.init() - } - - //-------------------------------------------------- - // MARK: - Default - //-------------------------------------------------- - - open override func setDefaults() { - } //-------------------------------------------------- @@ -107,10 +98,9 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { if let style = try typeContainer.decodeIfPresent(NotificationMoleculeModel.Style.self, forKey: .style) { self.style = style } - super.init() } - open override func encode(to encoder: Encoder) throws { + open func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) From 1edffd8e24614bc2f53d331d825f10e2b2f39837 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 12 Apr 2024 08:39:28 -0500 Subject: [PATCH 16/17] added encoding for inverted Signed-off-by: Matt Bruce --- .../Molecules/TopNotification/NotificationMoleculeModel.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift index 7fac6d43..0fc5d5d5 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift @@ -109,6 +109,7 @@ open class NotificationMoleculeModel: MoleculeModelProtocol { try container.encodeIfPresent(button, forKey: .button) try container.encodeIfPresent(secondaryButton, forKey: .secondaryButton) try container.encodeIfPresent(closeButton, forKey: .closeButton) + try container.encodeIfPresent(inverted, forKey: .inverted) try container.encode(style, forKey: .style) } } From a74362cc0c695350d514281cf08352197760a7bb Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 12 Apr 2024 13:06:15 -0500 Subject: [PATCH 17/17] fixed issue with taking out ContainerModel Signed-off-by: Matt Bruce --- .../Molecules/TopNotification/CollapsableNotification.swift | 2 +- .../TopNotification/CollapsableNotificationModel.swift | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift index 6372e7ca..cef93935 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift @@ -10,7 +10,7 @@ import Foundation import Combine import Dispatch import MVMCore -import VDSColorTokens +import VDSTokens @objcMembers open class CollapsableNotification: View { //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift index e6c32afd..4c87a4e4 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotificationModel.swift @@ -26,10 +26,10 @@ open class CollapsableNotificationModel: NotificationMoleculeModel { self.collapseTime = collapseTime } super.init(with: headline, style: style, backgroundColor: backgroundColor, body: body, button: button, closeButton: closeButton) + setDefaults() } - open override func setDefaults() { - super.setDefaults() + open func setDefaults() { if topLabel.numberOfLines == nil { topLabel.numberOfLines = 1 } @@ -61,6 +61,7 @@ open class CollapsableNotificationModel: NotificationMoleculeModel { self.initiallyCollapsed = initiallyCollapsed } try super.init(from: decoder) + setDefaults() } open override func encode(to encoder: Encoder) throws {