From 49d6d2bf76a7c6381f6cb5a6b840a8b52b8972f3 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 30 Oct 2023 12:45:12 -0400 Subject: [PATCH 1/3] bugfix for old color properties --- .../Atomic/Atoms/Buttons/ButtonModel.swift | 195 ++++-------------- .../NotificationMoleculeModel.swift | 6 +- 2 files changed, 43 insertions(+), 158 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index 94a7778b..38abd4cd 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -27,54 +27,12 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat public var action: ActionModelProtocol public var enabled: Bool = true public var width: CGFloat? - public var style: Use? { - didSet { - guard let style = style else { return } - setFacade(by: style) - } - } + public var style: Use = .primary public var size: VDS.Button.Size = .large public var groupName: String = "" public var inverted: Bool = false - - public lazy var enabledColors: FacadeElements = (fill: enabled_fillColor(), - text: enabled_textColor(), - border: enabled_borderColor()) - - public lazy var disabledColors: FacadeElements = (fill: disabled_fillColor(), - text: disabled_textColor(), - border: disabled_borderColor()) - - public var enabledFillColor: Color? - public var enabledTextColor: Color? - public var enabledBorderColor: Color? - - public var enabledFillColor_inverted: Color? - public var enabledTextColor_inverted: Color? - public var enabledBorderColor_inverted: Color? - - public var disabledFillColor: Color? - public var disabledTextColor: Color? - public var disabledBorderColor: Color? - - public var disabledFillColor_inverted: Color? - public var disabledTextColor_inverted: Color? - public var disabledBorderColor_inverted: Color? - - private var _backgroundColor: Color? - public var backgroundColor: Color? { - get { - if let backgroundColor = _backgroundColor { return backgroundColor } - if inverted { - return enabled ? enabledFillColor_inverted : disabledFillColor_inverted - } - return enabled ? enabledFillColor : disabledFillColor - } - set { - _backgroundColor = newValue - } - } - + public var backgroundColor: Color? + //-------------------------------------------------- // MARK: - Methods //-------------------------------------------------- @@ -88,88 +46,18 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat public init(with title: String, action: ActionModelProtocol) { self.title = title self.action = action - setFacade(by: .primary) } public init(secondaryButtonWith title: String, action: ActionModelProtocol) { self.title = title self.action = action style = .secondary - setFacade(by: .secondary) } public init(primaryButtonWith title: String, action: ActionModelProtocol) { self.title = title self.action = action style = .primary - setFacade(by: .primary) - } - - //-------------------------------------------------- - // MARK: - Methods - //-------------------------------------------------- - - public func enabled_fillColor() -> UIColor? { - (inverted ? enabledFillColor_inverted : enabledFillColor)?.uiColor - } - - public func enabled_textColor() -> UIColor? { - (inverted ? enabledTextColor_inverted : enabledTextColor)?.uiColor - } - - public func enabled_borderColor() -> UIColor? { - (inverted ? enabledBorderColor_inverted : enabledBorderColor)?.uiColor - } - - public func disabled_fillColor() -> UIColor? { - (inverted ? disabledFillColor_inverted : disabledFillColor)?.uiColor - } - - public func disabled_textColor() -> UIColor? { - (inverted ? disabledTextColor_inverted : disabledTextColor)?.uiColor - } - - public func disabled_borderColor() -> UIColor? { - (inverted ? disabledBorderColor_inverted : disabledBorderColor)?.uiColor - } - - /// Defines the default appearance for the primary style. - func setPrimaryFacade() { - enabledFillColor = Color(uiColor: VDSColor.elementsPrimaryOnlight) - enabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOndark) - disabledFillColor = Color(uiColor: VDSColor.interactiveDisabledOnlight) - disabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOndark) - - enabledFillColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark) - enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight) - disabledFillColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark) - disabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOnlight) - } - - /// Defines the default appearance for the Secondary style. - func setSecondaryFacade() { - enabledTextColor = Color(uiColor: VDSColor.elementsPrimaryOnlight) - enabledFillColor = Color(uiColor: UIColor.clear) - enabledBorderColor = Color(uiColor: VDSColor.elementsPrimaryOnlight) - disabledTextColor = Color(uiColor: VDSColor.interactiveDisabledOnlight) - disabledBorderColor = Color(uiColor: VDSColor.interactiveDisabledOnlight) - - enabledTextColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark) - enabledFillColor_inverted = Color(uiColor: UIColor.clear) - enabledBorderColor_inverted = Color(uiColor: VDSColor.elementsPrimaryOndark) - disabledTextColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark) - disabledBorderColor_inverted = Color(uiColor: VDSColor.interactiveDisabledOndark) - } - - public func setFacade(by style: VDS.Use) { - switch style { - case .primary: - setPrimaryFacade() - case .secondary: - setSecondaryFacade() - @unknown default: - setPrimaryFacade() - } } //-------------------------------------------------- @@ -179,7 +67,6 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat private enum CodingKeys: String, CodingKey { case id case moleculeName - case backgroundColor case accessibilityIdentifier case accessibilityText case title @@ -189,12 +76,6 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat case style case size case groupName - case fillColor - case textColor - case borderColor - case disabledFillColor - case disabledTextColor - case disabledBorderColor case width } @@ -214,12 +95,8 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat ///Style captured from the JSON if let style = try typeContainer.decodeIfPresent(Use.self, forKey: .style) { self.style = style - setFacade(by: style) } else if let style = decoder.context?.value(forKey: CodingKeys.style.stringValue) as? Use { ///Reading the style param from context which is set is molecules, ex: TwoButtonView self.style = style - setFacade(by: style) - } else { ///Default style - setFacade(by: .primary) } if let size = try typeContainer.decodeIfPresent(VDS.Button.Size.self, forKey: .size) { @@ -230,40 +107,57 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat self.enabled = enabled } - if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { - self.inverted = inverted - } - if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { self.groupName = groupName } + width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width) + + if let inverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .inverted) { + self.inverted = inverted + } else { + try setInverted(deprecatedFrom: decoder) + } + } + + private enum DeprecatedCodingKeys: String, CodingKey { + case fillColor + case textColor + case borderColor + case backgroundColor + } + + private func setInverted(deprecatedFrom decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: DeprecatedCodingKeys.self) if let enabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor) { - self.enabledFillColor = enabledFillColor + if (self.style == .secondary) { + self.inverted = enabledFillColor.uiColor.isDark() + } else { + self.inverted = !enabledFillColor.uiColor.isDark() + } } if let enabledTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) { - self.enabledTextColor = enabledTextColor + if (self.style == .secondary) { + self.inverted = !enabledTextColor.uiColor.isDark() + } else { + self.inverted = enabledTextColor.uiColor.isDark() + } } if let enabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) { - self.enabledBorderColor = enabledBorderColor + if (self.style == .secondary) { + self.inverted = !enabledBorderColor.uiColor.isDark() + } } - - if let disabledFillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledFillColor) { - self.disabledFillColor = disabledFillColor + + if let backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) { + if (self.style == .secondary) { + self.inverted = backgroundColor.uiColor.isDark() + } else { + self.inverted = !backgroundColor.uiColor.isDark() + } } - - if let disabledTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledTextColor) { - self.disabledTextColor = disabledTextColor - } - - if let disabledBorderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledBorderColor) { - self.disabledBorderColor = disabledBorderColor - } - - backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width) } open func encode(to encoder: Encoder) throws { @@ -274,15 +168,8 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat try container.encode(enabled, forKey: .enabled) 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(accessibilityText, forKey: .accessibilityText) - try container.encodeIfPresent(enabledFillColor, forKey: .fillColor) - try container.encodeIfPresent(enabledTextColor, forKey: .textColor) - try container.encodeIfPresent(enabledBorderColor, forKey: .borderColor) - try container.encodeIfPresent(disabledFillColor, forKey: .disabledFillColor) - try container.encodeIfPresent(disabledTextColor, forKey: .disabledTextColor) - try container.encodeIfPresent(disabledBorderColor, forKey: .disabledBorderColor) try container.encodeIfPresent(style, forKey: .style) try container.encodeIfPresent(size, forKey: .size) try container.encodeIfPresent(groupName, forKey: .groupName) diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift index 27ca95a8..9958b59a 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeModel.swift @@ -93,11 +93,9 @@ open class NotificationMoleculeModel: ContainerModel, MoleculeModelProtocol { button?.style = .secondary switch style { case .error, .warning: - button?.enabledTextColor = Color(uiColor: .mvmBlack) - button?.enabledBorderColor = Color(uiColor: .mvmBlack) + button?.inverted = false default: - button?.enabledTextColor = Color(uiColor: .mvmWhite) - button?.enabledBorderColor = Color(uiColor: .mvmWhite) + button?.inverted = true } if closeButton?.color == nil { From 17a16bf73cf12293dc0a298eecb0216a7d7d8268 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 30 Oct 2023 12:47:53 -0400 Subject: [PATCH 2/3] change encode --- MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index 38abd4cd..b712b04e 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -170,8 +170,8 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat try container.encodeModel(action, forKey: .action) try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier) try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) - try container.encodeIfPresent(style, forKey: .style) - try container.encodeIfPresent(size, forKey: .size) + try container.encode(style, forKey: .style) + try container.encode(size, forKey: .size) try container.encodeIfPresent(groupName, forKey: .groupName) try container.encodeIfPresent(width, forKey: .width) } From 4b9c3860716e0856476108f38813d7c363f9683b Mon Sep 17 00:00:00 2001 From: "Rajendran, Nandhini" Date: Tue, 31 Oct 2023 15:30:39 +0000 Subject: [PATCH 3/3] story: ONEAPP-5868 page control update --- .../Atoms/Views/CarouselIndicator/BarsIndicatorView.swift | 4 +++- MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift index 2eefd716..4cff7bdb 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CarouselIndicator/BarsIndicatorView.swift @@ -213,7 +213,9 @@ open class BarsIndicatorView: CarouselIndicator { let accessibleIndex = MVMCoreUIUtility.getOrdinalString(forIndex: NSNumber(value: index + 1)) else { return } - view.accessibilityLabel = String(format: accessibleValueFormat, accessibleIndex, numberOfPages) + let accessibilityValue = String(format: accessibleValueFormat, accessibleIndex, numberOfPages) + view.accessibilityLabel = accessibilityValue + view.accessibilityIdentifier = accessibilityValue } public override func assessTouchOf(_ touchPoint_X: CGFloat) { diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index 6b360120..cb618524 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -372,7 +372,9 @@ open class Carousel: View { self.carouselAccessibilityElement = carouselAccessibilityElement } - if let currentCell = collectionView.cellForItem(at: IndexPath(row: currentIndex, section: 0)) { + if let currentCell = collectionView.cellForItem(at: IndexPath(row: currentIndex, section: 0)), let pagingView = self.pagingView { + _accessibilityElements = [currentCell, carouselAccessibilityElement, pagingView] + } else if let currentCell = collectionView.cellForItem(at: IndexPath(row: currentIndex, section: 0)) { _accessibilityElements = [currentCell, carouselAccessibilityElement] } else { _accessibilityElements = [carouselAccessibilityElement]