diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index 3b72d37c..5bff2a39 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -198,6 +198,11 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat title = try typeContainer.decode(String.self, forKey: .title) action = try typeContainer.decodeModel(codingKey: .action) + if let style = decoder.context?.value(forKey: CodingKeys.style.stringValue) as? Styler.Button.Style{ + self.style = style + setFacade(by: style) + } + if let style = try typeContainer.decodeIfPresent(Styler.Button.Style.self, forKey: .style) { self.style = style setFacade(by: style) diff --git a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift index 4d843e6a..718cfc30 100644 --- a/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift +++ b/MVMCoreUI/Atomic/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift @@ -50,13 +50,17 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - primaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .primaryButton) - if primaryButton?.style == nil { - primaryButton?.style = .primary + + //set context value for 'primary' style to be set for the primaryButton in case the + //property is not returned in the JSON and once decoded, this value is removed from the context + try decoder.setContext(value: Styler.Button.Style.primary, for: "style") { + self.primaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .primaryButton) } - secondaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .secondaryButton) - if secondaryButton?.style == nil { - secondaryButton?.style = .secondary + + //set context value for 'secondary' style to be set for the primaryButton in case the + //property is not returned in the JSON and once decoded, this value is removed from the context + try decoder.setContext(value: Styler.Button.Style.secondary, for: "style") { + self.secondaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .secondaryButton) } }