From eb9ec0086618709faf73c85268ace4eeb092ca8a Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Fri, 15 Sep 2023 01:17:53 +0530 Subject: [PATCH] updated button traits dynamically --- MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift | 4 ++++ MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift | 4 +++- MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift | 6 ++++-- MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index 08afefde..ce5a846e 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -73,6 +73,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat _backgroundColor = newValue } } + public var accessibilityTraits: UIAccessibilityTraits? //-------------------------------------------------- // MARK: - Methods @@ -195,6 +196,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat case disabledTextColor case disabledBorderColor case width + case accessibilityTraits } //-------------------------------------------------- @@ -263,6 +265,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width) + accessibilityTraits = try typeContainer.decodeIfPresent(UIAccessibilityTraits.self, forKey: .accessibilityTraits) } open func encode(to encoder: Encoder) throws { @@ -286,5 +289,6 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat try container.encodeIfPresent(size, forKey: .size) try container.encodeIfPresent(groupName, forKey: .groupName) try container.encodeIfPresent(width, forKey: .width) + try container.encodeIfPresent(accessibilityTraits, forKey: .accessibilityTraits) } } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift index 323236a7..394f7d86 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift @@ -33,7 +33,9 @@ import Foundation super.set(with: model, delegateObject, additionalData) FormValidator.setupValidation(for: castModel, delegate: delegateObject?.formHolderDelegate) - + if let traits = model.accessibilityTraits { + accessibilityTraits = traits + } } public func setState() { diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift index a61ec150..75b6c923 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift @@ -24,7 +24,7 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro public var enabled: Bool = true public var enabledTintColor: Color? public var disabledTintColor: Color? - + public var accessibilityTraits: UIAccessibilityTraits? public var groupName: String = "" public var updateUI: ActionBlock? @@ -45,6 +45,7 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro case groupName case enabledTintColor case disabledTintColor + case accessibilityTraits } //-------------------------------------------------- @@ -59,7 +60,7 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro image = try typeContainer.decodeIfPresent(ImageViewModel.self, forKey: .image) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) action = try typeContainer.decodeModel(codingKey: .action) - + accessibilityTraits = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityTraits) if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { self.enabled = enabled } @@ -90,5 +91,6 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro try container.encodeIfPresent(groupName, forKey: .groupName) try container.encodeIfPresent(enabledTintColor, forKey: .enabledTintColor) try container.encodeIfPresent(disabledTintColor, forKey: .disabledTintColor) + try container.encodeIfPresent(accessibilityTraits, forKey: .accessibilityTraits) } } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift index e578fa51..71d5c332 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/PillButton.swift @@ -173,6 +173,9 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol { } FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate) + if let traits = model.accessibilityTraits { + accessibilityTraits = traits + } } open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {