Updating logic to read style params from context, JSON and default

This commit is contained in:
Sumanth Nadigadda 2022-08-04 22:19:20 +05:30
parent dbb0b3c6c7
commit d1b1db1967

View File

@ -206,15 +206,14 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
title = try typeContainer.decode(String.self, forKey: .title)
action = try typeContainer.decodeModel(codingKey: .action)
///Reading the style param from context which is set is molecules, ex: TwoButtonView
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) {
} else if let style = try typeContainer.decodeIfPresent(Styler.Button.Style.self, forKey: .style) { ///Style captured from the JSON
self.style = style
setFacade(by: style)
} else {
} else { ///Default style
setFacade(by: .primary)
}